Monado OpenXR Runtime
u_debug.h
Go to the documentation of this file.
1 // Copyright 2019-2023, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Small debug helpers.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup aux_util
8  *
9  * Debug get option helpers heavily inspired from mesa ones.
10  */
11 
12 #pragma once
13 
14 #include "xrt/xrt_compiler.h"
15 
16 #include "util/u_logging.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 
23 /*
24  *
25  * Definitions.
26  *
27  */
28 
29 #define DEBUG_CHAR_STORAGE_SIZE (1024)
30 
31 enum debug_tristate_option
32 {
33  DEBUG_TRISTATE_OFF,
34  DEBUG_TRISTATE_AUTO,
35  DEBUG_TRISTATE_ON
36 };
37 
38 
39 /*
40  *
41  * Conversion functions.
42  *
43  */
44 
45 bool
46 debug_string_to_bool(const char *string);
47 
48 enum debug_tristate_option
49 debug_string_to_tristate(const char *string);
50 
51 long
52 debug_string_to_num(const char *string, long _default);
53 
54 float
55 debug_string_to_float(const char *string, float _default);
56 
57 enum u_logging_level
58 debug_string_to_log_level(const char *string, enum u_logging_level _default);
59 
60 
61 /*
62  *
63  * Get functions.
64  *
65  */
66 
67 const char *
68 debug_get_option(char *chars, size_t char_count, const char *name, const char *_default);
69 
70 bool
71 debug_get_bool_option(const char *name, bool _default);
72 
73 enum debug_tristate_option
74 debug_get_tristate_option(const char *name);
75 
76 long
77 debug_string_to_num(const char *string, long _default);
78 
79 long
80 debug_get_num_option(const char *name, long _default);
81 
82 float
83 debug_get_float_option(const char *name, float _default);
84 
85 enum u_logging_level
86 debug_get_log_option(const char *name, enum u_logging_level _default);
87 
88 
89 /*
90  *
91  * Get once helpers.
92  *
93  */
94 
95 #define DEBUG_GET_ONCE_OPTION(suffix, name, _default) \
96  static const char *debug_get_option_##suffix(void) \
97  { \
98  static char storage[DEBUG_CHAR_STORAGE_SIZE]; \
99  static bool gotten = false; \
100  static const char *stored; \
101  if (!gotten) { \
102  gotten = true; \
103  stored = debug_get_option(storage, ARRAY_SIZE(storage), name, _default); \
104  } \
105  return stored; \
106  }
107 
108 #define DEBUG_GET_ONCE_TRISTATE_OPTION(suffix, name) \
109  static enum debug_tristate_option debug_get_tristate_option_##suffix(void) \
110  { \
111  static bool gotten = false; \
112  static enum debug_tristate_option stored; \
113  if (!gotten) { \
114  gotten = true; \
115  stored = debug_get_tristate_option(name); \
116  } \
117  return stored; \
118  }
119 
120 #define DEBUG_GET_ONCE_BOOL_OPTION(suffix, name, _default) \
121  static bool debug_get_bool_option_##suffix(void) \
122  { \
123  static bool gotten = false; \
124  static bool stored; \
125  if (!gotten) { \
126  gotten = true; \
127  stored = debug_get_bool_option(name, _default); \
128  } \
129  return stored; \
130  }
131 
132 #define DEBUG_GET_ONCE_NUM_OPTION(suffix, name, _default) \
133  static long debug_get_num_option_##suffix(void) \
134  { \
135  static long gotten = false; \
136  static long stored; \
137  if (!gotten) { \
138  gotten = true; \
139  stored = debug_get_num_option(name, _default); \
140  } \
141  return stored; \
142  }
143 
144 #define DEBUG_GET_ONCE_FLOAT_OPTION(suffix, name, _default) \
145  static float debug_get_float_option_##suffix(void) \
146  { \
147  static long gotten = false; \
148  static float stored; \
149  if (!gotten) { \
150  gotten = true; \
151  stored = debug_get_float_option(name, _default); \
152  } \
153  return stored; \
154  }
155 
156 #define DEBUG_GET_ONCE_LOG_OPTION(suffix, name, _default) \
157  static enum u_logging_level debug_get_log_option_##suffix(void) \
158  { \
159  static long gotten = false; \
160  static enum u_logging_level stored; \
161  if (!gotten) { \
162  gotten = true; \
163  stored = debug_get_log_option(name, _default); \
164  } \
165  return stored; \
166  }
167 
168 #ifdef __cplusplus
169 }
170 #endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
Basic logging functionality.
Header holding common defines.