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 
26 {
27  virtual void on_frame(rs2_frame * f) = 0;
28  virtual void release() = 0;
29  virtual ~rs2_frame_callback() {}
30 };
31 
33 {
34  virtual void on_frame(rs2_frame * f, rs2_source * source) = 0;
35  virtual void release() = 0;
37 };
38 
40 {
41  virtual void on_notification(rs2_notification* n) = 0;
42  virtual void release() = 0;
44 };
45 
47 {
48  virtual void on_event(rs2_log_severity severity, const char * message) = 0;
49  virtual void release() = 0;
50  virtual ~rs2_log_callback() {}
51 };
52 
54 {
55  virtual void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) = 0;
56  virtual void release() = 0;
58 };
59 
61 {
62  virtual void on_playback_status_changed(rs2_playback_status status) = 0;
63  virtual void release() = 0;
65 };
66 
68 {
69  virtual void on_update_progress(const float update_progress) = 0;
70  virtual void release() = 0;
72 };
73 
74 namespace rs2
75 {
76  class error : public std::runtime_error
77  {
78  std::string function, args;
79  rs2_exception_type type;
80  public:
81  explicit error(rs2_error* err) : runtime_error(rs2_get_error_message(err))
82  {
83  function = (nullptr != rs2_get_failed_function(err)) ? rs2_get_failed_function(err) : std::string();
84  args = (nullptr != rs2_get_failed_args(err)) ? rs2_get_failed_args(err) : std::string();
86  rs2_free_error(err);
87  }
88 
89  explicit error(const std::string& message) : runtime_error(message.c_str())
90  {
91  function = "";
92  args = "";
94  }
95 
96  const std::string& get_failed_function() const
97  {
98  return function;
99  }
100 
101  const std::string& get_failed_args() const
102  {
103  return args;
104  }
105 
106  rs2_exception_type get_type() const { return type; }
107 
108  static void handle(rs2_error* e);
109  };
110 
111  #define RS2_ERROR_CLASS(name, base) \
112  class name : public base\
113  {\
114  public:\
115  explicit name(rs2_error* e) noexcept : base(e) {}\
116  }
117 
118  RS2_ERROR_CLASS(recoverable_error, error);
119  RS2_ERROR_CLASS(unrecoverable_error, error);
120  RS2_ERROR_CLASS(camera_disconnected_error, unrecoverable_error);
121  RS2_ERROR_CLASS(backend_error, unrecoverable_error);
122  RS2_ERROR_CLASS(device_in_recovery_mode_error, unrecoverable_error);
123  RS2_ERROR_CLASS(invalid_value_error, recoverable_error);
124  RS2_ERROR_CLASS(wrong_api_call_sequence_error, recoverable_error);
125  RS2_ERROR_CLASS(not_implemented_error, recoverable_error);
126  #undef RS2_ERROR_CLASS
127 
128  inline void error::handle(rs2_error* e)
129  {
130  if (e)
131  {
133  switch (h) {
135  throw camera_disconnected_error(e);
137  throw backend_error(e);
139  throw invalid_value_error(e);
141  throw wrong_api_call_sequence_error(e);
143  throw not_implemented_error(e);
145  throw device_in_recovery_mode_error(e);
146  default:
147  throw error(e);
148  }
149  }
150  }
151 
152  class context;
153  class device;
154  class device_list;
155  class syncer;
156  class device_base;
157  class roi_sensor;
158  class frame;
159 
161  {
162  float min;
163  float max;
164  float def;
165  float step;
166  };
167 
169  {
170  int min_x;
171  int min_y;
172  int max_x;
173  int max_y;
174  };
175 }
176 
177 inline std::ostream & operator << (std::ostream & o, rs2_vector v) { return o << v.x << ", " << v.y << ", " << v.z; }
178 inline std::ostream & operator << (std::ostream & o, rs2_quaternion q) { return o << q.x << ", " << q.y << ", " << q.z << ", " << q.w; }
179 
180 #endif // LIBREALSENSE_RS2_TYPES_HPP
rs2_playback_status
rs2_playback_status
Definition: rs_record_playback.h:19
rs2::device
Definition: rs_device.hpp:18
rs2_notifications_callback::release
virtual void release()=0
rs2_frame_callback::release
virtual void release()=0
rs2_playback_status_changed_callback
Definition: rs_types.hpp:60
rs2::option_range::step
float step
Definition: rs_types.hpp:165
rs2_vector
3D vector in Euclidean coordinate space
Definition: rs_types.h:97
rs2::error::error
error(const std::string &message)
Definition: rs_types.hpp:89
rs2::error::get_type
rs2_exception_type get_type() const
Definition: rs_types.hpp:106
rs2_quaternion
Quaternion used to represent rotation
Definition: rs_types.h:103
rs2::frame
Definition: rs_frame.hpp:336
rs2_update_progress_callback::on_update_progress
virtual void on_update_progress(const float update_progress)=0
rs2::error::get_failed_function
const std::string & get_failed_function() const
Definition: rs_types.hpp:96
rs2_get_error_message
const char * rs2_get_error_message(const rs2_error *error)
RS2_EXCEPTION_TYPE_NOT_IMPLEMENTED
Definition: rs_types.h:37
rs2::region_of_interest::min_x
int min_x
Definition: rs_types.hpp:170
rs2_devices_changed_callback
Definition: rs_types.hpp:53
rs2_log_callback::on_event
virtual void on_event(rs2_log_severity severity, const char *message)=0
rs2_devices_changed_callback::~rs2_devices_changed_callback
virtual ~rs2_devices_changed_callback()
Definition: rs_types.hpp:57
RS2_EXCEPTION_TYPE_CAMERA_DISCONNECTED
Definition: rs_types.h:33
rs2_frame
struct rs2_frame rs2_frame
Definition: rs_types.h:213
RS2_EXCEPTION_TYPE_BACKEND
Definition: rs_types.h:34
rs2::device_list
Definition: rs_device.hpp:565
rs2_source
struct rs2_source rs2_source
Definition: rs_types.h:226
rs2_log_callback::~rs2_log_callback
virtual ~rs2_log_callback()
Definition: rs_types.hpp:50
rs2::error::get_failed_args
const std::string & get_failed_args() const
Definition: rs_types.hpp:101
rs2_get_failed_args
const char * rs2_get_failed_args(const rs2_error *error)
rs2_notifications_callback
Definition: rs_types.hpp:39
RS2_EXCEPTION_TYPE_UNKNOWN
Definition: rs_types.h:32
rs2_log_callback::release
virtual void release()=0
RS2_EXCEPTION_TYPE_INVALID_VALUE
Definition: rs_types.h:35
rs2_log_severity
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:121
rs2::option_range
Definition: rs_types.hpp:160
rs2_playback_status_changed_callback::release
virtual void release()=0
rs2_vector::z
float z
Definition: rs_types.h:99
rs2::region_of_interest::max_y
int max_y
Definition: rs_types.hpp:173
rs2_update_progress_callback::~rs2_update_progress_callback
virtual ~rs2_update_progress_callback()
Definition: rs_types.hpp:71
rs2_devices_changed_callback::release
virtual void release()=0
rs2_playback_status_changed_callback::~rs2_playback_status_changed_callback
virtual ~rs2_playback_status_changed_callback()
Definition: rs_types.hpp:64
rs2_notifications_callback::on_notification
virtual void on_notification(rs2_notification *n)=0
rs2_notification
struct rs2_notification rs2_notification
Definition: rs_types.h:238
rs2_notifications_callback::~rs2_notifications_callback
virtual ~rs2_notifications_callback()
Definition: rs_types.hpp:43
rs2_frame_processor_callback::~rs2_frame_processor_callback
virtual ~rs2_frame_processor_callback()
Definition: rs_types.hpp:36
rs2_quaternion::y
float y
Definition: rs_types.h:105
rs2_frame_processor_callback
Definition: rs_types.hpp:32
rs2_log_callback
Definition: rs_types.hpp:46
rs2_frame_callback::~rs2_frame_callback
virtual ~rs2_frame_callback()
Definition: rs_types.hpp:29
rs2::option_range::min
float min
Definition: rs_types.hpp:162
rs2_frame_processor_callback::release
virtual void release()=0
rs2::syncer
Definition: rs_processing.hpp:597
operator<<
std::ostream & operator<<(std::ostream &o, rs2_vector v)
Definition: rs_types.hpp:177
rs2
Definition: rs_context.hpp:11
rs2_playback_status_changed_callback::on_playback_status_changed
virtual void on_playback_status_changed(rs2_playback_status status)=0
rs2::region_of_interest
Definition: rs_types.hpp:168
rs2_vector::y
float y
Definition: rs_types.h:99
rs2_vector::x
float x
Definition: rs_types.h:99
rs2_devices_changed_callback::on_devices_changed
virtual void on_devices_changed(rs2_device_list *removed, rs2_device_list *added)=0
rs2_frame_processor_callback::on_frame
virtual void on_frame(rs2_frame *f, rs2_source *source)=0
rs2::option_range::max
float max
Definition: rs_types.hpp:163
rs2::region_of_interest::min_y
int min_y
Definition: rs_types.hpp:171
rs2_quaternion::w
float w
Definition: rs_types.h:105
RS2_EXCEPTION_TYPE_WRONG_API_CALL_SEQUENCE
Definition: rs_types.h:36
rs2_update_progress_callback::release
virtual void release()=0
rs2_free_error
void rs2_free_error(rs2_error *error)
rs2::context
Definition: rs_context.hpp:96
rs2::error
Definition: rs_types.hpp:76
rs2_update_progress_callback
Definition: rs_types.hpp:67
rs2_quaternion::z
float z
Definition: rs_types.h:105
rs2::error::handle
static void handle(rs2_error *e)
Definition: rs_types.hpp:128
rs2::error::error
error(rs2_error *err)
Definition: rs_types.hpp:81
rs2_frame_callback::on_frame
virtual void on_frame(rs2_frame *f)=0
RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE
Definition: rs_types.h:38
rs2::option_range::def
float def
Definition: rs_types.hpp:164
rs2_quaternion::x
float x
Definition: rs_types.h:105
rs2::RS2_ERROR_CLASS
RS2_ERROR_CLASS(recoverable_error, error)
rs2_device_list
struct rs2_device_list rs2_device_list
Definition: rs_types.h:218
rs2::region_of_interest::max_x
int max_x
Definition: rs_types.hpp:172
rs2_error
struct rs2_error rs2_error
Definition: rs_types.h:211
rs2::roi_sensor
Definition: rs_sensor.hpp:348
rs2_get_librealsense_exception_type
rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error *error)
rs2_get_failed_function
const char * rs2_get_failed_function(const rs2_error *error)
rs2_exception_type
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition: rs_types.h:30
rs2_frame_callback
Definition: rs_types.hpp:25