#include "IGScanManager.h" #include #include "libusbex.h" IGScanManager::IGScanManager(): brun(false) { #ifndef _WIN32 libusb_init(0); //libusb_set_debug(nullptr,LIBUSB_LOG_LEVEL_DEBUG|LIBUSB_LOG_LEVEL_ERROR|LIBUSB_LOG_LEVEL_INFO); #else std::cout<joinable()) { brun=false; m_usbnotifythread->join(); m_usbnotifythread.reset(); } libusb_exit(0); #endif } std::vector IGScanManager::getonlinedevices() { #ifndef _WIN32 return m_devices; #else m_devices.clear(); auto usblist = UsbScan_List::find_all_usb(); for(auto it =usblist.begin();it!=usblist.end();it++) for(auto i = 0;iIsConnected()) { timeval tm={1,0}; //auto ret =libusb_handle_events_completed(nullptr,nullptr); auto ret=libusb_handle_events_timeout(0,&tm); if(ret<0) printf("libusb_handle_events_timeout error %s\n",libusb_error_name(ret)); } std::this_thread::sleep_for(chrono::milliseconds(10)); } } int IGScanManager::OnUsbHotplugCallback(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *monitor) { IGScanManager* This = (IGScanManager*)monitor; return This->OnUsbHotplug(ctx, device, event); } void IGScanManager::registehotplug() { auto ret = libusb_hotplug_register_callback(0,(libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), (libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE, LIBUSB_HOTPLUG_MATCH_ANY,//LIBUSB_HOTPLUG_MATCH_ANY LIBUSB_HOTPLUG_MATCH_ANY,//LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, OnUsbHotplugCallback, this, &handle); if(ret!=LIBUSB_SUCCESS) { std::cout<<"WARRNNING register usb hotplug callback error"<