Monado OpenXR Runtime
u_var.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Variable tracking code.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup aux_util
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_defines.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 struct xrt_frame_sink;
20 
21 /*!
22  * @ingroup aux_util
23  * @{
24  */
25 
27 {
28  void *data;
29  int *index_ptr;
30  int length;
31 };
32 
34 {
35  //! Values to be plotted.
36  struct u_var_f32_arr values;
37 
38  //! A reference line drawn on the plot.
40 
41  //! If false, reference_timing will be the bottom of the graph.
43 
44  //! How many units the graph expands by default.
45  float range;
46 
47  //! Rescale graph's value range when value exceeds range.
49 
50  //! A string describing the unit used, not freed.
51  const char *unit;
52 };
53 
54 /*!
55  * What kind of variable is this tracking.
56  */
58 {
59  U_VAR_KIND_BOOL,
60  U_VAR_KIND_RGB_U8,
61  U_VAR_KIND_RGB_F32,
62  U_VAR_KIND_U8,
63  U_VAR_KIND_I32,
64  U_VAR_KIND_F32,
65  U_VAR_KIND_F32_ARR,
66  U_VAR_KIND_TIMING,
67  U_VAR_KIND_VEC3_I32,
68  U_VAR_KIND_VEC3_F32,
69  U_VAR_KIND_POSE,
70  U_VAR_KIND_SINK,
71  U_VAR_KIND_RO_TEXT,
72  U_VAR_KIND_RO_I32,
73  U_VAR_KIND_RO_U32,
74  U_VAR_KIND_RO_F32,
75  U_VAR_KIND_RO_I64,
76  U_VAR_KIND_RO_U64,
77  U_VAR_KIND_RO_F64,
78  U_VAR_KIND_RO_VEC3_I32,
79  U_VAR_KIND_RO_VEC3_F32,
80  U_VAR_KIND_RO_QUAT_F32,
81  U_VAR_KIND_GUI_HEADER,
82 };
83 
84 /*!
85  * Callback for entering and leaving root nodes.
86  */
87 typedef void (*u_var_root_cb)(const char *, void *);
88 
89 /*!
90  * Callback on each variable a root node has.
91  */
92 typedef void (*u_var_elm_cb)(const char *, enum u_var_kind, void *, void *);
93 
94 /*!
95  * Add a named root object, the u_var subsystem is completely none-invasive
96  * to the object it's tracking. The root pointer is used as a entry into a
97  * hashmap of hidden objecrs. When not active all calls are stubs and have no
98  * side-effects.
99  *
100  * This is intended only for debugging and is turned off by default, as this all
101  * very very unsafe. It is just pointers straight into objects, completely
102  * ignores ownership or any safe practices.
103  *
104  * If it's stupid, but it works, it ain't stupid.
105  *
106  * ```c
107  * // On create
108  * u_var_add_root((void*)psmv, "PS Move Controller", true);
109  * u_var_add_rgb_u8((void*)psmv, &psmv->led_color, "LED");
110  * u_var_add_bool((void*)psmv, &psmv->print_spew, "Spew");
111  * u_var_add_bool((void*)psmv, &psmv->print_debug, "Debug");
112  *
113  * // On destroy, only need to destroy the root object.
114  * u_var_remove_root((void*)psmv);
115  * ```
116  *
117  * @ingroup aux_util
118  */
119 void
120 u_var_add_root(void *root, const char *c_name, bool number);
121 
122 /*!
123  * Remove the root node.
124  */
125 void
126 u_var_remove_root(void *root);
127 
128 /*!
129  * Visit all root nodes and their variables.
130  */
131 void
132 u_var_visit(u_var_root_cb enter_cb,
133  u_var_root_cb exit_cb,
134  u_var_elm_cb elem_cb,
135  void *priv);
136 
137 /*!
138  * This forces the variable tracking code to on, it is disabled by default.
139  */
140 void
141 u_var_force_on(void);
142 
143 #define U_VAR_ADD_FUNCS() \
144  ADD_FUNC(bool, bool, BOOL) \
145  ADD_FUNC(rgb_u8, struct xrt_colour_rgb_u8, RGB_U8) \
146  ADD_FUNC(rgb_f32, struct xrt_colour_rgb_f32, RGB_F32) \
147  ADD_FUNC(u8, uint8_t, U8) \
148  ADD_FUNC(i32, int32_t, I32) \
149  ADD_FUNC(f32, float, F32) \
150  ADD_FUNC(f32_arr, struct u_var_f32_arr, F32_ARR) \
151  ADD_FUNC(f32_timing, struct u_var_timing, TIMING) \
152  ADD_FUNC(vec3_i32, struct xrt_vec3_i32, VEC3_I32) \
153  ADD_FUNC(vec3_f32, struct xrt_vec3, VEC3_F32) \
154  ADD_FUNC(pose, struct xrt_pose, POSE) \
155  ADD_FUNC(sink, struct xrt_frame_sink *, SINK) \
156  ADD_FUNC(ro_text, const char, RO_TEXT) \
157  ADD_FUNC(ro_i32, int32_t, RO_I32) \
158  ADD_FUNC(ro_u32, uint32_t, RO_I32) \
159  ADD_FUNC(ro_f32, float, RO_F32) \
160  ADD_FUNC(ro_i64, int64_t, RO_I64) \
161  ADD_FUNC(ro_u64, uint64_t, RO_U64) \
162  ADD_FUNC(ro_f64, double, RO_F64) \
163  ADD_FUNC(ro_vec3_i32, struct xrt_vec3_i32, RO_VEC3_I32) \
164  ADD_FUNC(ro_vec3_f32, struct xrt_vec3, RO_VEC3_F32) \
165  ADD_FUNC(ro_quat_f32, struct xrt_quat, RO_QUAT_F32) \
166  ADD_FUNC(gui_header, bool, GUI_HEADER)
167 
168 #define ADD_FUNC(SUFFIX, TYPE, ENUM) \
169  void u_var_add_##SUFFIX(void *, TYPE *, const char *);
170 
171 U_VAR_ADD_FUNCS()
172 
173 #undef ADD_FUNC
174 
175 /*!
176  * @}
177  */
178 
179 
180 #ifdef __cplusplus
181 }
182 #endif
Definition: u_var.h:33
Definition: u_var.h:26
float reference_timing
A reference line drawn on the plot.
Definition: u_var.h:39
void u_var_visit(u_var_root_cb enter_cb, u_var_root_cb exit_cb, u_var_elm_cb elem_cb, void *priv)
Visit all root nodes and their variables.
Definition: u_var.cpp:152
A object that is sent frames.
Definition: xrt_frame.h:51
const char * unit
A string describing the unit used, not freed.
Definition: u_var.h:51
bool dynamic_rescale
Rescale graph&#39;s value range when value exceeds range.
Definition: u_var.h:48
bool center_reference_timing
If false, reference_timing will be the bottom of the graph.
Definition: u_var.h:42
Common defines and enums for XRT.
void u_var_add_root(void *root, const char *c_name, bool number)
Add a named root object, the u_var subsystem is completely none-invasive to the object it&#39;s tracking...
Definition: u_var.cpp:116
void(* u_var_root_cb)(const char *, void *)
Callback for entering and leaving root nodes.
Definition: u_var.h:87
void u_var_force_on(void)
This forces the variable tracking code to on, it is disabled by default.
Definition: u_var.cpp:109
u_var_kind
What kind of variable is this tracking.
Definition: u_var.h:57
float range
How many units the graph expands by default.
Definition: u_var.h:45
void(* u_var_elm_cb)(const char *, enum u_var_kind, void *, void *)
Callback on each variable a root node has.
Definition: u_var.h:92
void u_var_remove_root(void *root)
Remove the root node.
Definition: u_var.cpp:137