Time-of-Flight Library(ToF) 4.0.1
 
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) : CrashReport(tof_crash_report_new(serial, description, TOF_ERROR_HANDLER{})) {}
33
34 /** Get the description
35 * @return Description
36 */
37 const char* get_description() const {
38 return tof_crash_report_get_description(this->ptr_, TOF_ERROR_HANDLER{});
39 }
40
41 /** Set the description
42 * @param description Description
43 */
44 void set_description(StringView description) {
45 return tof_crash_report_set_description(this->ptr_, description, TOF_ERROR_HANDLER{});
46 }
47
48 /** Get the complete report
49 * @return String of the entire report
50 */
51 const char* get_report() const {
52 return tof_crash_report_get_report(this->ptr_, TOF_ERROR_HANDLER{});
53 }
54
55 /** Save report to disk
56 * @param file_name File to save the report to
57 */
58 void save(StringView file_name) const {
59 return tof_crash_report_save(this->ptr_, file_name, TOF_ERROR_HANDLER{});
60 }
61
62};
63
64/** Get the version of the tof library
65 * @return Library version
66 */
67inline const char* get_version() {
68 return tof_get_version(TOF_ERROR_HANDLER{});
69}
70
71/** Log info/warning/error occuring in the tof library to stdout
72 */
73inline void log_to_console() {
74 return tof_log_to_console(TOF_ERROR_HANDLER{});
75}
76
77/** Log info/warning/error occuring in the tof library
78 * @param file_location Location where to store the log file
79 */
80inline void log_to_file(StringView file_location) {
81 return tof_log_to_file(file_location, TOF_ERROR_HANDLER{});
82}
83
84/** Log info/warning/error occuring in the tof library to function
85 * @param callback Function that is called with log data
86 */
87inline void log_callback(log_callback_fn &callback) {
88 return tof_log_callback(log_callback_cb_handler, &callback, TOF_ERROR_HANDLER{});
89}
90
91/** Log info/warning/error occuring in the tof library to function
92 * @param callback Function that is called with log data
93 * @param callback_user_data User data that will be passed back when the function pointer is called
94 */
95inline void log_callback(tof_log_callback_t callback, void* callback_user_data) {
96 return tof_log_callback(callback, callback_user_data, TOF_ERROR_HANDLER{});
97}
98
99/** Log info/warning/error occuring in the tof library to function
100 * @param callback_separated Function that is called with separated log data
101 */
102inline void log_callback_separated(log_callback_separated_fn &callback_separated) {
103 return tof_log_callback_separated(log_callback_separated_cb_handler, &callback_separated, TOF_ERROR_HANDLER{});
104}
105
106/** Log info/warning/error occuring in the tof library to function
107 * @param callback_separated Function that is called with separated log data
108 * @param callback_separated_user_data User data that will be passed back when the function pointer is called
109 */
110inline void log_callback_separated(tof_log_callback_separated_t callback_separated, void* callback_separated_user_data) {
111 return tof_log_callback_separated(callback_separated, callback_separated_user_data, TOF_ERROR_HANDLER{});
112}
113
114/** Stop logging
115 */
116inline void log_drop() {
117 return tof_log_drop(TOF_ERROR_HANDLER{});
118}
119
120} // tof
121} // chronoptics
122
123#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:51
void save(StringView file_name) const
Save report to disk.
Definition: log.hpp:58
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:44
const char * get_description() const
Get the description.
Definition: log.hpp:37