199 static int |
199 static int |
200 HIDGetDeviceProduct(io_service_t dev, char *name) |
200 HIDGetDeviceProduct(io_service_t dev, char *name) |
201 { |
201 { |
202 CFMutableDictionaryRef hidProperties, usbProperties; |
202 CFMutableDictionaryRef hidProperties, usbProperties; |
203 io_registry_entry_t parent1, parent2; |
203 io_registry_entry_t parent1, parent2; |
|
204 kern_return_t ret; |
204 |
205 |
205 hidProperties = usbProperties = 0; |
206 hidProperties = usbProperties = 0; |
|
207 |
|
208 ret = IORegistryEntryCreateCFProperties(hidDevice, &hidProperties, |
|
209 kCFAllocatorDefault, |
|
210 kNilOptions); |
|
211 if ((ret != KERN_SUCCESS) || !hidProperties) { |
|
212 SDL_SetError("Haptic: Unable to create CFProperties."); |
|
213 return -1; |
|
214 } |
206 |
215 |
207 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also |
216 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also |
208 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties |
217 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties |
209 */ |
218 */ |
210 if ((KERN_SUCCESS == |
219 if ((KERN_SUCCESS == |
211 IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1)) |
220 IORegistryEntryGetParentEntry(dev, kIOServicePlane, &parent1)) |
212 && (KERN_SUCCESS == |
221 && (KERN_SUCCESS == |
213 IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) |
222 IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) |
214 && (KERN_SUCCESS == |
223 && (KERN_SUCCESS == |
215 IORegistryEntryCreateCFProperties(parent2, &usbProperties, |
224 IORegistryEntryCreateCFProperties(parent2, &usbProperties, |
216 kCFAllocatorDefault, |
225 kCFAllocatorDefault, |
217 kNilOptions))) { |
226 kNilOptions))) { |
218 if (usbProperties) { |
227 if (usbProperties) { |
219 CFTypeRef refCF = 0; |
228 CFTypeRef refCF = 0; |
220 /* get device info |
229 /* get device info |
221 * try hid dictionary first, if fail then go to usb dictionary |
230 * try hid dictionary first, if fail then go to usb dictionary |
222 */ |
231 */ |
223 |
232 |
224 |
233 |
225 /* Get product name */ |
234 /* Get product name */ |
226 refCF = |
235 refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); |
227 CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); |
|
228 if (!refCF) |
236 if (!refCF) |
229 refCF = |
237 refCF = |
230 CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); |
238 CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); |
231 if (refCF) { |
239 if (refCF) { |
232 if (!CFStringGetCString(refCF, name, 256, |
240 if (!CFStringGetCString(refCF, name, 256, |