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