Monado OpenXR Runtime
oxr_handle.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Contains handle-related functions and defines only required in a few
6  * locations.
7  * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8  * @ingroup oxr_main
9  */
10 
11 #pragma once
12 
13 #include "oxr_objects.h"
14 
15 #include <stdlib.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /*
22  *
23  * oxr_handle_base.c
24  *
25  */
26 
27 /*!
28  * Initialize a handle holder, and if a parent is specified, update its child
29  * list to include this handle.
30  *
31  * @protected @memberof oxr_handle_base
32  */
33 XrResult
35  struct oxr_handle_base *hb,
36  uint64_t debug,
37  oxr_handle_destroyer destroy,
38  struct oxr_handle_base *parent);
39 
40 /*!
41  * Allocate some memory for use as a handle, and initialize it as a handle.
42  *
43  * Mainly for internal use - use OXR_ALLOCATE_HANDLE instead which wraps this.
44  *
45  * @relates oxr_handle_base
46  */
47 XrResult
49  size_t size,
50  uint64_t debug,
51  oxr_handle_destroyer destroy,
52  struct oxr_handle_base *parent,
53  void **out);
54 /*!
55  * Allocates memory for a handle and evaluates to an XrResult.
56  *
57  * @param LOG pointer to struct oxr_logger
58  * @param OUT the pointer to handle struct type you already created.
59  * @param DEBUG Magic per-type debugging constant
60  * @param DESTROY Handle destructor function
61  * @param PARENT a parent handle, if any
62  *
63  * Use when you want to do something other than immediately returning in case of
64  * failure. If returning immediately is OK, see OXR_ALLOCATE_HANDLE_OR_RETURN().
65  *
66  * @relates oxr_handle_base
67  */
68 #define OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT) \
69  oxr_handle_allocate_and_init(LOG, sizeof(*OUT), DEBUG, DESTROY, PARENT, (void **)&OUT)
70 
71 /*!
72  * Allocate memory for a handle, returning in case of failure.
73  *
74  * @param LOG pointer to struct oxr_logger
75  * @param OUT the pointer to handle struct type you already created.
76  * @param DEBUG Magic per-type debugging constant
77  * @param DESTROY Handle destructor function
78  * @param PARENT a parent handle, if any
79  *
80  * Will return an XrResult from the current function if something fails.
81  * If that's not OK, see OXR_ALLOCATE_HANDLE().
82  *
83  * @relates oxr_handle_base
84  */
85 #define OXR_ALLOCATE_HANDLE_OR_RETURN(LOG, OUT, DEBUG, DESTROY, PARENT) \
86  do { \
87  XrResult allocResult = OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT); \
88  if (allocResult != XR_SUCCESS) { \
89  return allocResult; \
90  } \
91  } while (0)
92 
93 #ifdef __cplusplus
94 }
95 #endif
XrResult(* oxr_handle_destroyer)(struct oxr_logger *log, struct oxr_handle_base *hb)
Function pointer type for a handle destruction function.
Definition: oxr_objects.h:136
The objects representing OpenXR handles, and prototypes for internal functions used in the state trac...
Used to hold diverse child handles and ensure orderly destruction.
Definition: oxr_objects.h:1306
XrResult oxr_handle_init(struct oxr_logger *log, struct oxr_handle_base *hb, uint64_t debug, oxr_handle_destroyer destroy, struct oxr_handle_base *parent)
Initialize a handle holder, and if a parent is specified, update its child list to include this handl...
XrResult oxr_handle_allocate_and_init(struct oxr_logger *log, size_t size, uint64_t debug, oxr_handle_destroyer destroy, struct oxr_handle_base *parent, void **out)
Allocate some memory for use as a handle, and initialize it as a handle.
Logger struct that lives on the stack, one for each call client call.
Definition: oxr_logger.h:40