4 #if (_MSC_FULL_VER < 180031101) 5 #error At least Visual Studio 2013 Update 4 is required to compile this backend 25 #pragma comment(lib, "winusb.lib") 32 const std::map<std::string, usb_class>
guids = {
44 std::vector<std::wstring> rv;
46 CONFIGRET
cr = CR_SUCCESS;
50 cr = CM_Get_Device_Interface_List_Size(&length, (LPGUID)&guid,
NULL,
51 CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
56 std::vector<WCHAR> device_list(length);
57 cr = CM_Get_Device_Interface_List((LPGUID)&guid,
NULL, device_list.data(),
length,
58 CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
61 while (offset < length)
63 auto str = std::wstring((device_list.data() +
offset));
66 offset +=
str.size() + 1;
68 }
while (cr == CR_BUFFER_SMALL);
76 std::wstring guidWStr(guidStr.begin(), guidStr.end());
77 CHECK_HR(CLSIDFromString(guidWStr.c_str(),
static_cast<LPCLSID
>(&guid)));
85 std::string device_str(device_wstr.begin(), device_wstr.end());
87 std::regex regex_camera_interface(
"\\b(.*VID_)(.*)(&PID_)(.*)(&MI_)(.*)(#.*&)(.*)(&.*)(&.*)(.*#)(.*)", std::regex_constants::icase);
88 std::regex regex_usb_interface(
"\\b(.*VID_)(.*)(&PID_)(.*)(#.*&)(.*)(&.*)(&.*)", std::regex_constants::icase);
89 std::regex regex_dfu_interface(
"\\b(.*VID_)(.*)(&PID_)(.*)(#)(.*)(#)(.*)", std::regex_constants::icase);
91 if (std::regex_search(device_str, matches, regex_camera_interface) && matches.size() == 13)
94 std::stringstream vid; vid << std::hex << matches[2]; vid >> rv.vid;
95 std::stringstream pid; pid << std::hex << matches[4]; pid >> rv.pid;
96 std::stringstream mi; mi << std::hex << matches[6]; mi >> rv.mi;
97 std::stringstream
uid; uid << std::hex << matches[8]; uid >> rv.unique_id;
98 auto it = guids.find(matches[12]);
102 if (std::regex_search(device_str, matches, regex_usb_interface) && matches.size() == 9)
105 std::stringstream vid; vid << std::hex << matches[2]; vid >> rv.vid;
106 std::stringstream pid; pid << std::hex << matches[4]; pid >> rv.pid;
107 std::stringstream
uid; uid << std::hex << matches[6]; uid >> rv.unique_id;
111 if (std::regex_search(device_str, matches, regex_dfu_interface))
114 std::stringstream vid; vid << std::hex << matches[2]; vid >> rv.vid;
115 std::stringstream pid; pid << std::hex << matches[4]; pid >> rv.pid;
116 std::stringstream
uid; uid << std::hex << matches[6]; uid >> rv.unique_id;
126 std::vector<usb_device_info> rv;
128 for (
auto&&
guid : guids)
143 std::vector<std::wstring> devices_path;
145 for (
auto&&
guid : guids)
150 if ((
i.vid == info.
vid) && (
i.pid == info.
pid) && (
i.id == info.
id))
151 devices_path.push_back(
id);
155 if (devices_path.size() == 0)
157 LOG_WARNING(
"failed to locate usb interfaces for device: " << info.
id);
163 return std::make_shared<usb_device_winusb>(
info, devices_path);
165 catch (std::exception
e)
167 LOG_WARNING(
"failed to create usb device: " << info.
id <<
", error: " << e.what());
GLsizei const GLchar *const * string
def info(name, value, persistent=False)
GLenum GLuint GLenum GLsizei length