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