Monado OpenXR Runtime
u_system.h
Go to the documentation of this file.
1// Copyright 2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Helper to implement @ref xrt_system.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_util
8 */
9
10#include "xrt/xrt_system.h"
11#include "xrt/xrt_session.h"
12#include "os/os_threading.h"
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct xrt_session;
22
23/*!
24 * A pair of @ref xrt_session and @ref xrt_session_event_sink that has been
25 * registered to this system, used to multiplex events to all sessions.
26 *
27 * @ingroup aux_util
28 */
30{
31 struct xrt_session *xs;
32 struct xrt_session_event_sink *xses;
33};
34
35/*!
36 * A helper to implement a @ref xrt_system, takes care of multiplexing events
37 * to sessions.
38 *
39 * @ingroup aux_util
40 * @implements xrt_system
41 */
43{
44 struct xrt_system base;
45
46 //! Pushes events to all sessions created from this system.
48
49 struct
50 {
51 struct os_mutex mutex;
52
53 //! Number of session and event sink pairs.
54 uint32_t count;
55 //! Capacity of the session array.
56 uint32_t capacity;
57 //! Array of session and event sink pairs.
59 } sessions;
60
61 /*!
62 * Used to implement @ref xrt_system::create_session, can be NULL. This
63 * field should be set with @ref u_system_set_system_compositor.
64 */
66};
67
68/*!
69 * Create a @ref u_system.
70 *
71 * @public @memberof u_system
72 * @ingroup aux_util
73 */
74struct u_system *
75u_system_create(void);
76
77/*!
78 * Add a @ref xrt_session to be tracked and to receive multiplexed events.
79 *
80 * @public @memberof u_system
81 * @ingroup aux_util
82 */
83void
84u_system_add_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses);
85
86/*!
87 * Remove a @ref xrt_session from tracking, it will no longer receive events,
88 * the given @p xses needs to match when it was added.
89 *
90 * @public @memberof u_system
91 * @ingroup aux_util
92 */
93void
94u_system_remove_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses);
95
96/*!
97 * Broadcast event to all sessions under this system.
98 *
99 * @public @memberof u_system
100 * @ingroup aux_util
101 */
102void
103u_system_broadcast_event(struct u_system *usys, const union xrt_session_event *xse);
104
105/*!
106 * Set the system compositor, used in the @ref xrt_system_create_session call.
107 *
108 * @public @memberof u_system
109 * @ingroup aux_util
110 */
111void
113
114/*!
115 * Fill system properties.
116 *
117 * @public @memberof u_system
118 * @ingroup aux_util
119 */
120void
121u_system_fill_properties(struct u_system *usys, const char *name);
122
123/*!
124 * Destroy an @ref u_system_create allocated @ref u_system - helper function.
125 *
126 * @param[in,out] usys_ptr A pointer to the @ref u_system_create allocated
127 * struct pointer.
128 *
129 * Will destroy the system devices if @p *usys_ptr is not NULL. Will then set
130 * @p *usys_ptr to NULL.
131 *
132 * @public @memberof u_system
133 */
134static inline void
135u_system_destroy(struct u_system **usys_ptr)
136{
137 struct u_system *usys = *usys_ptr;
138 if (usys == NULL) {
139 return;
140 }
141
142 *usys_ptr = NULL;
143 usys->base.destroy(&usys->base);
144}
145
146
147#ifdef __cplusplus
148}
149#endif
void u_system_broadcast_event(struct u_system *usys, const union xrt_session_event *xse)
Broadcast event to all sessions under this system.
Definition: u_system.c:211
void u_system_add_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses)
Add a xrt_session to be tracked and to receive multiplexed events.
Definition: u_system.c:137
void u_system_remove_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses)
Remove a xrt_session from tracking, it will no longer receive events, the given xses needs to match w...
Definition: u_system.c:164
void u_system_set_system_compositor(struct u_system *usys, struct xrt_system_compositor *xsysc)
Set the system compositor, used in the xrt_system_create_session call.
Definition: u_system.c:228
struct u_system * u_system_create(void)
Create a u_system.
Definition: u_system.c:110
void u_system_fill_properties(struct u_system *usys, const char *name)
Fill system properties.
Definition: u_system.c:236
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition: os_threading.h:55
A pair of xrt_session and xrt_session_event_sink that has been registered to this system,...
Definition: u_system.h:30
A helper to implement a xrt_system, takes care of multiplexing events to sessions.
Definition: u_system.h:43
uint32_t count
Number of session and event sink pairs.
Definition: u_system.h:54
static void u_system_destroy(struct u_system **usys_ptr)
Destroy an u_system_create allocated u_system - helper function.
Definition: u_system.h:135
uint32_t capacity
Capacity of the session array.
Definition: u_system.h:56
struct xrt_session_event_sink broadcast
Pushes events to all sessions created from this system.
Definition: u_system.h:47
struct xrt_system_compositor * xsysc
Used to implement xrt_system::create_session, can be NULL.
Definition: u_system.h:65
struct u_system_session_pair * pairs
Array of session and event sink pairs.
Definition: u_system.h:58
Used internally from producers of events to push events into session, some sinks might multiplex even...
Definition: xrt_session.h:206
The XRT representation of XrSession, this object does not have all of the functionality of a session,...
Definition: xrt_session.h:246
The system compositor handles composition for a system.
Definition: xrt_compositor.h:2423
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:63
void(* destroy)(struct xrt_system *xsys)
Destroy the system, must be destroyed after system devices and system compositor has been destroyed.
Definition: xrt_system.h:86
Union of all session events, used to return multiple events through one call.
Definition: xrt_session.h:186
Header for session object.
Header for system objects.