Monado OpenXR Runtime
Loading...
Searching...
No Matches
xrt_app_policy.h
Go to the documentation of this file.
1// Copyright 2026, Beyley Cardellio.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header for application policy object.
6 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
7 * @ingroup xrt_iface
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19
20struct xrt_system;
21struct xrt_app_system;
22
23/*!
24 * @interface xrt_app_instance
25 *
26 * This interface acts as a way to store per-application policy for @ref xrt_instance.
27 *
28 * Only a single one of these should be created per application (aka XrInstance, in OpenXR terminology).
29 *
30 * @sa xrt_instance
31 * @sa xrt_instance_create_app_instance
32 */
34{
35 /*!
36 * @name Interface Methods
37 *
38 * All implementations of the xrt_app_instance interface must
39 * populate all these function pointers with their implementation
40 * methods. To use this interface, see the helper functions.
41 * @{
42 */
43
44 /*!
45 * Creates an application system from the passed system.
46 *
47 * All @ref xrt_app_system instances created by this function are expected to be destroyed before the
48 * xrt_app_instance is destroyed.
49 *
50 * @note Code consuming this interface should use xrt_app_instance_create_app_system()
51 *
52 * @param xainst Pointer to self
53 * @param xsys Pointer to system to wrap.
54 * @param[out] out_xasys Return of application system, required.
55 */
57 struct xrt_system *xsys,
58 struct xrt_app_system **out_xasys);
59
60 /*!
61 * Destroy the application instance and its owned objects.
62 *
63 * Code consuming this interface should use xrt_app_instance_destroy().
64 *
65 * @param xainst Pointer to self
66 */
67 void (*destroy)(struct xrt_app_instance *xainst);
68
69 /*!
70 * @}
71 */
72};
73
74/*!
75 * @copydoc xrt_app_instance::create_app_system
76 *
77 * Helper for calling through the function pointer.
78 *
79 * @public @memberof xrt_app_instance
80 */
81XRT_NONNULL_ALL static inline xrt_result_t
83 struct xrt_system *xsys,
84 struct xrt_app_system **out_xasys)
85{
86 return xainst->create_app_system(xainst, xsys, out_xasys);
87}
88
89/*!
90 * @copydoc xrt_app_instance::destroy
91 *
92 * Helper for calling through the function pointer.
93 *
94 * @public @memberof xrt_app_instance
95 */
96XRT_NONNULL_ALL static inline void
98{
99 struct xrt_app_instance *xainst = *xainst_ptr;
100 if (xainst == NULL) {
101 return;
102 }
103
104 xainst->destroy(xainst);
105 *xainst_ptr = NULL;
106}
107
108
109/*!
110 * @interface xrt_app_system
111 *
112 * This interface acts as a way to store per-application policy for @ref xrt_system.
113 *
114 * Only a single one of these should be created per @ref xrt_system per application
115 * (aka per XrInstance, in OpenXR terminology).
116 *
117 * @sa xrt_app_instance_create_app_system
118 */
120{
121 /*!
122 * @name Interface Methods
123 *
124 * All implementations of the xrt_app_system interface must
125 * populate all these function pointers with their implementation
126 * methods. To use this interface, see the helper functions.
127 * @{
128 */
129
130 /*!
131 * Destroy the application system and its owned objects.
132 *
133 * @note Code consuming this interface should use xrt_app_system_destroy().
134 *
135 * @param xasys Pointer to self
136 */
137 void (*destroy)(struct xrt_app_system *xasys);
138
139 /*!
140 * @}
141 */
142};
143
144/*!
145 * @copydoc xrt_app_system::destroy
146 *
147 * Helper for calling through the function pointer.
148 *
149 * @public @memberof xrt_app_system
150 */
151XRT_NONNULL_ALL static inline void
153{
154 struct xrt_app_system *xasys = *xasys_ptr;
155 if (xasys == NULL) {
156 return;
157 }
158
159 xasys->destroy(xasys);
160 *xasys_ptr = NULL;
161}
162
163
164#ifdef __cplusplus
165};
166#endif
enum xrt_result xrt_result_t
Result type used across Monado.
This interface acts as a way to store per-application policy for xrt_instance.
Definition xrt_app_policy.h:34
void(* destroy)(struct xrt_app_instance *xainst)
Destroy the application instance and its owned objects.
Definition xrt_app_policy.h:67
static XRT_NONNULL_ALL xrt_result_t xrt_app_instance_create_app_system(struct xrt_app_instance *xainst, struct xrt_system *xsys, struct xrt_app_system **out_xasys)
Creates an application system from the passed system.
Definition xrt_app_policy.h:82
xrt_result_t(* create_app_system)(struct xrt_app_instance *xainst, struct xrt_system *xsys, struct xrt_app_system **out_xasys)
Creates an application system from the passed system.
Definition xrt_app_policy.h:56
static XRT_NONNULL_ALL void xrt_app_instance_destroy(struct xrt_app_instance **xainst_ptr)
Destroy the application instance and its owned objects.
Definition xrt_app_policy.h:97
This interface acts as a way to store per-application policy for xrt_system.
Definition xrt_app_policy.h:120
static XRT_NONNULL_ALL void xrt_app_system_destroy(struct xrt_app_system **xasys_ptr)
Destroy the application system and its owned objects.
Definition xrt_app_policy.h:152
void(* destroy)(struct xrt_app_system *xasys)
Destroy the application system and its owned objects.
Definition xrt_app_policy.h:137
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition xrt_system.h:65
Common defines and enums for XRT.