| 163 | } |
| 164 | |
| 165 | static std::vector<USBDeviceInfo> getPollingBasedDeviceList() |
| 166 | { |
| 167 | // Polling can be very expensive |
| 168 | // Perform this operation at most once every 10 seconds |
| 169 | static const int timeout = 10; |
| 170 | static std::vector<USBDeviceInfo> deviceList = {}; |
| 171 | static std::chrono::high_resolution_clock::time_point lastUpdate = {}; |
| 172 | |
| 173 | std::lock_guard<std::mutex> lock(mutex); |
| 174 | auto now = std::chrono::high_resolution_clock::now(); |
| 175 | if (std::chrono::duration_cast<std::chrono::seconds>(now - lastUpdate) |
| 176 | .count() >= timeout) { |
| 177 | deviceList = pollUSBDevices(); |
| 178 | lastUpdate = now; |
| 179 | } |
| 180 | |
| 181 | return deviceList; |
| 182 | } |
| 183 | |
| 184 | std::vector<USBDeviceInfo> GetUSBDevices() |
| 185 | { |
no test coverage detected