Monado OpenXR Runtime
u_pretty_print.h
Go to the documentation of this file.
1// Copyright 2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Pretty printing various Monado things.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_pretty
8 */
9#pragma once
10
11#include "xrt/xrt_defines.h"
12
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18
19/*!
20 * @defgroup aux_pretty Pretty printing functions and helpers
21 * @ingroup aux_util
22 *
23 * This is common functionality used directly and shared by additional pretty
24 * printing functions implemented in multiple modules, such as @ref oxr_api.
25 *
26 * Some functions have a `_indented` suffix added to them, this means that what
27 * they print starts indented, but also they start with a newline. This is so
28 * they can easily be chained together to form a debug message printing out
29 * various information. Most of the final logging functions in Monado inserts a
30 * newline at the end of the message and we don't want two to be inserted.
31 */
32
33/*!
34 * Function prototype for receiving pretty printed strings.
35 *
36 * @note Do not keep a reference to the pointer as it's often allocated on the
37 * stack for speed.
38 *
39 * @ingroup aux_pretty
40 */
41typedef void (*u_pp_delegate_func_t)(void *ptr, const char *str, size_t length);
42
43/*!
44 * Helper struct to hold a function pointer and data pointer.
45 *
46 * @ingroup aux_pretty
47 */
49{
50 //! Userdata pointer, placed first to match D/Volt delegates.
51 void *ptr;
52
53 //! String receiving function.
55};
56
57/*!
58 * Helper typedef for delegate struct, less typing.
59 *
60 * @ingroup aux_pretty
61 */
63
64/*!
65 * Formats a string and sends to the delegate.
66 *
67 * @ingroup aux_pretty
68 */
69void
70u_pp(struct u_pp_delegate dg, const char *fmt, ...) XRT_PRINTF_FORMAT(2, 3);
71
72/*!
73 * Pretty prints the @ref xrt_input_name.
74 *
75 * @ingroup aux_pretty
76 */
77void
79
80/*!
81 * Pretty prints the @ref xrt_output_name.
82 *
83 * @ingroup aux_pretty
84 */
85void
87
88/*!
89 * Pretty prints the @ref xrt_result_t.
90 *
91 * @ingroup aux_pretty
92 */
93void
95
96/*!
97 * Pretty prints the @ref xrt_reference_space_type.
98 *
99 * @ingroup aux_pretty
100 */
101void
103
104
105/*
106 *
107 * Math struct printers.
108 *
109 */
110
111/*!
112 * Printers for math structs. None of these functions inserts trailing newlines
113 * because it's hard to remove a trailing newline but easy to add one if one
114 * should be needed. The small functions do not insert a starting newline while
115 * the other functions does. This is so that you can easily chain print
116 * functions to print a struct.
117 *
118 * @note xrt_matrix_* parameters assumed to be column major.
119 *
120 * @ingroup aux_pretty
121 * @{
122 */
123void
124u_pp_small_vec3(u_pp_delegate_t dg, const struct xrt_vec3 *vec);
125
126void
127u_pp_small_pose(u_pp_delegate_t dg, const struct xrt_pose *pose);
128
129void
130u_pp_small_matrix_3x3(u_pp_delegate_t dg, const struct xrt_matrix_3x3 *m);
131
132void
133u_pp_small_matrix_4x4(u_pp_delegate_t dg, const struct xrt_matrix_4x4 *m);
134
135void
136u_pp_small_matrix_4x4_f64(u_pp_delegate_t dg, const struct xrt_matrix_4x4_f64 *m);
137
138void
139u_pp_small_array_f64(struct u_pp_delegate dg, const double *arr, size_t n);
140
141void
142u_pp_small_array2d_f64(struct u_pp_delegate dg, const double *arr, size_t n, size_t m);
143
144void
145u_pp_vec3(u_pp_delegate_t dg, const struct xrt_vec3 *vec, const char *name, const char *indent);
146
147void
148u_pp_pose(u_pp_delegate_t dg, const struct xrt_pose *pose, const char *name, const char *indent);
149
150void
151u_pp_matrix_3x3(u_pp_delegate_t dg, const struct xrt_matrix_3x3 *m, const char *name, const char *indent);
152
153void
154u_pp_matrix_4x4(u_pp_delegate_t dg, const struct xrt_matrix_4x4 *m, const char *name, const char *indent);
155
156void
157u_pp_matrix_4x4_f64(u_pp_delegate_t dg, const struct xrt_matrix_4x4_f64 *m, const char *name, const char *indent);
158
159//! Pretty prints `double arr[n]`
160void
161u_pp_array_f64(u_pp_delegate_t dg, const double *arr, size_t n, const char *name, const char *indent);
162
163//! Pretty prints `double arr[n][m]`
164void
165u_pp_array2d_f64(u_pp_delegate_t dg, const double *arr, size_t n, size_t m, const char *name, const char *indent);
166
167/*!
168 * @}
169 */
170
171
172/*
173 *
174 * Sinks.
175 *
176 */
177
178/*!
179 * Stack only pretty printer sink, no need to free, must be inited before use.
180 *
181 * @ingroup aux_pretty
182 */
184{
185 //! How much of the buffer is used.
186 size_t used;
187
188 //! Storage for the sink.
189 char buffer[1024 * 8];
190};
191
193u_pp_sink_stack_only_init(struct u_pp_sink_stack_only *sink);
194
195
196#ifdef __cplusplus
197}
198#endif
void u_pp_small_vec3(u_pp_delegate_t dg, const struct xrt_vec3 *vec)
Printers for math structs.
Definition: u_pretty_print.c:275
void u_pp_array_f64(u_pp_delegate_t dg, const double *arr, size_t n, const char *name, const char *indent)
Pretty prints double arr[n]
Definition: u_pretty_print.c:423
void u_pp_array2d_f64(u_pp_delegate_t dg, const double *arr, size_t n, size_t m, const char *name, const char *indent)
Pretty prints double arr[n][m]
Definition: u_pretty_print.c:430
void u_pp_xrt_output_name(struct u_pp_delegate dg, enum xrt_output_name name)
Pretty prints the xrt_output_name.
Definition: u_pretty_print.c:136
void(* u_pp_delegate_func_t)(void *ptr, const char *str, size_t length)
Function prototype for receiving pretty printed strings.
Definition: u_pretty_print.h:41
void u_pp(struct u_pp_delegate dg, const char *fmt,...) XRT_PRINTF_FORMAT(2
Formats a string and sends to the delegate.
void u_pp_xrt_result(struct u_pp_delegate dg, xrt_result_t xret)
Pretty prints the xrt_result_t.
Definition: u_pretty_print.c:185
void void u_pp_xrt_input_name(struct u_pp_delegate dg, enum xrt_input_name name)
Pretty prints the xrt_input_name.
Definition: u_pretty_print.c:112
void u_pp_xrt_reference_space_type(struct u_pp_delegate dg, enum xrt_reference_space_type type)
Pretty prints the xrt_reference_space_type.
Definition: u_pretty_print.c:243
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1306
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_reference_space_type
Type of a OpenXR mapped reference space, maps to the semantic spaces on the xrt_space_overseer struct...
Definition: xrt_defines.h:601
xrt_output_name
Name of a output with a baked in type.
Definition: xrt_defines.h:1919
Helper struct to hold a function pointer and data pointer.
Definition: u_pretty_print.h:49
u_pp_delegate_func_t func
String receiving function.
Definition: u_pretty_print.h:54
void * ptr
Userdata pointer, placed first to match D/Volt delegates.
Definition: u_pretty_print.h:51
Stack only pretty printer sink, no need to free, must be inited before use.
Definition: u_pretty_print.h:184
size_t used
How much of the buffer is used.
Definition: u_pretty_print.h:186
A tightly packed 3x3 matrix of floats.
Definition: xrt_defines.h:535
A tightly packed 4x4 matrix of double.
Definition: xrt_defines.h:572
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:562
A pose composed of a position and orientation.
Definition: xrt_defines.h:467
A 3 element vector with single floats.
Definition: xrt_defines.h:273
Common defines and enums for XRT.