我正在尝试通过IOUSBDeviceInterface245
(来自 Mac OS X 上的 IOKit)获取一些信息(例如产品名称):
代码 #1
io_iterator_t iterator;
io_object_t usb_device
SInt32 score = 0;
kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault,
IOServiceNameMatching("AppleUSBOHCI"),
&iterator);
IOCFPlugInInterface **plugin_interface = NULL;
IOUSBDeviceInterface245 **usb_interface = NULL;
// ...
// enumerate devices (usb_device = IOIteratorNext(iterator))
// ...
IOReturn return_code = IOCreatePlugInInterfaceForService(usb_device,
kIOUSBDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugin_interface,
&score);
HRESULT h_result = (*pluginInterface)->QueryInterface(pluginInterface,
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID245),
(LPVOID)&usb_interface);
IODestroyPlugInInterface(pluginInterface);
UInt8 product_string_index;
return_code = (*usb_interface)->USBGetProductStringIndex(usb_interface,
&product_string_index);
// Next, getting a product string by string's index. To do so, we need to send
// IOUSBDevRequest (with type "kUSBRqGetDescriptor") to the current USB-device.
// Code bellow - is a pseudocode:
char *product_name = malloc(128);
get_string_by_index(usb_interface, product_string_index, product_string, 128);
此代码适用于所有正在工作的设备,但不适用于暂停(“睡眠”)
设备(product_name
只是一个空白字符串)。
但是,如果我使用此代码:
代码 #2
CFMutableDictionaryRef child_properties = CFDictionaryCreateMutable(NULL, 0,
NULL,NULL);
kern_return_t kr;
io_service_t io_service;
// iterator = iterator for "AppleUSBOHCI" or "AppleUSBEHCI" services
while((io_service = IOIteratorNext(iterator))) {
io_iterator_t children_iterator;
kernel_return = IORegistryEntryGetChildIterator(io_service, kIOServicePlane,
&children_iterator);
io_registry_entry_t child;
while((child = IOIteratorNext(children_iterator))) {
// Create a CFDictionary with usb-device's properties
IORegistryEntryCreateCFProperties(child, &child_properties,
kCFAllocatorDefault,
kNilOptions);
NSLog(@"%@",[(NSDictionary*)child_properties valueForKey:@"USB Product Name"]);
}
}
这对所有设备都有效(我不知道为什么)。
我尝试通过此代码唤醒暂停的设备(与代码 #1 一起使用):
(*usb_interface)->USBDeviceSuspend(usb_interface, false);
但它什么也没改变。
我注意到的一件事 - 代码 #1 完全适用于睡眠设备的所有属性,除了字符串值(通过字符串的索引获取)。
UPDATE:
So, my question is how can I unsuspend a device for using with the first code block?
Thank you.