Time-of-Flight Library(ToF) 3.3.0
log.hpp
1#ifndef _CHRONOPTICS_TOF_LOG_HPP_
2#define _CHRONOPTICS_TOF_LOG_HPP_
3
4#include <chronoptics/tof/log.h>
5
6#include <chronoptics/tof/base.hpp>
7
8namespace chronoptics {
9namespace tof {
10
11// Function pointer type for log callback
12using log_callback_fn = std::function<void(const char*)>;
13constexpr auto log_callback_cb_handler = &detail::callback_handler<void, const char*>;
14
15// Function pointer type for log callback separated
16using log_callback_separated_fn = std::function<void(int16_t, const char*, const char*)>;
17constexpr auto log_callback_separated_cb_handler = &detail::callback_handler<void, int16_t, const char*, const char*>;
18
19/** Class containing log information about the crash that occurred
20*/
21class CrashReport : public detail::Base<tof_crash_report, tof_crash_report_delete> {
22 public:
23 /** Construct from pointer */
24 CrashReport(tof_crash_report_t ptr = nullptr) {
25 this->ptr_ = ptr;
26 }
27
28 /** Generate crash report on a camera
29 * @param serial Camera to generate the crash report on
30 * @param description Description of what happened
31 */
32 CrashReport(StringView serial, StringView description) {
33 this->ptr_ = tof_crash_report_new(serial, description, TOF_ERROR_HANDLER{});
34 }
35
36 /** Get the description
37 * @return Description
38 */
39 const char* get_description() const {
40 return tof_crash_report_get_description(this->ptr_, TOF_ERROR_HANDLER{});
41 }
42
43 /** Set the description
44 * @param description Description
45 */
46 void set_description(StringView description) {
47 return tof_crash_report_set_description(this->ptr_, description, TOF_ERROR_HANDLER{});
48 }
49
50 /** Get the complete report
51 * @return String of the entire report
52 */
53 const char* get_report() const {
54 return tof_crash_report_get_report(this->ptr_, TOF_ERROR_HANDLER{});
55 }
56
57 /** Save report to disk
58 * @param file_name File to save the report to
59 */
60 void save(StringView file_name) const {
61 return tof_crash_report_save(this->ptr_, file_name, TOF_ERROR_HANDLER{});
62 }
63
64};
65
66/** Get the version of the tof library
67 * @return Library version
68 */
69inline const char* get_version() {
70 return tof_get_version(TOF_ERROR_HANDLER{});
71}
72
73/** Log info/warning/error occuring in the tof library to stdout
74 */
75inline void log_to_console() {
76 return tof_log_to_console(TOF_ERROR_HANDLER{});
77}
78
79/** Log info/warning/error occuring in the tof library
80 * @param file_location Location where to store the log file
81 */
82inline void log_to_file(StringView file_location) {
83 return tof_log_to_file(file_location, TOF_ERROR_HANDLER{});
84}
85
86/** Log info/warning/error occuring in the tof library to function
87 * @param callback Function that is called with log data
88 */
89inline void log_callback(log_callback_fn &callback) {
90 return tof_log_callback(log_callback_cb_handler, &callback, TOF_ERROR_HANDLER{});
91}
92
93/** Log info/warning/error occuring in the tof library to function
94 * @param callback Function that is called with log data
95 * @param callback_user_data User data that will be passed back when the function pointer is called
96 */
97inline void log_callback(tof_log_callback_t callback, void* callback_user_data) {
98 return tof_log_callback(callback, callback_user_data, TOF_ERROR_HANDLER{});
99}
100
101/** Log info/warning/error occuring in the tof library to function
102 * @param callback_separated Function that is called with separated log data
103 */
104inline void log_callback_separated(log_callback_separated_fn &callback_separated) {
105 return tof_log_callback_separated(log_callback_separated_cb_handler, &callback_separated, TOF_ERROR_HANDLER{});
106}
107
108/** Log info/warning/error occuring in the tof library to function
109 * @param callback_separated Function that is called with separated log data
110 * @param callback_separated_user_data User data that will be passed back when the function pointer is called
111 */
112inline void log_callback_separated(tof_log_callback_separated_t callback_separated, void* callback_separated_user_data) {
113 return tof_log_callback_separated(callback_separated, callback_separated_user_data, TOF_ERROR_HANDLER{});
114}
115
116/** Stop logging
117 */
118inline void log_drop() {
119 return tof_log_drop(TOF_ERROR_HANDLER{});
120}
121
122} // tof
123} // chronoptics
124
125#endif
Class containing log information about the crash that occurred.
Definition: log.hpp:21
const char * get_report() const
Get the complete report.
Definition: log.hpp:53
void save(StringView file_name) const
Save report to disk.
Definition: log.hpp:60
CrashReport(StringView serial, StringView description)
Generate crash report on a camera.
Definition: log.hpp:32
CrashReport(tof_crash_report_t ptr=nullptr)
Construct from pointer.
Definition: log.hpp:24
void set_description(StringView description)
Set the description.
Definition: log.hpp:46
const char * get_description() const
Get the description.
Definition: log.hpp:39