Intel® RealSense™ Cross Platform API  2.13.0
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 
67 namespace rs2
68 {
69  class error : public std::runtime_error
70  {
71  std::string function, args;
72  rs2_exception_type type;
73  public:
74  explicit error(rs2_error* err) : runtime_error(rs2_get_error_message(err))
75  {
76  function = (nullptr != rs2_get_failed_function(err)) ? rs2_get_failed_function(err) : std::string();
77  args = (nullptr != rs2_get_failed_args(err)) ? rs2_get_failed_args(err) : std::string();
79  rs2_free_error(err);
80  }
81 
82  explicit error(const std::string& message) : runtime_error(message.c_str())
83  {
84  function = "";
85  args = "";
87  }
88 
89  const std::string& get_failed_function() const
90  {
91  return function;
92  }
93 
94  const std::string& get_failed_args() const
95  {
96  return args;
97  }
98 
99  rs2_exception_type get_type() const { return type; }
100 
101  static void handle(rs2_error* e);
102  };
103 
104  #define RS2_ERROR_CLASS(name, base) \
105  class name : public base\
106  {\
107  public:\
108  explicit name(rs2_error* e) noexcept : base(e) {}\
109  }
110 
111  RS2_ERROR_CLASS(recoverable_error, error);
112  RS2_ERROR_CLASS(unrecoverable_error, error);
113  RS2_ERROR_CLASS(camera_disconnected_error, unrecoverable_error);
114  RS2_ERROR_CLASS(backend_error, unrecoverable_error);
115  RS2_ERROR_CLASS(device_in_recovery_mode_error, unrecoverable_error);
116  RS2_ERROR_CLASS(invalid_value_error, recoverable_error);
117  RS2_ERROR_CLASS(wrong_api_call_sequence_error, recoverable_error);
118  RS2_ERROR_CLASS(not_implemented_error, recoverable_error);
119  #undef RS2_ERROR_CLASS
120 
121  inline void error::handle(rs2_error* e)
122  {
123  if (e)
124  {
126  switch (h) {
128  throw camera_disconnected_error(e);
130  throw backend_error(e);
132  throw invalid_value_error(e);
134  throw wrong_api_call_sequence_error(e);
136  throw not_implemented_error(e);
138  throw device_in_recovery_mode_error(e);
139  default:
140  throw error(e);
141  }
142  }
143  }
144 
145  class context;
146  class device;
147  class device_list;
148  class syncer;
149  class device_base;
150  class roi_sensor;
151  class frame;
152 
154  {
155  float min;
156  float max;
157  float def;
158  float step;
159  };
160 
162  {
163  int min_x;
164  int min_y;
165  int max_x;
166  int max_y;
167  };
168 }
169 
170 #endif // LIBREALSENSE_RS2_TYPES_HPP
Definition: rs_types.hpp:69
Definition: rs_types.hpp:25
const std::string & get_failed_args() const
Definition: rs_types.hpp:94
Definition: rs_frame.hpp:202
Definition: rs_types.hpp:161
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition: rs_types.h:29
void rs2_free_error(rs2_error *error)
virtual ~rs2_log_callback()
Definition: rs_types.hpp:50
virtual void on_frame(rs2_frame *f)=0
Definition: rs_types.hpp:39
int min_x
Definition: rs_types.hpp:163
Definition: rs_types.h:36
virtual void release()=0
virtual ~rs2_notifications_callback()
Definition: rs_types.hpp:43
virtual ~rs2_playback_status_changed_callback()
Definition: rs_types.hpp:64
float min
Definition: rs_types.hpp:155
Definition: rs_types.hpp:60
Definition: rs_context.hpp:11
virtual void on_devices_changed(rs2_device_list *removed, rs2_device_list *added)=0
Definition: rs_types.h:31
int max_y
Definition: rs_types.hpp:166
Definition: rs_context.hpp:78
int max_x
Definition: rs_types.hpp:165
Definition: rs_types.hpp:46
virtual void release()=0
rs2_exception_type get_type() const
Definition: rs_types.hpp:99
virtual void release()=0
float max
Definition: rs_types.hpp:156
float step
Definition: rs_types.hpp:158
virtual void on_frame(rs2_frame *f, rs2_source *source)=0
struct rs2_notification rs2_notification
Definition: rs_types.h:173
Definition: rs_types.h:33
error(rs2_error *err)
Definition: rs_types.hpp:74
Definition: rs_types.hpp:32
Definition: rs_types.hpp:153
virtual void on_event(rs2_log_severity severity, const char *message)=0
const char * rs2_get_error_message(const rs2_error *error)
rs2_playback_status
Definition: rs_record_playback.h:19
virtual ~rs2_devices_changed_callback()
Definition: rs_types.hpp:57
rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error *error)
virtual void on_playback_status_changed(rs2_playback_status status)=0
static void handle(rs2_error *e)
Definition: rs_types.hpp:121
struct rs2_source rs2_source
Definition: rs_types.h:163
const std::string & get_failed_function() const
Definition: rs_types.hpp:89
error(const std::string &message)
Definition: rs_types.hpp:82
virtual void on_notification(rs2_notification *n)=0
Definition: rs_device.hpp:184
float def
Definition: rs_types.hpp:157
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:273
Definition: rs_sensor.hpp:439
struct rs2_device_list rs2_device_list
Definition: rs_types.h:156
Definition: rs_types.hpp:53
struct rs2_error rs2_error
Definition: rs_types.h:149
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:82
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:34
int min_y
Definition: rs_types.hpp:164
struct rs2_frame rs2_frame
Definition: rs_types.h:151