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 //! Array of session and event sink pairs.
57 } sessions;
58
59 /*!
60 * Used to implement @ref xrt_system::create_session, can be NULL. This
61 * field should be set with @ref u_system_set_system_compositor.
62 */
64};
65
66/*!
67 * Create a @ref u_system.
68 *
69 * @public @memberof u_system
70 * @ingroup aux_util
71 */
72struct u_system *
73u_system_create(void);
74
75/*!
76 * Add a @ref xrt_session to be tracked and to receive multiplexed events.
77 *
78 * @public @memberof u_system
79 * @ingroup aux_util
80 */
81void
82u_system_add_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses);
83
84/*!
85 * Remove a @ref xrt_session from tracking, it will no longer receive events,
86 * the given @p xses needs to match when it was added.
87 *
88 * @public @memberof u_system
89 * @ingroup aux_util
90 */
91void
92u_system_remove_session(struct u_system *usys, struct xrt_session *xs, struct xrt_session_event_sink *xses);
93
94/*!
95 * Broadcast event to all sessions under this system.
96 *
97 * @public @memberof u_system
98 * @ingroup aux_util
99 */
100void
101u_system_broadcast_event(struct u_system *usys, const union xrt_session_event *xse);
102
103/*!
104 * Set the system compositor, used in the @ref xrt_system_create_session call.
105 *
106 * @public @memberof u_system
107 * @ingroup aux_util
108 */
109void
111
112/*!
113 * Fill system properties.
114 *
115 * @public @memberof u_system
116 * @ingroup aux_util
117 */
118void
119u_system_fill_properties(struct u_system *usys, const char *name);
120
121/*!
122 * Destroy an @ref u_system_create allocated @ref u_system - helper function.
123 *
124 * @param[in,out] usys_ptr A pointer to the @ref u_system_create allocated
125 * struct pointer.
126 *
127 * Will destroy the system devices if @p *usys_ptr is not NULL. Will then set
128 * @p *usys_ptr to NULL.
129 *
130 * @public @memberof u_system
131 */
132static inline void
133u_system_destroy(struct u_system **usys_ptr)
134{
135 struct u_system *usys = *usys_ptr;
136 if (usys == NULL) {
137 return;
138 }
139
140 *usys_ptr = NULL;
141 usys->base.destroy(&usys->base);
142}
143
144
145#ifdef __cplusplus
146}
147#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:194
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:131
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:149
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:211
struct u_system * u_system_create(void)
Create a u_system.
Definition: u_system.c:112
void u_system_fill_properties(struct u_system *usys, const char *name)
Fill system properties.
Definition: u_system.c:219
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:133
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:63
struct u_system_session_pair * pairs
Array of session and event sink pairs.
Definition: u_system.h:56
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:2414
A system is a collection of devices, policies and optionally a compositor that is organised into a ch...
Definition: xrt_system.h:62
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:85
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.