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 #pragma once
4 
5 #include <rsutils/signal.h>
6 #include <rsutils/json.h>
7 #include <vector>
8 #include <map>
9 
10 
11 namespace librealsense
12 {
13  class device_factory;
14  class device_info;
15  class processing_block_interface;
16 
17 
18  class context
19  {
20  context( rsutils::json const & ); // private! use make()
21 
22  void create_factories( std::shared_ptr< context > const & sptr );
23 
24  public:
25  static std::shared_ptr< context > make( rsutils::json const & );
26  static std::shared_ptr< context > make( char const * json_settings );
27 
28  ~context();
29 
30  // The 'device-mask' is specified in the context settings, and governs which devices will be matched by us
31  //
32  unsigned get_device_mask() const { return _device_mask; }
33 
34  // Given the requested RS2_PRODUCT_LINE mask, returns the final mask when combined with the device-mask field in
35  // settings.
36  //
37  // E.g., if the device-mask specifies only D400 devices, and the user requests only SW devices, the result
38  // should be only SW D400 devices.
39  //
40  static unsigned combine_device_masks( unsigned requested_mask, unsigned mask_in_settings );
41 
42  // Query any subset of available devices and return them as device-info objects from which actual devices can be
43  // created as needed.
44  //
45  // Devices will match both the requested mask and the device-mask from the context settings. See
46  // RS2_PRODUCT_LINE_... defines for possible values.
47  //
48  std::vector< std::shared_ptr< device_info > > query_devices( int mask ) const;
49 
51  = std::function< void( std::vector< std::shared_ptr< device_info > > const & devices_removed,
52  std::vector< std::shared_ptr< device_info > > const & devices_added ) >;
53 
54  // Subscribe to a notification to receive when the device-list changes.
55  //
57 
58  // Let the context maintain a list of custom devices. These can be anything, like playback devices or devices
59  // maintained by the user.
60  void add_device( std::shared_ptr< device_info > const & );
61  void remove_device( std::shared_ptr< device_info > const & );
62 
63  const rsutils::json & get_settings() const { return _settings; }
64 
65  // Create processing blocks given a name and settings.
66  //
67  std::shared_ptr< processing_block_interface > create_pp_block( std::string const & name,
68  rsutils::json const & settings );
69 
70  private:
71  void invoke_devices_changed_callbacks( std::vector< std::shared_ptr< device_info > > const & devices_removed,
72  std::vector< std::shared_ptr< device_info > > const & devices_added );
73 
74  std::map< std::string /*address*/, std::weak_ptr< device_info > > _user_devices;
75 
77  std::vector< std::shared_ptr< device_info > > const & /*added*/ >
79 
80  rsutils::json _settings; // Save operation settings
81  unsigned const _device_mask;
82 
83  std::vector< std::shared_ptr< device_factory > > _factories;
84  };
85 
86 }
librealsense
Definition: algo.h:18
librealsense::context::_settings
rsutils::json _settings
Definition: context.h:80
test-device-discovery.devices_removed
int devices_removed
Definition: test-device-discovery.py:119
string
GLsizei const GLchar *const * string
Definition: glad/glad/glad.h:2861
void
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
librealsense::context::query_devices
std::vector< std::shared_ptr< device_info > > query_devices(int mask) const
Definition: context.cpp:109
librealsense::context::_user_devices
std::map< std::string, std::weak_ptr< device_info > > _user_devices
Definition: context.h:74
librealsense::context
Definition: context.h:18
rsutils::signal
Definition: signal.h:35
mask
GLint GLuint mask
Definition: glad/glad/glad.h:1460
librealsense::context::get_settings
const rsutils::json & get_settings() const
Definition: context.h:63
librealsense::context::create_factories
void create_factories(std::shared_ptr< context > const &sptr)
Definition: context.cpp:60
librealsense::context::combine_device_masks
static unsigned combine_device_masks(unsigned requested_mask, unsigned mask_in_settings)
Definition: context.cpp:97
librealsense::context::_device_mask
const unsigned _device_mask
Definition: context.h:81
librealsense::context::create_pp_block
std::shared_ptr< processing_block_interface > create_pp_block(std::string const &name, rsutils::json const &settings)
Definition: context.cpp:180
librealsense::context::remove_device
void remove_device(std::shared_ptr< device_info > const &)
Definition: context.cpp:162
librealsense::context::invoke_devices_changed_callbacks
void invoke_devices_changed_callbacks(std::vector< std::shared_ptr< device_info > > const &devices_removed, std::vector< std::shared_ptr< device_info > > const &devices_added)
Definition: context.cpp:134
devices.settings
dictionary settings
Definition: third-party/realdds/scripts/devices.py:38
librealsense::context::_devices_changed
rsutils::signal< std::vector< std::shared_ptr< device_info > > const &, std::vector< std::shared_ptr< device_info > > const & > _devices_changed
Definition: context.h:78
librealsense::context::~context
~context()
Definition: context.cpp:92
name
GLuint const GLchar * name
Definition: glad/glad/glad.h:2777
signal.h
librealsense::context::_factories
std::vector< std::shared_ptr< device_factory > > _factories
Definition: context.h:83
librealsense::context::on_device_changes
rsutils::subscription on_device_changes(devices_changed_callback &&)
Definition: context.cpp:142
rsutils::json
nlohmann::basic_json< std::map, std::vector, json_key, bool, std::int64_t, std::uint64_t, double, std::allocator, nlohmann::adl_serializer, std::vector< std::uint8_t >, json_base > json
Definition: json-fwd.h:66
librealsense::context::add_device
void add_device(std::shared_ptr< device_info > const &)
Definition: context.cpp:148
librealsense::context::make
static std::shared_ptr< context > make(rsutils::json const &)
Definition: context.cpp:78
librealsense::context::context
context(rsutils::json const &)
Definition: context.cpp:47
rsutils::subscription
Definition: subscription.h:25
json.h
d405.device_info
device_info
Definition: d405.py:8
librealsense::context::get_device_mask
unsigned get_device_mask() const
Definition: context.h:32
test-device-discovery.devices_added
int devices_added
Definition: test-device-discovery.py:118
librealsense::context::devices_changed_callback
std::function< void(std::vector< std::shared_ptr< device_info > > const &devices_removed, std::vector< std::shared_ptr< device_info > > const &devices_added) > devices_changed_callback
Definition: context.h:52


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Fri Aug 2 2024 08:30:01