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
14 extern "C" {
15 #endif
16 
17 
18 #define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, sval) \
19  do { \
20  if ((cnt_output) == NULL) { \
21  return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
22  } \
23  *(cnt_output) = (uint32_t)(count); \
24  \
25  if ((cnt_input) == 0) { \
26  return sval; \
27  } \
28  if ((cnt_input) < (uint32_t)(count)) { \
29  return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
30  } \
31  for (uint32_t i = 0; i < (count); i++) { \
32  (output)[i] = (data)[i]; \
33  } \
34  return (sval); \
35  } while (false)
36 
37 //! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
38 #define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, output_structs, count, fill_fn, source_structs, sval) \
39  do { \
40  if (cnt_output == NULL) { \
41  return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
42  } \
43  *cnt_output = count; \
44  \
45  if (cnt_input == 0) { \
46  return sval; \
47  } \
48  if (cnt_input < count) { \
49  return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
50  } \
51  for (uint32_t i = 0; i < count; i++) { \
52  fill_fn(&output_structs[i], &source_structs[i]); \
53  } \
54  return sval; \
55  } while (false)
56 
57 #ifdef __cplusplus
58 }
59 #endif