···11-// Copyright 2020-2024, Collabora, Ltd.
11+// Copyright 2020-2025, Collabora, Ltd.
22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
···1212#pragma once
13131414#include "xrt/xrt_compiler.h"
1515+#include "xrt/xrt_results.h"
15161617#include "util/u_pretty_print.h"
1718···176177 } \
177178 } while (false)
178179180180+/*!
181181+ * This define will error if `XRET` is not `XRT_SUCCESS`, printing out that the
182182+ * @p FUNC_STR string has failed, then returns @p XRET.
183183+ *
184184+ * @param COND_LEVEL Log level used for @p cond_level, in logging helpers.
185185+ * @param XRET The @p xrt_result_t to check.
186186+ * @param FUNC_STR String literal with the function name, used for logging.
187187+ */
188188+#define U_LOG_CHK_AND_RET(COND_LEVEL, XRET, FUNC_STR) \
189189+ do { \
190190+ xrt_result_t _ret = XRET; \
191191+ if (_ret != XRT_SUCCESS) { \
192192+ u_log_print_result(COND_LEVEL, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
193193+ return _ret; \
194194+ } \
195195+ } while (false)
196196+197197+/*!
198198+ * This define will error if `XRET` is not `XRT_SUCCESS`, printing out that the
199199+ * @p FUNC_STR string has failed, then gotos @p GOTO.
200200+ *
201201+ * @param COND_LEVEL Log level used for @p cond_level, in logging helpers.
202202+ * @param XRET The @p xrt_result_t to check.
203203+ * @param FUNC_STR String literal with the function name, used for logging.
204204+ * @param GOTO Goto label to jump to on error.
205205+ */
206206+#define U_LOG_CHK_WITH_GOTO(COND_LEVEL, XRET, FUNC_STR, GOTO) \
207207+ do { \
208208+ xrt_result_t _ret = XRET; \
209209+ if (_ret != XRT_SUCCESS) { \
210210+ u_log_print_result(COND_LEVEL, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
211211+ goto GOTO; \
212212+ } \
213213+ } while (false)
214214+215215+/*!
216216+ * This define will error if `XRET` is not `XRT_SUCCESS`, printing out that the
217217+ * @p FUNC_STR string has failed, then returns @p RET.
218218+ *
219219+ * @param COND_LEVEL Log level used for @p cond_level, in logging helpers.
220220+ * @param XRET The @p xrt_result_t to check.
221221+ * @param FUNC_STR String literal with the function name, used for logging.
222222+ * @param RET The value that is returned on error.
223223+ */
224224+#define U_LOG_CHK_WITH_RET(COND_LEVEL, XRET, FUNC_STR, RET) \
225225+ do { \
226226+ xrt_result_t _ret = XRET; \
227227+ if (_ret != XRT_SUCCESS) { \
228228+ u_log_print_result(COND_LEVEL, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
229229+ return RET; \
230230+ } \
231231+ } while (false)
232232+233233+/*!
234234+ * This define will error if `XRET` is not `XRT_SUCCESS`, printing out that the
235235+ * @p FUNC_STR string has failed, it only prints and does nothing else.
236236+ *
237237+ * @param COND_LEVEL Log level used for @p cond_level, in logging helpers.
238238+ * @param XRET The @p xrt_result_t to check.
239239+ * @param FUNC_STR String literal with the function name, used for logging.
240240+ */
241241+#define U_LOG_CHK_ONLY_PRINT(COND_LEVEL, XRET, FUNC_STR) \
242242+ do { \
243243+ xrt_result_t _ret = XRET; \
244244+ if (_ret != XRT_SUCCESS) { \
245245+ u_log_print_result(COND_LEVEL, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
246246+ } \
247247+ } while (false)
248248+249249+/*!
250250+ * This define will error if `XRET` is not `XRT_SUCCESS`, printing out that the
251251+ * @p FUNC_STR string has failed, then it will always return the value.
252252+ *
253253+ * @param COND_LEVEL Log level used for @p cond_level, in logging helpers.
254254+ * @param XRET The @p xrt_result_t to check and always return.
255255+ * @param FUNC_STR String literal with the function name, used for logging.
256256+ */
257257+#define U_LOG_CHK_ALWAYS_RET(COND_LEVEL, XRET, FUNC_STR) \
258258+ do { \
259259+ xrt_result_t _ret = XRET; \
260260+ if (_ret != XRT_SUCCESS) { \
261261+ u_log_print_result(COND_LEVEL, __FILE__, __LINE__, __func__, _ret, FUNC_STR); \
262262+ } \
263263+ return _ret; \
264264+ } while (false)
179265180266/*!
181267 * Returns the global logging level, subsystems own logging level take precedence.
···271357 */
272358void
273359u_log_set_sink(u_log_sink_func_t func, void *data);
360360+361361+/*!
362362+ * Helper to print the results of called functions that return xret results, if
363363+ * the result is @p XRT_SUCCESS will log with info, otherwise error. Will also
364364+ * check if logging should be done with @p cond_level.
365365+ *
366366+ * @param cond_level What the current logging level is.
367367+ * @param file Callee site (__FILE__).
368368+ * @param line Callee site (__LINE__).
369369+ * @param calling_fn Callee site (__func__).
370370+ * @param xret Result from the called function.
371371+ * @param called_fn Which function that this return is from.
372372+ */
373373+void
374374+u_log_print_result(enum u_logging_level cond_level,
375375+ const char *file,
376376+ int line,
377377+ const char *calling_fn,
378378+ xrt_result_t xret,
379379+ const char *called_fn);
274380275381/*!
276382 * @}