Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
rs_types.hpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #ifndef LIBREALSENSE_RS2_TYPES_HPP
5 #define LIBREALSENSE_RS2_TYPES_HPP
6 
7 #include "../rs.h"
8 #include "../h/rs_context.h"
9 #include "../h/rs_device.h"
10 #include "../h/rs_frame.h"
11 #include "../h/rs_processing.h"
12 #include "../h/rs_record_playback.h"
13 #include "../h/rs_sensor.h"
14 #include "../h/rs_pipeline.h"
15 
16 #include <string>
17 #include <vector>
18 #include <memory>
19 #include <functional>
20 #include <exception>
21 #include <iterator>
22 #include <sstream>
23 #include <chrono>
24 #include <cstring>
25 
27 {
28  virtual void on_frame(rs2_frame * f) = 0;
29  virtual void release() = 0;
30  virtual ~rs2_frame_callback() {}
31 };
32 typedef std::shared_ptr<rs2_frame_callback> rs2_frame_callback_sptr;
33 
35 {
36  virtual void on_frame(rs2_frame * f, rs2_source * source) = 0;
37  virtual void release() = 0;
39 };
40 typedef std::shared_ptr<rs2_frame_processor_callback> rs2_frame_processor_callback_sptr;
41 
43 {
44  virtual void on_notification(rs2_notification* n) = 0;
45  virtual void release() = 0;
47 };
48 typedef std::shared_ptr<rs2_notifications_callback> rs2_notifications_callback_sptr;
49 
50 typedef void ( *log_callback_function_ptr )(rs2_log_severity severity, rs2_log_message const * msg );
51 
53 {
54  virtual void on_destruction() = 0;
55  virtual void release() = 0;
57 };
58 typedef std::shared_ptr<rs2_software_device_destruction_callback> rs2_software_device_destruction_callback_sptr;
59 
61 {
62  virtual void on_log( rs2_log_severity severity, rs2_log_message const & msg ) noexcept = 0;
63  virtual void release() = 0;
64  virtual ~rs2_log_callback() {}
65 };
66 typedef std::shared_ptr< rs2_log_callback > rs2_log_callback_sptr;
67 
69 {
70  virtual void on_calibration_change( rs2_calibration_status ) noexcept = 0;
71  virtual void release() = 0;
73 };
74 typedef std::shared_ptr<rs2_calibration_change_callback> rs2_calibration_change_callback_sptr;
75 
77 {
78  virtual void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) = 0;
79  virtual void release() = 0;
81 };
82 typedef std::shared_ptr<rs2_devices_changed_callback> rs2_devices_changed_callback_sptr;
83 
85 {
86  virtual void on_playback_status_changed(rs2_playback_status status) = 0;
87  virtual void release() = 0;
89 };
90 typedef std::shared_ptr<rs2_playback_status_changed_callback> rs2_playback_status_changed_callback_sptr;
91 
93 {
94  virtual void on_update_progress(const float update_progress) = 0;
95  virtual void release() = 0;
97 };
98 typedef std::shared_ptr<rs2_update_progress_callback> rs2_update_progress_callback_sptr;
99 
101 {
102  virtual void on_value_changed( rs2_options_list * list ) = 0;
103  virtual void release() = 0;
105 };
106 typedef std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr;
107 
108 namespace rs2
109 {
110  class error : public std::runtime_error
111  {
112  std::string function, args;
113  rs2_exception_type type;
114  public:
115  explicit error(rs2_error* err) : runtime_error(rs2_get_error_message(err))
116  {
117  function = (nullptr != rs2_get_failed_function(err)) ? rs2_get_failed_function(err) : std::string();
118  args = (nullptr != rs2_get_failed_args(err)) ? rs2_get_failed_args(err) : std::string();
120  rs2_free_error(err);
121  }
122 
123  explicit error(const std::string& message) : runtime_error(message.c_str())
124  {
125  function = "";
126  args = "";
128  }
129 
130  const std::string& get_failed_function() const
131  {
132  return function;
133  }
134 
135  const std::string& get_failed_args() const
136  {
137  return args;
138  }
139 
140  rs2_exception_type get_type() const { return type; }
141 
142  static void handle(rs2_error* e);
143  };
144 
145  #define RS2_ERROR_CLASS(name, base) \
146  class name : public base\
147  {\
148  public:\
149  explicit name(rs2_error* e) noexcept : base(e) {}\
150  }
151 
152  RS2_ERROR_CLASS(recoverable_error, error);
153  RS2_ERROR_CLASS(unrecoverable_error, error);
154  RS2_ERROR_CLASS(camera_disconnected_error, unrecoverable_error);
155  RS2_ERROR_CLASS(backend_error, unrecoverable_error);
156  RS2_ERROR_CLASS(device_in_recovery_mode_error, unrecoverable_error);
157  RS2_ERROR_CLASS(invalid_value_error, recoverable_error);
158  RS2_ERROR_CLASS(wrong_api_call_sequence_error, recoverable_error);
159  RS2_ERROR_CLASS(not_implemented_error, recoverable_error);
160  #undef RS2_ERROR_CLASS
161 
162  inline void error::handle(rs2_error* e)
163  {
164  if (e)
165  {
167  switch (h) {
169  throw camera_disconnected_error(e);
171  throw backend_error(e);
173  throw invalid_value_error(e);
175  throw wrong_api_call_sequence_error(e);
177  throw not_implemented_error(e);
179  throw device_in_recovery_mode_error(e);
180  default:
181  throw error(e);
182  }
183  }
184  }
185 
186  class context;
187  class device;
188  class device_list;
189  class syncer;
190  class device_base;
191  class roi_sensor;
192  class frame;
193 
195  {
196  float min;
197  float max;
198  float def;
199  float step;
200  };
201 
203  {
204  int min_x;
205  int min_y;
206  int max_x;
207  int max_y;
208  };
209 }
210 
211 inline std::ostream & operator << (std::ostream & o, rs2_vector v) { return o << v.x << ", " << v.y << ", " << v.z; }
212 inline std::ostream & operator << (std::ostream & o, rs2_quaternion q) { return o << q.x << ", " << q.y << ", " << q.z << ", " << q.w; }
213 
214 inline bool operator==(rs2_calibration_config const& self, rs2_calibration_config const& other)
215 {
216  return !std::memcmp(&self, &other, sizeof(rs2_calibration_config));
217 }
218 
219 #endif // LIBREALSENSE_RS2_TYPES_HPP
Definition: rs_types.hpp:110
Definition: rs_types.hpp:26
Definition: rs_types.hpp:100
const std::string & get_failed_args() const
Definition: rs_types.hpp:135
Definition: rs_frame.hpp:345
Definition: rs_types.hpp:202
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition: rs_types.h:32
virtual void on_update_progress(const float update_progress)=0
float y
Definition: rs_types.h:107
void rs2_free_error(rs2_error *error)
std::ostream & operator<<(std::ostream &o, rs2_vector v)
Definition: rs_types.hpp:211
virtual ~rs2_log_callback()
Definition: rs_types.hpp:64
std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr
Definition: rs_types.hpp:106
virtual void on_frame(rs2_frame *f)=0
float z
Definition: rs_types.h:101
Definition: rs_types.hpp:42
int min_x
Definition: rs_types.hpp:204
Definition: rs_types.h:39
virtual void release()=0
std::shared_ptr< rs2_software_device_destruction_callback > rs2_software_device_destruction_callback_sptr
Definition: rs_types.hpp:58
virtual ~rs2_software_device_destruction_callback()
Definition: rs_types.hpp:56
virtual void on_log(rs2_log_severity severity, rs2_log_message const &msg) noexcept=0
virtual ~rs2_notifications_callback()
Definition: rs_types.hpp:46
virtual ~rs2_playback_status_changed_callback()
Definition: rs_types.hpp:88
float min
Definition: rs_types.hpp:196
std::shared_ptr< rs2_devices_changed_callback > rs2_devices_changed_callback_sptr
Definition: rs_types.hpp:82
virtual ~rs2_calibration_change_callback()
Definition: rs_types.hpp:72
Definition: rs_types.hpp:84
Definition: rs_types.hpp:52
std::shared_ptr< rs2_calibration_change_callback > rs2_calibration_change_callback_sptr
Definition: rs_types.hpp:74
Definition: rs_context.hpp:11
Definition: rs_types.hpp:68
virtual void on_devices_changed(rs2_device_list *removed, rs2_device_list *added)=0
std::shared_ptr< rs2_log_callback > rs2_log_callback_sptr
Definition: rs_types.hpp:66
Definition: rs_types.h:34
float x
Definition: rs_types.h:107
int max_y
Definition: rs_types.hpp:207
Definition: rs_context.hpp:96
int max_x
Definition: rs_types.hpp:206
Definition: rs_types.hpp:60
virtual void release()=0
rs2_exception_type get_type() const
Definition: rs_types.hpp:140
virtual void release()=0
float max
Definition: rs_types.hpp:197
float step
Definition: rs_types.hpp:199
virtual void on_frame(rs2_frame *f, rs2_source *source)=0
Quaternion used to represent rotation.
Definition: rs_types.h:105
float y
Definition: rs_types.h:101
std::shared_ptr< rs2_playback_status_changed_callback > rs2_playback_status_changed_callback_sptr
Definition: rs_types.hpp:90
void(* log_callback_function_ptr)(rs2_log_severity severity, rs2_log_message const *msg)
Definition: rs_types.hpp:50
struct rs2_notification rs2_notification
Definition: rs_types.h:258
virtual void on_calibration_change(rs2_calibration_status) noexcept=0
Definition: rs_types.h:36
virtual ~rs2_update_progress_callback()
Definition: rs_types.hpp:96
error(rs2_error *err)
Definition: rs_types.hpp:115
Definition: rs_types.hpp:34
rs2_calibration_status
Definition: rs_device.h:414
Definition: rs_types.hpp:194
const char * rs2_get_error_message(const rs2_error *error)
rs2_playback_status
Definition: rs_record_playback.h:19
struct rs2_log_message rs2_log_message
Definition: rs_types.h:230
Definition: rs_types.h:299
virtual ~rs2_devices_changed_callback()
Definition: rs_types.hpp:80
rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error *error)
virtual void on_playback_status_changed(rs2_playback_status status)=0
virtual void on_value_changed(rs2_options_list *list)=0
float x
Definition: rs_types.h:101
std::shared_ptr< rs2_frame_processor_callback > rs2_frame_processor_callback_sptr
Definition: rs_types.hpp:40
std::shared_ptr< rs2_update_progress_callback > rs2_update_progress_callback_sptr
Definition: rs_types.hpp:98
static void handle(rs2_error *e)
Definition: rs_types.hpp:162
struct rs2_source rs2_source
Definition: rs_types.h:245
std::shared_ptr< rs2_notifications_callback > rs2_notifications_callback_sptr
Definition: rs_types.hpp:48
virtual ~rs2_options_changed_callback()
Definition: rs_types.hpp:104
const std::string & get_failed_function() const
Definition: rs_types.hpp:130
std::shared_ptr< rs2_frame_callback > rs2_frame_callback_sptr
Definition: rs_types.hpp:32
3D vector in Euclidean coordinate space
Definition: rs_types.h:99
float w
Definition: rs_types.h:107
Definition: rs_types.hpp:92
error(const std::string &message)
Definition: rs_types.hpp:123
virtual void on_notification(rs2_notification *n)=0
Definition: rs_device.hpp:1088
float def
Definition: rs_types.hpp:198
virtual ~rs2_frame_processor_callback()
Definition: rs_types.hpp:38
virtual ~rs2_frame_callback()
Definition: rs_types.hpp:30
bool operator==(rs2_calibration_config const &self, rs2_calibration_config const &other)
Definition: rs_types.hpp:214
RS2_ERROR_CLASS(recoverable_error, error)
Definition: rs_processing.hpp:641
Definition: rs_sensor.hpp:421
struct rs2_device_list rs2_device_list
Definition: rs_types.h:237
Definition: rs_types.hpp:76
struct rs2_error rs2_error
Definition: rs_types.h:229
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:123
struct rs2_options_list rs2_options_list
Definition: rs_types.h:255
Definition: rs_device.hpp:19
const char * rs2_get_failed_function(const rs2_error *error)
const char * rs2_get_failed_args(const rs2_error *error)
Definition: rs_types.h:37
float z
Definition: rs_types.h:107
int min_y
Definition: rs_types.hpp:205
struct rs2_frame rs2_frame
Definition: rs_types.h:232