monado/src/xrt/state_trackers/oxr/oxr_two_call.h

60 lines
4 KiB
C
Raw Normal View History

2019-03-18 05:52:32 +00:00
// Copyright 2018-2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Two call helper functions.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @author Jakob Bornecrantz <jakob@collabora.com>
* @ingroup oxr_main
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
2021-01-14 14:13:48 +00:00
#define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, sval) \
do { \
if ((cnt_output) == NULL) { \
2021-01-14 14:13:48 +00:00
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
} \
*(cnt_output) = (uint32_t)(count); \
2021-01-14 14:13:48 +00:00
\
if ((cnt_input) == 0) { \
2021-01-14 14:13:48 +00:00
return sval; \
} \
if ((cnt_input) < (uint32_t)(count)) { \
2021-01-14 14:13:48 +00:00
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
} \
for (uint32_t i = 0; i < (count); i++) { \
2021-01-14 14:13:48 +00:00
(output)[i] = (data)[i]; \
} \
return (sval); \
2019-03-18 05:52:32 +00:00
} while (false)
//! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
2021-01-14 14:13:48 +00:00
#define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, output_structs, count, fill_fn, source_structs, sval) \
do { \
if (cnt_output == NULL) { \
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \
} \
*cnt_output = count; \
\
if (cnt_input == 0) { \
return sval; \
} \
if (cnt_input < count) { \
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \
} \
for (uint32_t i = 0; i < count; i++) { \
fill_fn(&output_structs[i], &source_structs[i]); \
} \
return sval; \
} while (false)
2019-03-18 05:52:32 +00:00
#ifdef __cplusplus
}
#endif