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 Ryan Pavlik <ryan.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 XrResult
32 oxr_handle_init(struct oxr_logger *log,
33  struct oxr_handle_base *hb,
34  uint64_t debug,
35  oxr_handle_destroyer destroy,
36  struct oxr_handle_base *parent);
37 
38 /*!
39  * Allocate some memory for use as a handle, and initialize it as a handle.
40  *
41  * Mainly for internal use - use OXR_ALLOCATE_HANDLE instead which wraps this.
42  */
43 XrResult
45  size_t size,
46  uint64_t debug,
47  oxr_handle_destroyer destroy,
48  struct oxr_handle_base *parent,
49  void **out);
50 /*!
51  * Allocates memory for a handle and evaluates to an XrResult.
52  *
53  * @param LOG pointer to struct oxr_logger
54  * @param OUT the pointer to handle struct type you already created.
55  * @param DEBUG Magic per-type debugging constant
56  * @param DESTROY Handle destructor function
57  * @param PARENT a parent handle, if any
58  *
59  * Use when you want to do something other than immediately returning in case of
60  * failure. If returning immediately is OK, see OXR_ALLOCATE_HANDLE_OR_RETURN().
61  */
62 #define OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT) \
63  oxr_handle_allocate_and_init(LOG, sizeof(*OUT), DEBUG, DESTROY, \
64  PARENT, (void **)&OUT)
65 
66 /*!
67  * Allocate memory for a handle, returning in case of failure.
68  *
69  * @param LOG pointer to struct oxr_logger
70  * @param OUT the pointer to handle struct type you already created.
71  * @param DEBUG Magic per-type debugging constant
72  * @param DESTROY Handle destructor function
73  * @param PARENT a parent handle, if any
74  *
75  * Will return an XrResult from the current function if something fails.
76  * If that's not OK, see OXR_ALLOCATE_HANDLE().
77  */
78 #define OXR_ALLOCATE_HANDLE_OR_RETURN(LOG, OUT, DEBUG, DESTROY, PARENT) \
79  do { \
80  XrResult allocResult = \
81  OXR_ALLOCATE_HANDLE(LOG, OUT, DEBUG, DESTROY, PARENT); \
82  if (allocResult != XR_SUCCESS) { \
83  return allocResult; \
84  } \
85  } while (0)
86 
87 #ifdef __cplusplus
88 }
89 #endif
Logger struct that lives on the stack, one for each call client call.
Definition: oxr_logger.h:36
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...
Definition: oxr_handle_base.c:55
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.
Definition: oxr_handle_base.c:109
Contains the instance struct that a lot of things hang from.
Used to hold diverse child handles and ensure orderly destruction.
Definition: oxr_objects.h:826
XrResult(* oxr_handle_destroyer)(struct oxr_logger *log, struct oxr_handle_base *hb)
Definition: oxr_objects.h:90