Monado OpenXR Runtime
Loading...
Searching...
No Matches
b_system_devices.h
Go to the documentation of this file.
1// Copyright 2022-2023, Collabora, Ltd.
2// Copyright 2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Default implementation helpers for @ref xrt_system_devices.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup base
9 */
10
11#pragma once
12
13#include "xrt/xrt_frame.h"
14#include "xrt/xrt_system.h"
15#include "xrt/xrt_tracking.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
22
23/*!
24 * Helper struct to manage devices by implementing the @ref xrt_system_devices.
25 *
26 * The default destroy function that is set by @ref b_system_devices_allocate
27 * will first destroy all of the @ref xrt_device and then destroy all nodes
28 * in the @ref xrt_frame_context.
29 *
30 * @ingroup base
31 */
33{
34 struct xrt_system_devices base;
35
36 //! Optional frame context for visual tracking.
38
39 //! Optional shared tracking origin.
41};
42
43/*!
44 * Small inline helper to cast from @ref xrt_system_devices.
45 *
46 * @ingroup base
47 */
48static inline struct b_system_devices *
50{
51 return (struct b_system_devices *)xsysd;
52}
53
54/*!
55 * Allocates a empty @ref b_system_devices to be filled in by the caller, only
56 * the destroy function is filled in.
57 *
58 * @ingroup base
59 */
60struct b_system_devices *
62
63/*!
64 * Destroys all devices and clears out the frame context, doesn't free the
65 * struct itself, useful for code embedding the system devices struct into
66 * other objects where it's not the first member or C++ classes.
67 *
68 * @ingroup base
69 */
70void
72
73/*!
74 * Destroy an b_system_devices_allocate and owned devices - helper function.
75 *
76 * @param[in,out] bsysd_ptr A pointer to the b_system_devices_allocate struct pointer.
77 *
78 * Will destroy the system devices if *bsysd_ptr is not NULL. Will then set *bsysd_ptr to NULL.
79 *
80 * @public @memberof b_system_devices_allocate
81 */
82static inline void
83b_system_devices_destroy(struct b_system_devices **bsysd_ptr)
84{
85 struct b_system_devices *bsysd = *bsysd_ptr;
86 if (bsysd == NULL) {
87 return;
88 }
89
90 *bsysd_ptr = NULL;
91 bsysd->base.destroy(&bsysd->base);
92}
93
94
95/*
96 *
97 * Static helper.
98 *
99 */
100
101/*!
102 * Helper struct to manage devices by implementing the @ref xrt_system_devices,
103 * this has only static device roles.
104 *
105 * @ingroup base
106 */
108{
109 struct b_system_devices base;
110
111 //! Is automatically returned.
113
114 //! Tracks usage of device features.
115 struct xrt_reference feature_use[XRT_DEVICE_FEATURE_MAX_ENUM];
116};
117
118/*!
119 * Small inline helper to cast from @ref xrt_system_devices.
120 *
121 * @ingroup base
122 */
123static inline struct b_system_devices_static *
125{
126 return (struct b_system_devices_static *)xsysd;
127}
128
129/*!
130 * Allocates a empty @ref b_system_devices to be filled in by the caller, only
131 * the destroy function is filled in.
132 *
133 * @ingroup base
134 */
137
138/*!
139 * Finalizes the static struct with the given input devices, the system devices
140 * will always return these devices for the left and right role. This function
141 * must be called before @ref xrt_system_devices_get_roles is called.
142 *
143 * @ingroup base
144 */
145void
147 struct xrt_device *left,
148 struct xrt_device *right,
149 struct xrt_device *gamepad);
150
151#ifdef __cplusplus
152}
153#endif
struct b_system_devices_static * b_system_devices_static_allocate(void)
Allocates a empty b_system_devices to be filled in by the caller, only the destroy function is filled...
Definition b_system_devices.c:231
void b_system_devices_close(struct xrt_system_devices *xsysd)
Destroys all devices and clears out the frame context, doesn't free the struct itself,...
Definition b_system_devices.c:219
struct b_system_devices * b_system_devices_allocate(void)
Allocates a empty b_system_devices to be filled in by the caller, only the destroy function is filled...
Definition b_system_devices.c:210
void b_system_devices_static_finalize(struct b_system_devices_static *bsysds, struct xrt_device *left, struct xrt_device *right, struct xrt_device *gamepad)
Finalizes the static struct with the given input devices, the system devices will always return these...
Definition b_system_devices.c:243
Helper struct to manage devices by implementing the xrt_system_devices, this has only static device r...
Definition b_system_devices.h:108
struct xrt_system_roles cached
Is automatically returned.
Definition b_system_devices.h:112
struct xrt_reference feature_use[XRT_DEVICE_FEATURE_MAX_ENUM]
Tracks usage of device features.
Definition b_system_devices.h:115
Helper struct to manage devices by implementing the xrt_system_devices.
Definition b_system_devices.h:33
struct xrt_tracking_origin origin
Optional shared tracking origin.
Definition b_system_devices.h:40
struct xrt_frame_context xfctx
Optional frame context for visual tracking.
Definition b_system_devices.h:37
A single HMD or input device.
Definition xrt_device.h:310
Object used to track all sinks and frame producers in a graph.
Definition xrt_frame.h:108
A base class for reference counted objects.
Definition xrt_defines.h:99
Used internally from producers of events to push events into session, some sinks might multiplex even...
Definition xrt_session.h:237
A collection of xrt_device, and an interface for identifying the roles they have been assigned.
Definition xrt_system.h:214
void(* destroy)(struct xrt_system_devices *xsysd)
Destroy all the devices that are owned by this system devices.
Definition xrt_system.h:349
Data associating a device index (in xrt_system_devices::static_xdevs) with a given "role" for dynamic...
Definition xrt_system.h:154
A tracking system or device origin.
Definition xrt_tracking.h:75
Data frame header.
Header for system objects.
Header defining the tracking system integration in Monado.