RealSense Cross Platform API
RealSense Cross-platform API
Loading...
Searching...
No Matches
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 RealSense, Inc. 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"
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;
31};
32typedef 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};
45typedef 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};
53typedef std::shared_ptr<rs2_notifications_callback> rs2_notifications_callback_sptr;
54
55typedef void ( *log_callback_function_ptr )(rs2_log_severity severity, rs2_log_message const * msg );
56
63typedef 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};
71typedef 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};
79typedef 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};
87typedef std::shared_ptr<rs2_devices_changed_callback> rs2_devices_changed_callback_sptr;
88
95typedef 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};
103typedef 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};
111typedef std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr;
112
113namespace rs2
114{
115 class error : public std::runtime_error
116 {
117 std::string function, args;
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
216inline std::ostream & operator << (std::ostream & o, rs2_vector v) { return o << v.x << ", " << v.y << ", " << v.z; }
217inline 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_context.hpp:97
Definition rs_device.hpp:1058
Definition rs_device.hpp:20
Definition rs_types.hpp:116
rs2_exception_type get_type() const
Definition rs_types.hpp:145
error(rs2_error *err)
Definition rs_types.hpp:120
const std::string & get_failed_function() const
Definition rs_types.hpp:135
error(const std::string &message)
Definition rs_types.hpp:128
static void handle(rs2_error *e)
Definition rs_types.hpp:167
const std::string & get_failed_args() const
Definition rs_types.hpp:140
Definition rs_frame.hpp:355
Definition rs_sensor.hpp:458
Definition rs_processing.hpp:673
Definition rs_processing_gl.hpp:13
Exposes librealsense functionality for C compilers.
Exposes RealSense context functionality for C compilers.
Exposes RealSense device functionality for C compilers.
rs2_calibration_status
Definition rs_device.h:421
Exposes RealSense frame functionality for C compilers.
Exposes RealSense processing-block functionality for C compilers.
Exposes RealSense processing-block functionality for C compilers.
Exposes record and playback functionality for C compilers.
rs2_playback_status
Definition rs_record_playback.h:20
Exposes RealSense sensor functionality for C compilers.
rs2_exception_type rs2_get_librealsense_exception_type(const rs2_error *error)
rs2_log_severity
Severity of the librealsense logger.
Definition rs_types.h:123
struct rs2_log_message rs2_log_message
Definition rs_types.h:277
void rs2_free_error(rs2_error *error)
const char * rs2_get_failed_args(const rs2_error *error)
struct rs2_source rs2_source
Definition rs_types.h:292
const char * rs2_get_error_message(const rs2_error *error)
struct rs2_notification rs2_notification
Definition rs_types.h:308
const char * rs2_get_failed_function(const rs2_error *error)
struct rs2_device_list rs2_device_list
Definition rs_types.h:284
struct rs2_error rs2_error
Definition rs_types.h:276
rs2_exception_type
Exception types are the different categories of errors that RealSense API might return.
Definition rs_types.h:33
@ RS2_EXCEPTION_TYPE_NOT_IMPLEMENTED
Definition rs_types.h:39
@ RS2_EXCEPTION_TYPE_CAMERA_DISCONNECTED
Definition rs_types.h:35
@ RS2_EXCEPTION_TYPE_BACKEND
Definition rs_types.h:36
@ RS2_EXCEPTION_TYPE_INVALID_VALUE
Definition rs_types.h:37
@ RS2_EXCEPTION_TYPE_UNKNOWN
Definition rs_types.h:34
@ RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE
Definition rs_types.h:40
@ RS2_EXCEPTION_TYPE_WRONG_API_CALL_SEQUENCE
Definition rs_types.h:38
struct rs2_options_list rs2_options_list
Definition rs_types.h:304
struct rs2_frame rs2_frame
Definition rs_types.h:279
std::shared_ptr< rs2_frame_callback > rs2_frame_callback_sptr
Definition rs_types.hpp:32
std::ostream & operator<<(std::ostream &o, rs2_vector v)
Definition rs_types.hpp:216
#define RS2_ERROR_CLASS(name, base)
Definition rs_types.hpp:150
std::shared_ptr< rs2_devices_changed_callback > rs2_devices_changed_callback_sptr
Definition rs_types.hpp:87
std::shared_ptr< rs2_log_callback > rs2_log_callback_sptr
Definition rs_types.hpp:71
std::shared_ptr< rs2_notifications_callback > rs2_notifications_callback_sptr
Definition rs_types.hpp:53
std::shared_ptr< rs2_frame_processor_callback > rs2_frame_processor_callback_sptr
Definition rs_types.hpp:45
std::shared_ptr< rs2_options_changed_callback > rs2_options_changed_callback_sptr
Definition rs_types.hpp:111
std::shared_ptr< rs2_playback_status_changed_callback > rs2_playback_status_changed_callback_sptr
Definition rs_types.hpp:95
std::shared_ptr< rs2_calibration_change_callback > rs2_calibration_change_callback_sptr
Definition rs_types.hpp:79
void(* log_callback_function_ptr)(rs2_log_severity severity, rs2_log_message const *msg)
Definition rs_types.hpp:55
std::shared_ptr< rs2_update_progress_callback > rs2_update_progress_callback_sptr
Definition rs_types.hpp:103
std::shared_ptr< rs2_software_device_destruction_callback > rs2_software_device_destruction_callback_sptr
Definition rs_types.hpp:63
Definition rs_types.hpp:200
float def
Definition rs_types.hpp:203
float step
Definition rs_types.hpp:204
float max
Definition rs_types.hpp:202
float min
Definition rs_types.hpp:201
Definition rs_types.hpp:208
int min_x
Definition rs_types.hpp:209
int max_y
Definition rs_types.hpp:212
int max_x
Definition rs_types.hpp:211
int min_y
Definition rs_types.hpp:210
Definition rs_types.hpp:74
virtual void on_calibration_change(rs2_calibration_status) noexcept=0
virtual ~rs2_calibration_change_callback()
Definition rs_types.hpp:77
Definition rs_types.hpp:82
virtual void on_devices_changed(rs2_device_list *removed, rs2_device_list *added)=0
virtual ~rs2_devices_changed_callback()
Definition rs_types.hpp:85
Definition rs_types.hpp:27
virtual ~rs2_frame_callback()
Definition rs_types.hpp:30
virtual void on_frame(rs2_frame *f)=0
virtual void release()=0
Definition rs_types.hpp:40
virtual ~rs2_frame_processor_callback()
Definition rs_types.hpp:43
virtual void on_frame(rs2_frame *f, rs2_source *source)=0
Definition rs_types.hpp:66
virtual void release()=0
virtual ~rs2_log_callback()
Definition rs_types.hpp:69
virtual void on_log(rs2_log_severity severity, rs2_log_message const &msg) noexcept=0
Definition rs_types.hpp:48
virtual void on_notification(rs2_notification *n)=0
virtual ~rs2_notifications_callback()
Definition rs_types.hpp:51
virtual void release()=0
Definition rs_types.hpp:106
virtual void on_value_changed(rs2_options_list *list)=0
virtual ~rs2_options_changed_callback()
Definition rs_types.hpp:109
Definition rs_types.hpp:90
virtual void on_playback_status_changed(rs2_playback_status status)=0
virtual ~rs2_playback_status_changed_callback()
Definition rs_types.hpp:93
Quaternion used to represent rotation.
Definition rs_types.h:106
float y
Definition rs_types.h:107
float z
Definition rs_types.h:107
float w
Definition rs_types.h:107
float x
Definition rs_types.h:107
virtual ~rs2_software_device_destruction_callback()
Definition rs_types.hpp:61
Definition rs_types.hpp:35
std::vector< rs2_stream > list
Definition rs_types.hpp:36
Definition rs_types.hpp:98
virtual ~rs2_update_progress_callback()
Definition rs_types.hpp:101
virtual void on_update_progress(const float update_progress)=0
3D vector in Euclidean coordinate space
Definition rs_types.h:100
float x
Definition rs_types.h:101
float y
Definition rs_types.h:101
float z
Definition rs_types.h:101