context.h
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 #pragma once
5 
6 #include "types.h"
7 #include "backend.h"
8 #include "mock/recorder.h"
9 #include "core/streaming.h"
10 
11 #include <vector>
13 
14 namespace librealsense
15 {
16  class context;
17  class device_info;
18 }
19 
21 {
22  std::shared_ptr<librealsense::context> ctx;
23  std::shared_ptr<librealsense::device_info> info;
24 };
25 
27 {
28  std::shared_ptr<librealsense::context> ctx;
29  std::vector<rs2_device_info> list;
30 };
31 
33 {
35  std::shared_ptr<librealsense::stream_profile_interface> clone;
36 };
37 
38 namespace librealsense
39 {
40  class device;
41  class context;
42 
44  {
45  public:
46  virtual std::shared_ptr<device_interface> create_device(bool register_device_notifications = false) const
47  {
48  return create(_ctx, register_device_notifications);
49  }
50 
51  virtual ~device_info() = default;
52 
53  virtual platform::backend_device_group get_device_data()const = 0;
54 
55  virtual bool operator==(const device_info& other) const
56  {
57  return other.get_device_data() == get_device_data();
58  }
59 
60  protected:
61  explicit device_info(std::shared_ptr<context> backend)
62  : _ctx(move(backend))
63  {}
64 
65  virtual std::shared_ptr<device_interface> create(std::shared_ptr<context> ctx,
66  bool register_device_notifications) const = 0;
67 
68  std::shared_ptr<context> _ctx;
69  };
70 
71  enum class backend_type
72  {
73  standard,
74  record,
75  playback
76  };
77 
78 
80  {
81  std::shared_ptr<playback_device> _dev;
82  public:
83  explicit playback_device_info(std::shared_ptr<playback_device> dev)
84  : device_info(nullptr), _dev(dev)
85  {
86 
87  }
88 
89  std::shared_ptr<device_interface> create_device(bool) const override
90  {
91  return _dev;
92  }
94  {
95  return platform::backend_device_group({ platform::playback_device_info{ _dev->get_file_name() } });
96  }
97 
98  std::shared_ptr<device_interface> create(std::shared_ptr<context>, bool) const override
99  {
100  return _dev;
101  }
102  };
103 
104  typedef std::vector<std::shared_ptr<device_info>> devices_info;
105 
106  class context : public std::enable_shared_from_this<context>
107  {
108  public:
109  explicit context(backend_type type,
110  const char* filename = nullptr,
111  const char* section = nullptr,
113  std::string min_api_version = "0.0.0");
114 
115  void stop(){ if (!_devices_changed_callbacks.size()) _device_watcher->stop();}
116  ~context();
117  std::vector<std::shared_ptr<device_info>> query_devices(int mask) const;
118  const platform::backend& get_backend() const { return *_backend; }
119 
120  uint64_t register_internal_device_callback(devices_changed_callback_ptr callback);
121  void unregister_internal_device_callback(uint64_t cb_id);
122  void set_devices_changed_callback(devices_changed_callback_ptr callback);
123 
124  std::vector<std::shared_ptr<device_info>> create_devices(platform::backend_device_group devices,
125  const std::map<std::string, std::weak_ptr<device_info>>& playback_devices, int mask) const;
126 
127  std::shared_ptr<playback_device_info> add_device(const std::string& file);
128  void remove_device(const std::string& file);
129 
130  void add_software_device(std::shared_ptr<device_info> software_device);
131 
132 #if WITH_TRACKING
133  void unload_tracking_module();
134 #endif
135 
136  private:
137  void on_device_changed(platform::backend_device_group old,
139  const std::map<std::string, std::weak_ptr<device_info>>& old_playback_devices,
140  const std::map<std::string, std::weak_ptr<device_info>>& new_playback_devices);
141  void raise_devices_changed(const std::vector<rs2_device_info>& removed, const std::vector<rs2_device_info>& added);
142  int find_stream_profile(const stream_interface& p);
143  std::shared_ptr<lazy<rs2_extrinsics>> fetch_edge(int from, int to);
144 
145  std::shared_ptr<platform::backend> _backend;
146  std::shared_ptr<platform::device_watcher> _device_watcher;
147  std::map<std::string, std::weak_ptr<device_info>> _playback_devices;
148  std::map<uint64_t, devices_changed_callback_ptr> _devices_changed_callbacks;
149 
151  std::map<int, std::weak_ptr<const stream_interface>> _streams;
152  std::map<int, std::map<int, std::weak_ptr<lazy<rs2_extrinsics>>>> _extrinsics;
153  std::mutex _streams_mutex, _devices_changed_callbacks_mtx;
154  };
155 
157  {
158  public:
159  readonly_device_info(std::shared_ptr<device_interface> dev) : device_info(dev->get_context()), _dev(dev) {}
160  std::shared_ptr<device_interface> create(std::shared_ptr<context> ctx, bool register_device_notifications) const override
161  {
162  return _dev;
163  }
164 
166  {
167  return _dev->get_device_data();
168  }
169  private:
170  std::shared_ptr<device_interface> _dev;
171  };
172 
173  // Helper functions for device list manipulation:
174  std::vector<platform::uvc_device_info> filter_by_product(const std::vector<platform::uvc_device_info>& devices, const std::set<uint16_t>& pid_list);
175  std::vector<std::pair<std::vector<platform::uvc_device_info>, std::vector<platform::hid_device_info>>> group_devices_and_hids_by_unique_id(
176  const std::vector<std::vector<platform::uvc_device_info>>& devices,
177  const std::vector<platform::hid_device_info>& hids);
178  std::vector<std::vector<platform::uvc_device_info>> group_devices_by_unique_id(const std::vector<platform::uvc_device_info>& devices);
179  void trim_device_list(std::vector<platform::uvc_device_info>& devices, const std::vector<platform::uvc_device_info>& chosen);
180  bool mi_present(const std::vector<platform::uvc_device_info>& devices, uint32_t mi);
181  platform::uvc_device_info get_mi(const std::vector<platform::uvc_device_info>& devices, uint32_t mi);
182  std::vector<platform::uvc_device_info> filter_by_mi(const std::vector<platform::uvc_device_info>& devices, uint32_t mi);
183 
184  std::vector<platform::usb_device_info> filter_by_product(const std::vector<platform::usb_device_info>& devices, const std::set<uint16_t>& pid_list);
185  void trim_device_list(std::vector<platform::usb_device_info>& devices, const std::vector<platform::usb_device_info>& chosen);
186 }
std::shared_ptr< librealsense::context > ctx
Definition: context.h:28
std::shared_ptr< librealsense::context > ctx
Definition: context.h:22
std::vector< platform::uvc_device_info > filter_by_product(const std::vector< platform::uvc_device_info > &devices, const std::set< uint16_t > &pid_list)
Definition: context.cpp:478
playback_device_info(std::shared_ptr< playback_device > dev)
Definition: context.h:83
virtual bool operator==(const device_info &other) const
Definition: context.h:55
virtual platform::backend_device_group get_device_data() const =0
std::map< std::string, std::weak_ptr< device_info > > _playback_devices
Definition: context.h:147
std::shared_ptr< librealsense::device_info > info
Definition: context.h:23
GLfloat GLfloat p
Definition: glext.h:12687
platform::backend_device_group get_device_data() const override
Definition: context.h:165
void trim_device_list(std::vector< platform::usb_device_info > &devices, const std::vector< platform::usb_device_info > &chosen)
Definition: context.cpp:600
std::vector< std::shared_ptr< device_info > > devices_info
Definition: context.h:104
rs2_recording_mode
Definition: rs_internal.h:32
GLint GLuint mask
const platform::backend & get_backend() const
Definition: context.h:118
GLsizei const GLchar *const * string
std::vector< rs2_device_info > list
Definition: context.h:29
std::shared_ptr< device_interface > create(std::shared_ptr< context >, bool) const override
Definition: context.h:98
std::map< int, std::weak_ptr< const stream_interface > > _streams
Definition: context.h:151
std::mutex _streams_mutex
Definition: context.h:153
GLenum mode
std::shared_ptr< context > _ctx
Definition: context.h:68
std::vector< std::pair< std::vector< platform::uvc_device_info >, std::vector< platform::hid_device_info > > > group_devices_and_hids_by_unique_id(const std::vector< std::vector< platform::uvc_device_info >> &devices, const std::vector< platform::hid_device_info > &hids)
Definition: context.cpp:501
std::shared_ptr< librealsense::stream_profile_interface > clone
Definition: context.h:35
std::vector< std::vector< platform::uvc_device_info > > group_devices_by_unique_id(const std::vector< platform::uvc_device_info > &devices)
Definition: context.cpp:583
std::map< int, std::map< int, std::weak_ptr< lazy< rs2_extrinsics > > > > _extrinsics
Definition: context.h:152
readonly_device_info(std::shared_ptr< device_interface > dev)
Definition: context.h:159
platform::backend_device_group get_device_data() const override
Definition: context.h:93
unsigned int uint32_t
Definition: stdint.h:80
devices
Definition: test-fg.py:9
platform::uvc_device_info get_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:634
def callback(frame)
Definition: t265_stereo.py:91
unsigned __int64 uint64_t
Definition: stdint.h:90
std::shared_ptr< playback_device > _dev
Definition: context.h:81
std::shared_ptr< platform::device_watcher > _device_watcher
Definition: context.h:146
std::shared_ptr< device_interface > create(std::shared_ptr< context > ctx, bool register_device_notifications) const override
Definition: context.h:160
virtual std::shared_ptr< device_interface > create_device(bool register_device_notifications=false) const
Definition: context.h:46
librealsense::stream_profile_interface * profile
Definition: context.h:34
std::shared_ptr< device_interface > create_device(bool) const override
Definition: context.h:89
GLenum type
std::map< uint64_t, devices_changed_callback_ptr > _devices_changed_callbacks
Definition: context.h:148
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
std::shared_ptr< platform::backend > _backend
Definition: context.h:145
std::shared_ptr< rs2_devices_changed_callback > devices_changed_callback_ptr
Definition: src/types.h:1076
device_info(std::shared_ptr< context > backend)
Definition: context.h:61
std::vector< platform::uvc_device_info > filter_by_mi(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:644
std::shared_ptr< device_interface > _dev
Definition: context.h:170
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
Definition: catch.hpp:4271
auto device
Definition: pyrs_net.cpp:17
devices_changed_callback_ptr _devices_changed_callback
Definition: context.h:150
bool mi_present(const std::vector< platform::uvc_device_info > &devices, uint32_t mi)
Definition: context.cpp:624


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