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_result_t.
82 *
83 * @ingroup aux_pretty
84 */
85void
87
88/*!
89 * Pretty prints the @ref xrt_reference_space_type.
90 *
91 * @ingroup aux_pretty
92 */
93void
95
96
97/*
98 *
99 * Math struct printers.
100 *
101 */
102
103/*!
104 * Printers for math structs. None of these functions inserts trailing newlines
105 * because it's hard to remove a trailing newline but easy to add one if one
106 * should be needed. The small functions do not insert a starting newline while
107 * the other functions does. This is so that you can easily chain print
108 * functions to print a struct.
109 *
110 * @note xrt_matrix_* parameters assumed to be column major.
111 *
112 * @ingroup aux_pretty
113 * @{
114 */
115void
116u_pp_small_vec3(u_pp_delegate_t dg, const struct xrt_vec3 *vec);
117
118void
119u_pp_small_pose(u_pp_delegate_t dg, const struct xrt_pose *pose);
120
121void
122u_pp_small_matrix_3x3(u_pp_delegate_t dg, const struct xrt_matrix_3x3 *m);
123
124void
125u_pp_small_matrix_4x4(u_pp_delegate_t dg, const struct xrt_matrix_4x4 *m);
126
127void
128u_pp_small_matrix_4x4_f64(u_pp_delegate_t dg, const struct xrt_matrix_4x4_f64 *m);
129
130void
131u_pp_small_array_f64(struct u_pp_delegate dg, const double *arr, size_t n);
132
133void
134u_pp_small_array2d_f64(struct u_pp_delegate dg, const double *arr, size_t n, size_t m);
135
136void
137u_pp_vec3(u_pp_delegate_t dg, const struct xrt_vec3 *vec, const char *name, const char *indent);
138
139void
140u_pp_pose(u_pp_delegate_t dg, const struct xrt_pose *pose, const char *name, const char *indent);
141
142void
143u_pp_matrix_3x3(u_pp_delegate_t dg, const struct xrt_matrix_3x3 *m, const char *name, const char *indent);
144
145void
146u_pp_matrix_4x4(u_pp_delegate_t dg, const struct xrt_matrix_4x4 *m, const char *name, const char *indent);
147
148void
149u_pp_matrix_4x4_f64(u_pp_delegate_t dg, const struct xrt_matrix_4x4_f64 *m, const char *name, const char *indent);
150
151//! Pretty prints `double arr[n]`
152void
153u_pp_array_f64(u_pp_delegate_t dg, const double *arr, size_t n, const char *name, const char *indent);
154
155//! Pretty prints `double arr[n][m]`
156void
157u_pp_array2d_f64(u_pp_delegate_t dg, const double *arr, size_t n, size_t m, const char *name, const char *indent);
158
159/*!
160 * @}
161 */
162
163
164/*
165 *
166 * Sinks.
167 *
168 */
169
170/*!
171 * Stack only pretty printer sink, no need to free, must be inited before use.
172 *
173 * @ingroup aux_pretty
174 */
176{
177 //! How much of the buffer is used.
178 size_t used;
179
180 //! Storage for the sink.
181 char buffer[1024 * 8];
182};
183
185u_pp_sink_stack_only_init(struct u_pp_sink_stack_only *sink);
186
187
188#ifdef __cplusplus
189}
190#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:224
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:372
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:379
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:136
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:192
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition: xrt_defines.h:1298
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:599
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:176
size_t used
How much of the buffer is used.
Definition: u_pretty_print.h:178
A tightly packed 3x3 matrix of floats.
Definition: xrt_defines.h:533
A tightly packed 4x4 matrix of double.
Definition: xrt_defines.h:570
A tightly packed 4x4 matrix of floats.
Definition: xrt_defines.h:560
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Common defines and enums for XRT.