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