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 <ostream>
22 #include <atomic>
23 #include <condition_variable>
24 #include <iterator>
25 #include <sstream>
26 
28 {
29  virtual void on_frame(rs2_frame * f) = 0;
30  virtual void release() = 0;
31  virtual ~rs2_frame_callback() {}
32 };
33 
35 {
36  virtual void on_frame(rs2_frame * f, rs2_source * source) = 0;
37  virtual void release() = 0;
39 };
40 
42 {
43  virtual void on_notification(rs2_notification* n) = 0;
44  virtual void release() = 0;
46 };
47 
49 {
50  virtual void on_event(rs2_log_severity severity, const char * message) = 0;
51  virtual void release() = 0;
52  virtual ~rs2_log_callback() {}
53 };
54 
56 {
57  virtual void on_devices_changed(rs2_device_list* removed, rs2_device_list* added) = 0;
58  virtual void release() = 0;
60 };
61 
63 {
64  virtual void on_playback_status_changed(rs2_playback_status status) = 0;
65  virtual void release() = 0;
67 };
68 
69 namespace rs2
70 {
71  class error : public std::runtime_error
72  {
73  std::string function, args;
74  rs2_exception_type type;
75  public:
76  explicit error(rs2_error* err) : runtime_error(rs2_get_error_message(err))
77  {
78  function = (nullptr != rs2_get_failed_function(err)) ? rs2_get_failed_function(err) : std::string();
79  args = (nullptr != rs2_get_failed_args(err)) ? rs2_get_failed_args(err) : std::string();
81  rs2_free_error(err);
82  }
83 
84  explicit error(const std::string& message) : runtime_error(message.c_str())
85  {
86  function = "";
87  args = "";
89  }
90 
91  const std::string& get_failed_function() const
92  {
93  return function;
94  }
95 
96  const std::string& get_failed_args() const
97  {
98  return args;
99  }
100 
101  rs2_exception_type get_type() const { return type; }
102 
103  static void handle(rs2_error* e);
104  };
105 
106  #define RS2_ERROR_CLASS(name, base) \
107  class name : public base\
108  {\
109  public:\
110  explicit name(rs2_error* e) noexcept : base(e) {}\
111  }
112 
113  RS2_ERROR_CLASS(recoverable_error, error);
114  RS2_ERROR_CLASS(unrecoverable_error, error);
115  RS2_ERROR_CLASS(camera_disconnected_error, unrecoverable_error);
116  RS2_ERROR_CLASS(backend_error, unrecoverable_error);
117  RS2_ERROR_CLASS(device_in_recovery_mode_error, unrecoverable_error);
118  RS2_ERROR_CLASS(invalid_value_error, recoverable_error);
119  RS2_ERROR_CLASS(wrong_api_call_sequence_error, recoverable_error);
120  RS2_ERROR_CLASS(not_implemented_error, recoverable_error);
121  #undef RS2_ERROR_CLASS
122 
123  inline void error::handle(rs2_error* e)
124  {
125  if (e)
126  {
128  switch (h) {
130  throw camera_disconnected_error(e);
132  throw backend_error(e);
134  throw invalid_value_error(e);
136  throw wrong_api_call_sequence_error(e);
138  throw not_implemented_error(e);
140  throw device_in_recovery_mode_error(e);
141  default:
142  throw error(e);
143  }
144  }
145  }
146 
147  class context;
148  class device;
149  class device_list;
150  class syncer;
151  class device_base;
152  class roi_sensor;
153  class frame;
154 
156  {
157  float min;
158  float max;
159  float def;
160  float step;
161  };
162 
164  {
165  int min_x;
166  int min_y;
167  int max_x;
168  int max_y;
169  };
170 }
171 
172 #endif // LIBREALSENSE_RS2_TYPES_HPP
Definition: rs_types.hpp:71
Definition: rs_types.hpp:27
#define RS2_ERROR_CLASS(name, base)
Definition: rs_types.hpp:106
const std::string & get_failed_args() const
Definition: rs_types.hpp:96
Definition: rs_frame.hpp:202
Definition: rs_types.hpp:163
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:52
virtual void on_frame(rs2_frame *f)=0
Definition: rs_types.hpp:41
int min_x
Definition: rs_types.hpp:165
Definition: rs_types.h:36
virtual ~rs2_notifications_callback()
Definition: rs_types.hpp:45
virtual ~rs2_playback_status_changed_callback()
Definition: rs_types.hpp:66
float min
Definition: rs_types.hpp:157
Definition: api.h:18
Definition: rs_types.hpp:62
Definition: rs_context.hpp:11
Definition: rs_types.h:31
int max_y
Definition: rs_types.hpp:168
Definition: rs_context.hpp:78
int max_x
Definition: rs_types.hpp:167
Definition: rs_types.hpp:48
status
Defines return codes that SDK interfaces use. Negative values indicate errors, a zero value indicates...
Definition: serialization.h:305
rs2_exception_type get_type() const
Definition: rs_types.hpp:101
virtual void release()=0
float max
Definition: rs_types.hpp:158
float step
Definition: rs_types.hpp:160
Definition: processing.h:12
Definition: rs_types.h:33
Definition: context.h:29
error(rs2_error *err)
Definition: rs_types.hpp:76
Definition: rs_types.hpp:34
Definition: rs_types.hpp:155
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:59
rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error *error)
const std::string & get_failed_function() const
Definition: rs_types.hpp:91
error(const std::string &message)
Definition: rs_types.hpp:84
Definition: rs_device.hpp:184
float def
Definition: rs_types.hpp:159
virtual ~rs2_frame_processor_callback()
Definition: rs_types.hpp:38
virtual ~rs2_frame_callback()
Definition: rs_types.hpp:31
Definition: rs_processing.hpp:273
Definition: rs_sensor.hpp:439
Definition: api.h:26
Definition: rs_types.hpp:55
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:166
struct rs2_frame rs2_frame
Definition: rs_types.h:151