RealSense Cross Platform API
RealSense Cross-platform API
Loading...
Searching...
No Matches
rs.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_HPP
5#define LIBREALSENSE_RS2_HPP
6
7#include "rs.h"
8#include "hpp/rs_types.hpp"
9#include "hpp/rs_context.hpp"
10#include "hpp/rs_device.hpp"
11#include "hpp/rs_frame.hpp"
12#include "hpp/rs_processing.hpp"
14#include "hpp/rs_sensor.hpp"
16#include "hpp/rs_pipeline.hpp"
17#include "hpp/rs_eth_config.hpp"
18
19namespace rs2
20{
21 inline void log_to_console(rs2_log_severity min_severity)
22 {
23 rs2_error* e = nullptr;
24 rs2_log_to_console(min_severity, &e);
26 }
27
28 inline void log_to_file(rs2_log_severity min_severity, const char * file_path = nullptr)
29 {
30 rs2_error* e = nullptr;
31 rs2_log_to_file(min_severity, file_path, &e);
33 }
34
35 inline void reset_logger()
36 {
37 rs2_error* e = nullptr;
40 }
41
42 // Enable rolling log file when used with rs2_log_to_file:
43 // Upon reaching (max_size/2) bytes, the log will be renamed with an ".old" suffix and a new log created. Any
44 // previous .old file will be erased.
45 // Must have permissions to remove/rename files in log file directory.
46 //
47 // @param max_size max file size in megabytes
48 //
49 inline void enable_rolling_log_file( unsigned max_size )
50 {
51 rs2_error * e = nullptr;
52 rs2_enable_rolling_log_file( max_size, &e );
53 error::handle( e );
54 }
55
56 /*
57 Interface to the log message data we expose.
58 */
59 class log_message
60 {
61 // Only log_callback should be creating us!
62 friend class log_callback;
63
64 log_message( rs2_log_message const & msg ) : _msg( msg ) {}
65
66 public:
67 /* Returns the line-number in the file where the LOG() comment was issued */
68 size_t line_number() const
69 {
70 rs2_error* e = nullptr;
71 size_t ln = rs2_get_log_message_line_number( &_msg, &e );
72 error::handle( e );
73 return ln;
74 }
75 /* Returns the file in which the LOG() command was issued */
76 const char * filename() const
77 {
78 rs2_error* e = nullptr;
79 const char * path = rs2_get_log_message_filename( &_msg, &e );
80 error::handle( e );
81 return path;
82 }
83 /* Returns the raw message, as it was passed to LOG(), before any embelishments like level etc. */
84 const char* raw() const
85 {
86 rs2_error* e = nullptr;
87 const char* r = rs2_get_raw_log_message( &_msg, &e );
88 error::handle( e );
89 return r;
90 }
91 /*
92 Returns a complete log message, as defined by librealsense, with level, timestamp, etc.:
93 11/12 13:49:40,153 INFO [10604] (rs.cpp:2271) Framebuffer size changed to 1552 x 919
94 */
95 const char* full() const
96 {
97 rs2_error* e = nullptr;
98 const char* str = rs2_get_full_log_message( &_msg, &e );
99 error::handle( e );
100 return str;
101 }
102
103 private:
104 rs2_log_message const & _msg;
105 };
106
107 /*
108 Wrapper around any callback function that is given to log_to_callback.
109 */
111 {
112 public:
113 typedef std::function< void( rs2_log_severity, rs2::log_message const & ) > log_fn;
114
115 private:
116 log_fn on_log_function;
117
118 public:
120 : on_log_function( std::move( on_log ) )
121 {
122 }
123
124 void on_log( rs2_log_severity severity, rs2_log_message const & msg ) noexcept override
125 {
126 on_log_function( severity, log_message( msg ));
127 }
128
129 void release() override { delete this; }
130 };
131
132 /*
133 Your callback should look like this, for example:
134 void callback( rs2_log_severity severity, rs2::log_message const & msg ) noexcept
135 {
136 std::cout << msg.build() << std::endl;
137 }
138 and, when initializing rs2:
139 rs2::log_to_callback( callback );
140 or:
141 rs2::log_to_callback(
142 []( rs2_log_severity severity, rs2::log_message const & msg ) noexcept
143 {
144 std::cout << msg.build() << std::endl;
145 })
146 */
147 inline void log_to_callback( rs2_log_severity min_severity, log_callback::log_fn callback )
148 {
149 // We wrap the callback with an interface and pass it to librealsense, who will
150 // now manage its lifetime. Rather than deleting it, though, it will call its
151 // release() function, where (back in our context) it can be safely deleted:
152 rs2_error* e = nullptr;
153 rs2_log_to_callback_cpp( min_severity, new log_callback( std::move( callback )), &e );
154 error::handle( e );
155 }
156
157 inline void log(rs2_log_severity severity, const char* message)
158 {
159 rs2_error* e = nullptr;
160 rs2_log(severity, message, &e);
161 error::handle(e);
162 }
163}
164
165inline std::ostream & operator << (std::ostream & o, rs2_stream stream) { return o << rs2_stream_to_string(stream); }
166inline std::ostream & operator << (std::ostream & o, rs2_format format) { return o << rs2_format_to_string(format); }
167inline std::ostream & operator << (std::ostream & o, rs2_distortion distortion) { return o << rs2_distortion_to_string(distortion); }
168inline std::ostream & operator << (std::ostream & o, rs2_option option) { return o << rs2_option_to_string(option); } // This function is being deprecated. For existing options it will return option name, but for future API additions the user should call rs2_get_option_name instead.
169inline std::ostream & operator << (std::ostream & o, rs2_log_severity severity) { return o << rs2_log_severity_to_string(severity); }
170inline std::ostream & operator << (std::ostream & o, rs2::log_message const & msg ) { return o << msg.raw(); }
171inline std::ostream & operator << (std::ostream & o, rs2_camera_info camera_info) { return o << rs2_camera_info_to_string(camera_info); }
172inline std::ostream & operator << (std::ostream & o, rs2_frame_metadata_value metadata) { return o << rs2_frame_metadata_to_string(metadata); }
173inline std::ostream & operator << (std::ostream & o, rs2_timestamp_domain domain) { return o << rs2_timestamp_domain_to_string(domain); }
174inline std::ostream & operator << (std::ostream & o, rs2_notification_category notificaton) { return o << rs2_notification_category_to_string(notificaton); }
175inline std::ostream & operator << (std::ostream & o, rs2_sr300_visual_preset preset) { return o << rs2_sr300_visual_preset_to_string(preset); }
176inline std::ostream & operator << (std::ostream & o, rs2_exception_type exception_type) { return o << rs2_exception_type_to_string(exception_type); }
177inline std::ostream & operator << (std::ostream & o, rs2_playback_status status) { return o << rs2_playback_status_to_string(status); }
178inline std::ostream & operator << (std::ostream & o, rs2_l500_visual_preset preset) {return o << rs2_l500_visual_preset_to_string(preset);}
179inline std::ostream & operator << (std::ostream & o, rs2_sensor_mode mode) { return o << rs2_sensor_mode_to_string(mode); }
180inline std::ostream & operator << (std::ostream & o, rs2_calibration_type mode) { return o << rs2_calibration_type_to_string(mode); }
181inline std::ostream & operator << (std::ostream & o, rs2_calibration_status mode) { return o << rs2_calibration_status_to_string(mode); }
182inline std::ostream & operator << (std::ostream & o, rs2_eth_link_priority priority) { return o << rs2_eth_link_priority_to_string(priority); }
183
184#endif // LIBREALSENSE_RS2_HPP
static void handle(rs2_error *e)
Definition rs_types.hpp:167
Definition rs.hpp:111
std::function< void(rs2_log_severity, rs2::log_message const &) > log_fn
Definition rs.hpp:113
void release() override
Definition rs.hpp:129
void on_log(rs2_log_severity severity, rs2_log_message const &msg) noexcept override
Definition rs.hpp:124
log_callback(log_fn &&on_log)
Definition rs.hpp:119
Definition rs.hpp:60
size_t line_number() const
Definition rs.hpp:68
friend class log_callback
Definition rs.hpp:62
const char * filename() const
Definition rs.hpp:76
const char * raw() const
Definition rs.hpp:84
const char * full() const
Definition rs.hpp:95
Definition rs_processing_gl.hpp:13
void log(rs2_log_severity severity, const char *message)
Definition rs.hpp:157
void enable_rolling_log_file(unsigned max_size)
Definition rs.hpp:49
void reset_logger()
Definition rs.hpp:35
void log_to_console(rs2_log_severity min_severity)
Definition rs.hpp:21
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
Definition rs.hpp:28
void log_to_callback(rs2_log_severity min_severity, log_callback::log_fn callback)
Definition rs.hpp:147
Exposes librealsense functionality for C compilers.
void rs2_log_to_console(rs2_log_severity min_severity, rs2_error **error)
unsigned rs2_get_log_message_line_number(rs2_log_message const *msg, rs2_error **error)
void rs2_log_to_file(rs2_log_severity min_severity, const char *file_path, rs2_error **error)
const char * rs2_get_log_message_filename(rs2_log_message const *msg, rs2_error **error)
void rs2_enable_rolling_log_file(unsigned max_size, rs2_error **error)
const char * rs2_get_full_log_message(rs2_log_message const *msg, rs2_error **error)
void rs2_log_to_callback_cpp(rs2_log_severity min_severity, rs2_log_callback *callback, rs2_error **error)
void rs2_reset_logger(rs2_error **error)
void rs2_log(rs2_log_severity severity, const char *message, rs2_error **error)
const char * rs2_get_raw_log_message(rs2_log_message const *msg, rs2_error **error)
std::ostream & operator<<(std::ostream &o, rs2_stream stream)
Definition rs.hpp:165
rs2_calibration_type
Definition rs_device.h:409
const char * rs2_calibration_type_to_string(rs2_calibration_type)
rs2_calibration_status
Definition rs_device.h:421
const char * rs2_calibration_status_to_string(rs2_calibration_status)
rs2_eth_link_priority
Ethernet link priority options.
Definition rs_eth_config.h:21
const char * rs2_eth_link_priority_to_string(rs2_eth_link_priority priority)
const char * rs2_timestamp_domain_to_string(rs2_timestamp_domain info)
rs2_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition rs_frame.h:20
const char * rs2_frame_metadata_to_string(rs2_frame_metadata_value metadata)
rs2_frame_metadata_value
Per-Frame-Metadata is the set of read-only properties that might be exposed for each individual frame...
Definition rs_frame.h:30
const char * rs2_l500_visual_preset_to_string(rs2_l500_visual_preset preset)
rs2_sr300_visual_preset
For SR300 devices: provides optimized settings (presets) for specific types of usage.
Definition rs_option.h:205
rs2_l500_visual_preset
For L500 devices: provides optimized settings (presets) for specific types of usage.
Definition rs_option.h:237
const char * rs2_option_to_string(rs2_option option)
const char * rs2_sensor_mode_to_string(rs2_sensor_mode preset)
rs2_sensor_mode
DEPRECATED! - For setting the camera_mode option.
Definition rs_option.h:251
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls,...
Definition rs_option.h:27
const char * rs2_sr300_visual_preset_to_string(rs2_sr300_visual_preset preset)
const char * rs2_playback_status_to_string(rs2_playback_status status)
rs2_playback_status
Definition rs_record_playback.h:20
rs2_stream
Streams are different types of data provided by RealSense devices.
Definition rs_sensor.h:47
const char * rs2_stream_to_string(rs2_stream stream)
const char * rs2_camera_info_to_string(rs2_camera_info info)
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
Definition rs_sensor.h:22
const char * rs2_format_to_string(rs2_format format)
rs2_format
A stream's format identifies how binary data is encoded within a frame.
Definition rs_sensor.h:68
const char * rs2_exception_type_to_string(rs2_exception_type type)
rs2_log_severity
Severity of the librealsense logger.
Definition rs_types.h:123
const char * rs2_distortion_to_string(rs2_distortion distortion)
struct rs2_log_message rs2_log_message
Definition rs_types.h:277
rs2_notification_category
Category of the librealsense notification.
Definition rs_types.h:19
rs2_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition rs_types.h:48
const char * rs2_log_severity_to_string(rs2_log_severity info)
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
const char * rs2_notification_category_to_string(rs2_notification_category category)
Definition rs_types.hpp:66