MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / hid_enumerate

Function hid_enumerate

lib/hidapi/mac/hid.c:700–791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

698}
699
700struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
701{
702 struct hid_device_info *root = NULL; /* return object */
703 struct hid_device_info *cur_dev = NULL;
704 CFIndex num_devices;
705 int i;
706
707 /* Set up the HID Manager if it hasn't been done */
708 if (hid_init() < 0) {
709 return NULL;
710 }
711 /* register_global_error: global error is set/reset by hid_init */
712
713 /* give the IOHIDManager a chance to update itself */
714 process_pending_events();
715
716 /* Get a list of the Devices */
717 CFMutableDictionaryRef matching = NULL;
718 if (vendor_id != 0 || product_id != 0) {
719 matching = CFDictionaryCreateMutable(kCFAllocatorDefault, kIOHIDOptionsTypeNone, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
720
721 if (matching && vendor_id != 0) {
722 CFNumberRef v = CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &vendor_id);
723 CFDictionarySetValue(matching, CFSTR(kIOHIDVendorIDKey), v);
724 CFRelease(v);
725 }
726
727 if (matching && product_id != 0) {
728 CFNumberRef p = CFNumberCreate(kCFAllocatorDefault, kCFNumberShortType, &product_id);
729 CFDictionarySetValue(matching, CFSTR(kIOHIDProductIDKey), p);
730 CFRelease(p);
731 }
732 }
733 IOHIDManagerSetDeviceMatching(hid_mgr, matching);
734 if (matching != NULL) {
735 CFRelease(matching);
736 }
737
738 CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
739
740 IOHIDDeviceRef *device_array = NULL;
741
742 if (device_set != NULL) {
743 /* Convert the list into a C array so we can iterate easily. */
744 num_devices = CFSetGetCount(device_set);
745 device_array = (IOHIDDeviceRef*) calloc(num_devices, sizeof(IOHIDDeviceRef));
746 CFSetGetValues(device_set, (const void **) device_array);
747 } else {
748 num_devices = 0;
749 }
750
751 /* Iterate over each device, making an entry for it. */
752 for (i = 0; i < num_devices; i++) {
753
754 IOHIDDeviceRef dev = device_array[i];
755 if (!dev) {
756 continue;
757 }

Callers 6

hid.cFile · 0.70
mainFunction · 0.50
hid.cFile · 0.50
mainFunction · 0.50
onRescanMethod · 0.50
enumerateDevicesMethod · 0.50

Calls 3

process_pending_eventsFunction · 0.85
create_device_infoFunction · 0.85
register_global_errorFunction · 0.70

Tested by 2

mainFunction · 0.40
onRescanMethod · 0.40