request-usbhost.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include "request-usbhost.h"
5 #include "endpoint-usbhost.h"
6 #include "device-usbhost.h"
7 
8 namespace librealsense
9 {
10  namespace platform
11  {
13  {
14  _endpoint = endpoint;
15  auto dev = std::static_pointer_cast<usb_device_usbhost>(device);
16  auto read_ep = std::static_pointer_cast<usb_endpoint_usbhost>(_endpoint);
17  auto desc = read_ep->get_descriptor();
18  _native_request = std::shared_ptr<::usb_request>(usb_request_new(dev->get_handle(), &desc),
19  [this](::usb_request* req)
20  {
21  if(!_active)
22  usb_request_free(req);
23  else
24  LOG_ERROR("active request didn't return on time");
25  });
26  _native_request->client_data = this;
27  }
28 
30  {
31  if(_active)
33 
34  int attempts = 10;
35  while(_active && attempts--)
36  std::this_thread::sleep_for(std::chrono::milliseconds(10));
37  }
38 
40  {
41  _active = state;
42  }
43 
45  {
46  return _native_request->buffer_length;
47  }
48 
50  {
51  _native_request->buffer_length = length;
52  }
53 
55  {
56  return _native_request->actual_length;
57  }
58 
60  {
61  _native_request->buffer = buffer;
62  }
63 
65  {
66  return (uint8_t*)_native_request->buffer;
67  }
68 
70  {
71  return _native_request.get();
72  }
73 
74  std::shared_ptr<usb_request> usb_request_usbhost::get_shared() const
75  {
76  return _shared.lock();
77  }
78 
79  void usb_request_usbhost::set_shared(const std::shared_ptr<usb_request>& shared)
80  {
81  _shared = shared;
82  }
83  }
84 }
void set_shared(const std::shared_ptr< usb_request > &shared)
std::shared_ptr< usb_request > get_shared() const
virtual void set_native_buffer_length(int length) override
std::shared_ptr<::usb_request > _native_request
std::weak_ptr< usb_request > _shared
unsigned char uint8_t
Definition: stdint.h:78
GLenum GLfloat * buffer
usb_request_usbhost(rs_usb_device device, rs_usb_endpoint endpoint)
virtual void set_native_buffer(uint8_t *buffer) override
virtual int get_actual_length() const override
std::shared_ptr< usb_endpoint > rs_usb_endpoint
Definition: usb-endpoint.h:24
void usb_request_free(struct usb_request *req)
Definition: usbhost.c:720
virtual void * get_native_request() const override
#define LOG_ERROR(...)
Definition: src/types.h:242
int usb_request_cancel(struct usb_request *req)
Definition: usbhost.c:776
struct usb_request * usb_request_new(struct usb_device *dev, const struct usb_endpoint_descriptor *ep_desc)
Definition: usbhost.c:687
GLenum GLuint GLenum GLsizei length
virtual uint8_t * get_native_buffer() const override
auto device
Definition: pyrs_net.cpp:17
std::shared_ptr< usb_device > rs_usb_device
Definition: usb-device.h:29


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