Monado OpenXR Runtime
oxr_two_call.h
Go to the documentation of this file.
1// Copyright 2018-2019, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Two call helper functions.
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup oxr_main
9 */
10
11#pragma once
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#define OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval) \
18 do { \
19 if ((cnt_output) == NULL) { \
20 return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
21 } \
22 *(cnt_output) = (uint32_t)(count); \
23 \
24 if ((cnt_input) == 0) { \
25 return sval; \
26 } \
27 if ((cnt_input) < (uint32_t)(count)) { \
28 return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
29 } \
30 } while (false)
31
32#define OXR_TWO_CALL_CHECK_GOTO(log, cnt_input, cnt_output, count, sval, goto_label) \
33 do { \
34 if ((cnt_output) == NULL) { \
35 sval = oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
36 goto goto_label; \
37 } \
38 *(cnt_output) = (uint32_t)(count); \
39 \
40 if ((cnt_input) == 0) { \
41 goto goto_label; \
42 } \
43 if ((cnt_input) < (uint32_t)(count)) { \
44 sval = oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
45 goto goto_label; \
46 } \
47 } while (false)
48
49#define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, sval) \
50 do { \
51 OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval); \
52 \
53 for (uint32_t i = 0; i < (count); i++) { \
54 (output)[i] = (data)[i]; \
55 } \
56 return (sval); \
57 } while (false)
58
59//! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
60#define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, output_structs, count, fill_fn, source_structs, sval) \
61 do { \
62 OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval); \
63 \
64 for (uint32_t i = 0; i < count; i++) { \
65 fill_fn(&output_structs[i], &source_structs[i]); \
66 } \
67 return sval; \
68 } while (false)
69
70//! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
71#define OXR_TWO_CALL_FILL_IN_GOTO(log, cnt_input, cnt_output, output_structs, count, fill_macro, source_structs, sval, \
72 goto_label) \
73 do { \
74 OXR_TWO_CALL_CHECK_GOTO(log, cnt_input, cnt_output, count, sval, goto_label); \
75 \
76 for (uint32_t i = 0; i < count; i++) { \
77 fill_macro(output_structs[i], source_structs[i]); \
78 } \
79 } while (false)
80
81#ifdef __cplusplus
82}
83#endif