Closed
Description
Assuming the manufacturer of a device did not use serial_numbers to make particular hid devices unique. Is there a way to uniquely map from a given already open hid_device opaque pointer / handle back to a hid_device_info struct in the linked list provided by hid_enumerate(0,0)?
I initially thought that I could do something like the following:
hid_device_info match_device(hid_device *given_dev) {
hid_device_info info = {};
hid_device_info *first = hid_enumerate(0,0);
for(hid_device_info *cur=first, cur; cur=cur->next) {
hid_device *test_dev = hid_open_path(cur->path);
if (test_dev == given_dev) {
memcpy(&info, cur, sizeof(info));
info->next = NULL;
} else {
hid_close(test_dev);
}
}
hid_free_enumeration(first);
return info;
}
Unfortunately, on windows the second hid_open_path function returns a handle that is not identical to the provided handle. As such this code can not return a match.
An alternative method would be if there were a function to extract the path from a given hid_device. In this case, the above code could be modified as following:
hid_device_info match_device(hid_device *given_dev) {
hid_device_info info = {};
/* hypothetical function to get path given an hid_device pointer */
const char *path = hid_device_path(given_dev);
hid_device_info *first = hid_enumerate(0,0);
for(hid_device_info *cur=first, cur; cur=cur->next) {
if (strcmp(path, cur->path) == 0) {
memcpy(&info, cur, sizeof(info));
info->next = NULL;
break;
}
}
hid_free_enumeration(first);
return info;
}
Is there a way to get the path from a hid_device pointer?