The open source OpenXR runtime
at main 91 lines 2.0 kB view raw
1// Copyright 2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Helper to implement @ref xrt_session. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 * @ingroup aux_util 8 */ 9 10#include "xrt/xrt_session.h" 11#include "os/os_threading.h" 12 13 14#ifdef __cplusplus 15extern "C" { 16#endif 17 18 19/*! 20 * Struct used by @ref u_session to queue up events. 21 * 22 * @ingroup aux_util 23 */ 24struct u_session_event 25{ 26 union xrt_session_event xse; 27 struct u_session_event *next; 28}; 29 30/*! 31 * This is a helper struct that fully implements @ref xrt_session object. 32 * 33 * The use of @ref u_system is optional, but if not used you will need to track 34 * the session and signal it's destruction yourself. 35 * 36 * @ingroup aux_util 37 * @implements xrt_session 38 */ 39struct u_session 40{ 41 struct xrt_session base; 42 43 //! Pushes events to this session, used to share to other components. 44 struct xrt_session_event_sink sink; 45 46 //! Owning system, optional. 47 struct u_system *usys; 48 49 struct 50 { 51 struct os_mutex mutex; 52 struct u_session_event *ptr; 53 } events; 54}; 55 56/*! 57 * Create a session, optionally pass in a @ref u_system. If @p usys is not NULL 58 * the call register this session on that system. This function is exposed so 59 * that code can reuse @ref u_session as a base class. 60 * 61 * @public @memberof u_session 62 * @ingroup aux_util 63 */ 64struct u_session * 65u_session_create(struct u_system *usys); 66 67/*! 68 * Push an event to this session. This function is exposed so that code can 69 * reuse @ref u_session as a base class. 70 * 71 * 72 * @public @memberof u_session 73 * @ingroup aux_util 74 */ 75void 76u_session_event_push(struct u_session *us, const union xrt_session_event *xse); 77 78/*! 79 * Pop a single event from this session, if no event is available 80 * then the type of the event will be @ref XRT_SESSION_EVENT_NONE. 81 * 82 * @public @memberof u_session 83 * @ingroup aux_util 84 */ 85void 86u_session_event_pop(struct u_session *us, union xrt_session_event *out_xse); 87 88 89#ifdef __cplusplus 90} 91#endif