繁体   English   中英

IOKIT mac os IORegistryEntry

[英]IOKIT mac os IORegistryEntry

我想知道如何使用以下代码链接IOKit.framework 我无法在应用程序中链接它:XCode始终警告我所使用的方法未知。 我知道有使用限制 例如仅在内核扩展中 :I / O套件使用面向对象的编程模型,该模型在C ++受限子集中实现,以提高代码的重用性,如I / O套件概述中所述 如果您能帮助我,我将非常高兴,以便我学习。

 OSData * data;
 IORegistryEntry * entry;
 OSString * string = 0;
 uuid_string_t uuid;
 const IORegistryPlane * gIODTPlane;



 entry = IORegistryEntry :: fromPath ("/efi/platform", gIODTPlane);
 if (entry)
 {
     data = OSDynamicCast (OSData, entry-> getProperty ("SystemSerialNumber"));
     if (data && data-> getLength () == 16)
     {
         string = OSString :: withCString ((char const *) data-> getBytesNoCopy ());
     }

     entry-> release ();
 }

这些类型和函数都在Kernel.framework定义。 除非您要构建内核扩展,否则这不是您想要的。 用于访问IOKit的用户空间API是通过IOKit.framework提供的C API(IOKitLib)来IOKit.framework

此处的文档位于: https : //developer.apple.com/library/content/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html

看起来您想让IORegistryEntryFromPath()IORegistryEntryCreateCFProperty()函数在用户空间中获取所需的信息。

(两者均在<IOKit/IOKitLib.h>中声明,请确保将IOKit.framework添加到要链接的目标库列表中。如果您的应用程序尚未链接到,则还可能需要针对CoreFoundation.framework进行链接。还是Cocoa.framework。)

在将“ CFMutableDictionaryRef”与“ IORegistryEntryFromPath”,“ IORegistryEntryCreateCFProperties”和“ CFDictionaryApplyFunction”配合使用的情况下,您将获得“平台”中包含的块,该块已使用转换字符串或数据对每个元素进行了排序。这就是ioreg.c在很轻的形式

void getsystemuuid()
{

    io_registry_entry_t service  = 0;
    struct options      options;
    CFMutableDictionaryRef properties = 0;
    kern_return_t       status      = KERN_SUCCESS;


    service = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/efi/platform");

    status=IORegistryEntryCreateCFProperties( service,&properties,kCFAllocatorDefault,kNilOptions );

    if (status)
        goto sortie;


    CFDictionaryApplyFunction(properties, showitem,&options.depth);

sortie:
    CFRelease(properties);
    IOObjectRelease(service);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM