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  std::vector< rs2_stream > list;
37 };
38 
40 {
41  virtual void on_frame(rs2_frame * f, rs2_source * source) = 0;
42  virtual void release() = 0;
44 };
45 typedef std::shared_ptr<rs2_frame_processor_callback> rs2_frame_processor_callback_sptr;
46 
48 {
49  virtual void on_notification(rs2_notification* n) = 0;
50  virtual void release() = 0;
52 };
53 typedef std::shared_ptr<rs2_notifications_callback> rs2_notifications_callback_sptr;
54 
55 typedef void ( *log_callback_function_ptr )(rs2_log_severity severity, rs2_log_message const * msg );
56 
58 {
59  virtual void on_destruction() = 0;
60  virtual void release() = 0;
62 };
63 typedef std::shared_ptr<rs2_software_device_destruction_callback> rs2_software_device_destruction_callback_sptr;
64 
66 {
67  virtual void on_log( rs2_log_severity severity, rs2_log_message const & msg ) noexcept = 0;
68  virtual void release() = 0;
69  virtual ~rs2_log_callback() {}
70 };
71 typedef std::shared_ptr< rs2_log_callback > rs2_log_callback_sptr;
72 
74 {
75  virtual void on_calibration_change( rs2_calibration_status ) noexcept = 0;
76  virtual void release() = 0;
78 };
79 typedef std::shared_ptr<rs2_calibration_change_callback> rs2_calibration_change_callback_sptr;
80 
82 {
83  virtual void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) = 0;
84  virtual void release() = 0;
86 };
87 typedef std::shared_ptr<rs2_devices_changed_callback> rs2_devices_changed_callback_sptr;
88 
90 {
91  virtual void on_playback_status_changed(rs2_playback_status status) = 0;
92  virtual void release() = 0;
94 };
95 typedef std::shared_ptr<rs2_playback_status_changed_callback> rs2_playback_status_changed_callback_sptr;
96 
98 {
99  virtual void on_update_progress(const float update_progress) = 0;
100  virtual void release() = 0;
102 };
103 typedef std::shared_ptr<rs2_update_progress_callback> rs2_update_progress_callback_sptr;
104 
106 {
107  virtual void on_value_changed( rs2_options_list * list ) = 0;
108  virtual void release() = 0;
110 };
111 typedef std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr;
112 
113 namespace rs2
114 {
115  class error : public std::runtime_error
116  {
117  std::string function, args;
118  rs2_exception_type type;
119  public:
120  explicit error(rs2_error* err) : runtime_error(rs2_get_error_message(err))
121  {
122  function = (nullptr != rs2_get_failed_function(err)) ? rs2_get_failed_function(err) : std::string();
123  args = (nullptr != rs2_get_failed_args(err)) ? rs2_get_failed_args(err) : std::string();
125  rs2_free_error(err);
126  }
127 
128  explicit error(const std::string& message) : runtime_error(message.c_str())
129  {
130  function = "";
131  args = "";
133  }
134 
135  const std::string& get_failed_function() const
136  {
137  return function;
138  }
139 
140  const std::string& get_failed_args() const
141  {
142  return args;
143  }
144 
145  rs2_exception_type get_type() const { return type; }
146 
147  static void handle(rs2_error* e);
148  };
149 
150  #define RS2_ERROR_CLASS(name, base) \
151  class name : public base\
152  {\
153  public:\
154  explicit name(rs2_error* e) noexcept : base(e) {}\
155  }
156 
157  RS2_ERROR_CLASS(recoverable_error, error);
158  RS2_ERROR_CLASS(unrecoverable_error, error);
159  RS2_ERROR_CLASS(camera_disconnected_error, unrecoverable_error);
160  RS2_ERROR_CLASS(backend_error, unrecoverable_error);
161  RS2_ERROR_CLASS(device_in_recovery_mode_error, unrecoverable_error);
162  RS2_ERROR_CLASS(invalid_value_error, recoverable_error);
163  RS2_ERROR_CLASS(wrong_api_call_sequence_error, recoverable_error);
164  RS2_ERROR_CLASS(not_implemented_error, recoverable_error);
165  #undef RS2_ERROR_CLASS
166 
167  inline void error::handle(rs2_error* e)
168  {
169  if (e)
170  {
172  switch (h) {
174  throw camera_disconnected_error(e);
176  throw backend_error(e);
178  throw invalid_value_error(e);
180  throw wrong_api_call_sequence_error(e);
182  throw not_implemented_error(e);
184  throw device_in_recovery_mode_error(e);
185  default:
186  throw error(e);
187  }
188  }
189  }
190 
191  class context;
192  class device;
193  class device_list;
194  class syncer;
195  class device_base;
196  class roi_sensor;
197  class frame;
198 
200  {
201  float min;
202  float max;
203  float def;
204  float step;
205  };
206 
208  {
209  int min_x;
210  int min_y;
211  int max_x;
212  int max_y;
213  };
214 }
215 
216 inline std::ostream & operator << (std::ostream & o, rs2_vector v) { return o << v.x << ", " << v.y << ", " << v.z; }
217 inline std::ostream & operator << (std::ostream & o, rs2_quaternion q) { return o << q.x << ", " << q.y << ", " << q.z << ", " << q.w; }
218 
219 #endif // LIBREALSENSE_RS2_TYPES_HPP
Definition: rs_types.hpp:115
Definition: rs_types.hpp:26
Definition: rs_types.hpp:105
const std::string & get_failed_args() const
Definition: rs_types.hpp:140
Definition: rs_frame.hpp:354
Definition: rs_types.hpp:207
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:216
virtual ~rs2_log_callback()
Definition: rs_types.hpp:69
std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr
Definition: rs_types.hpp:111
virtual void on_frame(rs2_frame *f)=0
float z
Definition: rs_types.h:101
Definition: rs_types.hpp:47
int min_x
Definition: rs_types.hpp:209
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:63
virtual ~rs2_software_device_destruction_callback()
Definition: rs_types.hpp:61
virtual void on_log(rs2_log_severity severity, rs2_log_message const &msg) noexcept=0
virtual ~rs2_notifications_callback()
Definition: rs_types.hpp:51
virtual ~rs2_playback_status_changed_callback()
Definition: rs_types.hpp:93
float min
Definition: rs_types.hpp:201
std::shared_ptr< rs2_devices_changed_callback > rs2_devices_changed_callback_sptr
Definition: rs_types.hpp:87
virtual ~rs2_calibration_change_callback()
Definition: rs_types.hpp:77
Definition: rs_types.hpp:89
Definition: rs_types.hpp:57
std::shared_ptr< rs2_calibration_change_callback > rs2_calibration_change_callback_sptr
Definition: rs_types.hpp:79
Definition: rs_context.hpp:11
Definition: rs_types.hpp:73
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:71
Definition: rs_types.h:34
float x
Definition: rs_types.h:107
int max_y
Definition: rs_types.hpp:212
Definition: rs_context.hpp:96
int max_x
Definition: rs_types.hpp:211
Definition: rs_types.hpp:65
virtual void release()=0
rs2_exception_type get_type() const
Definition: rs_types.hpp:145
virtual void release()=0
float max
Definition: rs_types.hpp:202
float step
Definition: rs_types.hpp:204
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:95
void(* log_callback_function_ptr)(rs2_log_severity severity, rs2_log_message const *msg)
Definition: rs_types.hpp:55
struct rs2_notification rs2_notification
Definition: rs_types.h:261
virtual void on_calibration_change(rs2_calibration_status) noexcept=0
Definition: rs_types.h:36
virtual ~rs2_update_progress_callback()
Definition: rs_types.hpp:101
error(rs2_error *err)
Definition: rs_types.hpp:120
Definition: rs_types.hpp:39
rs2_calibration_status
Definition: rs_device.h:414
Definition: rs_types.hpp:199
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:232
Definition: rs_types.hpp:34
std::vector< rs2_stream > list
Definition: rs_types.hpp:36
virtual ~rs2_devices_changed_callback()
Definition: rs_types.hpp:85
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:45
std::shared_ptr< rs2_update_progress_callback > rs2_update_progress_callback_sptr
Definition: rs_types.hpp:103
static void handle(rs2_error *e)
Definition: rs_types.hpp:167
struct rs2_source rs2_source
Definition: rs_types.h:247
std::shared_ptr< rs2_notifications_callback > rs2_notifications_callback_sptr
Definition: rs_types.hpp:53
virtual ~rs2_options_changed_callback()
Definition: rs_types.hpp:109
const std::string & get_failed_function() const
Definition: rs_types.hpp:135
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:97
error(const std::string &message)
Definition: rs_types.hpp:128
virtual void on_notification(rs2_notification *n)=0
Definition: rs_device.hpp:1046
float def
Definition: rs_types.hpp:203
virtual ~rs2_frame_processor_callback()
Definition: rs_types.hpp:43
virtual ~rs2_frame_callback()
Definition: rs_types.hpp:30
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:239
Definition: rs_types.hpp:81
struct rs2_error rs2_error
Definition: rs_types.h:231
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:123
struct rs2_options_list rs2_options_list
Definition: rs_types.h:257
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:210
struct rs2_frame rs2_frame
Definition: rs_types.h:234