usb-request.h
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 #pragma once
5 
6 #include "usb-endpoint.h"
7 
8 #include <memory>
9 #include <vector>
10 #include <functional>
11 #include <mutex>
12 #include <queue>
13 
14 namespace librealsense
15 {
16  namespace platform
17  {
19  typedef std::shared_ptr<usb_request_callback> rs_usb_request_callback;
20 
22  {
23  public:
24  virtual rs_usb_endpoint get_endpoint() const = 0;
25  virtual int get_actual_length() const = 0;
26  virtual void set_callback(rs_usb_request_callback callback) = 0;
27  virtual rs_usb_request_callback get_callback() const = 0;
28  virtual void set_client_data(void* data) = 0;
29  virtual void* get_client_data() const = 0;
30  virtual void* get_native_request() const = 0;
31  virtual const std::vector<uint8_t>& get_buffer() const = 0;
32  virtual void set_buffer(const std::vector<uint8_t>& buffer) = 0;
33 
34  protected:
35  virtual void set_native_buffer_length(int length) = 0;
36  virtual int get_native_buffer_length() = 0;
37  virtual void set_native_buffer(uint8_t* buffer) = 0;
38  virtual uint8_t* get_native_buffer() const = 0;
39  };
40 
41  typedef std::shared_ptr<usb_request> rs_usb_request;
42 
44  {
45  public:
46  virtual rs_usb_endpoint get_endpoint() const override { return _endpoint; }
47  virtual void set_callback(rs_usb_request_callback callback) override { _callback = callback; }
48  virtual rs_usb_request_callback get_callback() const override { return _callback; }
49  virtual void set_client_data(void* data) override { _client_data = data; }
50  virtual void* get_client_data() const override { return _client_data; }
51  virtual const std::vector<uint8_t>& get_buffer() const override { return _buffer; }
52  virtual void set_buffer(const std::vector<uint8_t>& buffer) override
53  {
54  _buffer = buffer;
55  set_native_buffer(_buffer.data());
56  set_native_buffer_length( static_cast< int >( _buffer.size() ));
57  }
58 
59  protected:
60  void* _client_data;
61  rs_usb_request request;
63  std::vector<uint8_t> _buffer;
64  rs_usb_request_callback _callback;
65  };
66 
68  std::function<void(rs_usb_request)> _callback;
69  std::mutex _mutex;
70  public:
71  usb_request_callback(std::function<void(rs_usb_request)> callback)
72  {
73  _callback = callback;
74  }
75 
77  {
78  cancel();
79  }
80 
81  void cancel() {
82  std::lock_guard<std::mutex> lk(_mutex);
83  _callback = nullptr;
84  }
85 
86  void callback(rs_usb_request response) {
87  std::lock_guard<std::mutex> lk(_mutex);
88  if (_callback)
89  _callback(response);
90  }
91  };
92  }
93 }
virtual void * get_client_data() const override
Definition: usb-request.h:50
std::shared_ptr< usb_request > rs_usb_request
Definition: usb-request.h:41
virtual int get_actual_length() const =0
virtual void * get_client_data() const =0
virtual rs_usb_request_callback get_callback() const =0
virtual void set_client_data(void *data) override
Definition: usb-request.h:49
virtual void set_buffer(const std::vector< uint8_t > &buffer) override
Definition: usb-request.h:52
virtual const std::vector< uint8_t > & get_buffer() const =0
unsigned char uint8_t
Definition: stdint.h:78
GLenum GLfloat * buffer
rs_usb_request_callback _callback
Definition: usb-request.h:64
virtual void set_native_buffer_length(int length)=0
virtual void set_callback(rs_usb_request_callback callback)=0
std::shared_ptr< usb_endpoint > rs_usb_endpoint
Definition: usb-endpoint.h:24
std::shared_ptr< usb_request_callback > rs_usb_request_callback
Definition: usb-request.h:18
virtual rs_usb_request_callback get_callback() const override
Definition: usb-request.h:48
virtual uint8_t * get_native_buffer() const =0
def callback(frame)
Definition: t265_stereo.py:91
virtual void set_buffer(const std::vector< uint8_t > &buffer)=0
std::function< void(rs_usb_request)> _callback
Definition: usb-request.h:68
void callback(rs_usb_request response)
Definition: usb-request.h:86
virtual void * get_native_request() const =0
virtual void set_client_data(void *data)=0
virtual rs_usb_endpoint get_endpoint() const =0
virtual rs_usb_endpoint get_endpoint() const override
Definition: usb-request.h:46
GLenum GLuint GLenum GLsizei length
virtual const std::vector< uint8_t > & get_buffer() const override
Definition: usb-request.h:51
virtual void set_callback(rs_usb_request_callback callback) override
Definition: usb-request.h:47
GLboolean * data
virtual void set_native_buffer(uint8_t *buffer)=0
Definition: parser.hpp:150
usb_request_callback(std::function< void(rs_usb_request)> callback)
Definition: usb-request.h:71


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