interface-winusb.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "interface-winusb.h"
5 #include "win/win-helpers.h"
6 #include "messenger-winusb.h"
7 #include "handle-winusb.h"
8 
9 #include "types.h"
10 
11 namespace librealsense
12 {
13  namespace platform
14  {
15  usb_interface_winusb::usb_interface_winusb(WINUSB_INTERFACE_HANDLE handle, USB_INTERFACE_DESCRIPTOR info, const std::wstring& device_path) :
16  _info(info), _device_path(device_path)
17  {
18  USB_CONFIGURATION_DESCRIPTOR cfgDesc;
19  ULONG returnLength = 0;
20  if (!WinUsb_GetDescriptor(handle, USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, (PUCHAR)&cfgDesc, sizeof(cfgDesc), &returnLength))
21  {
22  throw winapi_error("WinUsb action failed, last error: " + GetLastError());
23  }
24 
25  std::vector<uint8_t> config(cfgDesc.wTotalLength);
26 
27  // Returns configuration descriptor - including all interface, endpoint, class-specific, and vendor-specific descriptors
28  if (!WinUsb_GetDescriptor(handle, USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, config.data(), cfgDesc.wTotalLength, &returnLength))
29  {
30  throw winapi_error("WinUsb action failed, last error: " + GetLastError());
31  }
32 
33  for (int i = 0; i < info.bNumEndpoints; i++) {
34  WINUSB_PIPE_INFORMATION pipeInformation;
35  if (!WinUsb_QueryPipe(handle, info.bAlternateSetting, i, &pipeInformation)) {
36  auto error = GetLastError();
37  if (error != ERROR_NO_MORE_ITEMS)
38  throw winapi_error("WinUsb action failed, last error: " + error);
39  break;
40  }
41  _endpoints.push_back(std::make_shared<usb_endpoint_winusb>(pipeInformation, info.bInterfaceNumber));
42  }
43  }
44 
46  {
47  for (auto&& ep : _endpoints)
48  {
49  if (ep->get_type() != type)
50  continue;
51  if (ep->get_direction() != direction)
52  continue;
53  return ep;
54  }
55  return nullptr;
56  }
57  }
58 }
GLuint64 GLenum void * handle
Definition: glext.h:7785
usb_interface_winusb(WINUSB_INTERFACE_HANDLE handle, USB_INTERFACE_DESCRIPTOR info, const std::wstring &device_path)
direction
Definition: rs-align.cpp:25
enum librealsense::platform::_endpoint_direction endpoint_direction
def info(name, value, persistent=False)
Definition: test.py:301
std::shared_ptr< usb_endpoint > rs_usb_endpoint
Definition: usb-endpoint.h:24
virtual const rs_usb_endpoint first_endpoint(const endpoint_direction direction, const endpoint_type type=RS2_USB_ENDPOINT_BULK) const override
GLenum type
int i
enum librealsense::platform::_endpoint_type endpoint_type
std::vector< std::shared_ptr< usb_endpoint > > _endpoints


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:17