| 68 | } |
| 69 | |
| 70 | static std::vector<USBDeviceInfo> pollUSBDevices() |
| 71 | { |
| 72 | libusb_device **devices; |
| 73 | ssize_t count = libusb_get_device_list(NULL, &devices); |
| 74 | if (count < 0) { |
| 75 | logLibusbError(count, "Failed to query device list"); |
| 76 | return {}; |
| 77 | } |
| 78 | |
| 79 | std::vector<USBDeviceInfo> result; |
| 80 | |
| 81 | for (int i = 0; i < count; i++) { |
| 82 | libusb_device *device = devices[i]; |
| 83 | struct libusb_device_descriptor descriptor; |
| 84 | |
| 85 | int ret = libusb_get_device_descriptor(device, &descriptor); |
| 86 | if (ret != LIBUSB_SUCCESS) { |
| 87 | logLibusbError(ret, "Error getting device descriptor"); |
| 88 | continue; |
| 89 | } |
| 90 | |
| 91 | libusb_device_handle *handle; |
| 92 | ret = libusb_open(device, &handle); |
| 93 | if (ret != LIBUSB_SUCCESS) { |
| 94 | logLibusbError(ret, "Error opening device"); |
| 95 | continue; |
| 96 | } |
| 97 | result.emplace_back(getDeviceInfo(device, handle, descriptor)); |
| 98 | libusb_close(handle); |
| 99 | } |
| 100 | |
| 101 | libusb_free_device_list(devices, 1); |
| 102 | |
| 103 | return result; |
| 104 | } |
| 105 | |
| 106 | static int hotplugCallback(struct libusb_context *, |
| 107 | struct libusb_device *device, |
no test coverage detected