Freenect2 device storage and control. */
| 346 | |
| 347 | /** Freenect2 device storage and control. */ |
| 348 | class Freenect2Impl |
| 349 | { |
| 350 | private: |
| 351 | bool managed_usb_context_; |
| 352 | libusb_context *usb_context_; |
| 353 | EventLoop usb_event_loop_; |
| 354 | public: |
| 355 | struct UsbDeviceWithSerial |
| 356 | { |
| 357 | libusb_device *dev; |
| 358 | std::string serial; |
| 359 | }; |
| 360 | typedef std::vector<UsbDeviceWithSerial> UsbDeviceVector; |
| 361 | typedef std::vector<Freenect2DeviceImpl *> DeviceVector; |
| 362 | |
| 363 | bool has_device_enumeration_; |
| 364 | UsbDeviceVector enumerated_devices_; |
| 365 | DeviceVector devices_; |
| 366 | |
| 367 | bool initialized; |
| 368 | |
| 369 | Freenect2Impl(void *usb_context) : |
| 370 | managed_usb_context_(usb_context == 0), |
| 371 | usb_context_(reinterpret_cast<libusb_context *>(usb_context)), |
| 372 | has_device_enumeration_(false), |
| 373 | initialized(false) |
| 374 | { |
| 375 | #ifdef __linux__ |
| 376 | if (libusb_get_version()->nano < 10952) |
| 377 | { |
| 378 | LOG_ERROR << "Your libusb does not support large iso buffer!"; |
| 379 | return; |
| 380 | } |
| 381 | #endif |
| 382 | |
| 383 | if(managed_usb_context_) |
| 384 | { |
| 385 | int r = libusb_init(&usb_context_); |
| 386 | if(r != 0) |
| 387 | { |
| 388 | LOG_ERROR << "failed to create usb context: " << WRITE_LIBUSB_ERROR(r); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | #if defined(_WIN32) || defined (__WIN32__) || defined(__WINDOWS__) |
| 393 | (void)libusb_set_option(usb_context_, LIBUSB_OPTION_USE_USBDK); |
| 394 | #endif |
| 395 | } |
| 396 | |
| 397 | usb_event_loop_.start(usb_context_); |
| 398 | initialized = true; |
| 399 | } |
| 400 | |
| 401 | ~Freenect2Impl() |
| 402 | { |
| 403 | if (!initialized) |
| 404 | return; |
| 405 |
nothing calls this directly
no outgoing calls
no test coverage detected