我如何通过IO Kit的钥匙迭代? [英] How do I iterate through IO Kit's keys?

查看:275
本文介绍了我如何通过IO Kit的钥匙迭代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让系统中的所有设备的列表,包括它们是如何连接在一起。因此,我想基本上克隆IO套件服务树的结构(您可以用 IORegistryExplorer 见)。我如何通过所有的键重复? (其中一个这是令人困惑我的原因是因为我不明白什么 io_service对象 io_registry 之间的差异, io_object 是)。

I am trying to get a list of all devices in the system together with how they are connected. Therefore, I want to essentially clone the structure of the IO Kit services tree (that you can see with IORegistryExplorer). How do I iterate through all the keys? (One of the reasons this is confusing to me is because I dont understand what the difference between io_service, io_registry, and io_object are).

推荐答案

服务,注册表和对象之间的区别只是在它们被使用的情况。否则,他们的完全一样的。
从IOTypes.h:

The difference between service, registry and object is only in the circumstances they are used. Otherwise they are completely the same. From IOTypes.h:

typedef io_object_t io_registry_entry_t;
typedef io_object_t io_service_t;

有可用约<一个文档href=\"https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html#//apple_ref/doc/uid/TP30000380-TPXREF112\"相对=nofollow>遍历I / O注册表,其中还包括在遍历整个注册表信息。
对于每个条目,然后你将不得不<一个href=\"https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html#//apple_ref/doc/uid/TP30000380-BABIDJDI\"相对=nofollow>获得的属性,并将它们保存在注册表中的您重新presentation。

There is documentation available about Traversing the I/O Registry, which also includes information on traversing the whole registry. For each entry you then would have to get the properties and save them with your representation of the registry.

所以,你会使用 IORegistryGetRootEntry(),打印/保存它的名称和属性,然后遍历其子与<一个href=\"https://developer.apple.com/library/mac/documentation/IOKit/Reference/IOKitLib_header_reference/Reference/reference.html#//apple_ref/doc/c_ref/IORegistryEntryGetChildIterator\"相对=nofollow> IORegistryEntryGetChildIterator()

So you would use IORegistryGetRootEntry(), print/save its name and properties and then iterate over the children with IORegistryEntryGetChildIterator().

您获得与 IORegistryEntryCreateCFProperties的属性()继<一个href=\"http://developer.apple.com/library/ios/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/func/CFDictionaryGetKeysAndValues\"相对=nofollow> CFDictionaryGetKeysAndValues​​() 。对于数值你就必须检查这些都是打印/保存(或使用CFSHOW)什么类型的。如果你真的想克隆到不同的结构(不同类型的)这一点,你必须明确地处理每一种可能CFTypeID。

You get the properties with IORegistryEntryCreateCFProperties() following aCFDictionaryGetKeysAndValues(). For the values you then have to check what types these are to print/save them (or use CFSHOW). When you really want to clone this into a different structure (with different types) you have to handle every possible CFTypeID explicitely.

我创建了一个工作原型在
https://gist.github.com/JonnyJD/6126680

I created a working prototype at https://gist.github.com/JonnyJD/6126680

编辑:

另一SO回答中的(C)来源$ C ​​$的ç名为ioreg 链接。这应该是印刷一个很好的资源/解压缺少的CFTypes。

In another SO answer the (C) source code of ioreg is linked. That should be a good resource for printing/extracting missing CFTypes.

这篇关于我如何通过IO Kit的钥匙迭代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆