The open source OpenXR runtime
at mr/scanout-values 119 lines 2.9 kB view raw
1// Copyright 2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief IPC Client system devices. 6 * @author Korcan Hussein <korcan.hussein@collabora.com> 7 * @author Jakob Bornecrantz <jakob@collabora.com> 8 * @ingroup ipc_client 9 */ 10 11#include "ipc_client.h" 12#include "ipc_client_generated.h" 13 14#include "util/u_system_helpers.h" 15 16 17struct ipc_client_system_devices 18{ 19 //! @public Base 20 struct u_system_devices base; 21 22 //! Connection to service. 23 struct ipc_connection *ipc_c; 24 25 struct xrt_reference feature_use[XRT_DEVICE_FEATURE_MAX_ENUM]; 26}; 27 28 29/* 30 * 31 * Helpers 32 * 33 */ 34 35static inline struct ipc_client_system_devices * 36ipc_system_devices(struct xrt_system_devices *xsysd) 37{ 38 return (struct ipc_client_system_devices *)xsysd; 39} 40 41 42/* 43 * 44 * Member functions. 45 * 46 */ 47 48static xrt_result_t 49ipc_client_system_devices_get_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles) 50{ 51 struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); 52 53 return ipc_call_system_devices_get_roles(usysd->ipc_c, out_roles); 54} 55 56static xrt_result_t 57ipc_client_system_devices_feature_inc(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type) 58{ 59 struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); 60 xrt_result_t xret; 61 62 assert(type < XRT_DEVICE_FEATURE_MAX_ENUM); 63 64 // If it wasn't zero nothing to do. 65 if (!xrt_reference_inc_and_was_zero(&usysd->feature_use[type])) { 66 return XRT_SUCCESS; 67 } 68 69 xret = ipc_call_system_devices_begin_feature(usysd->ipc_c, type); 70 IPC_CHK_ALWAYS_RET(usysd->ipc_c, xret, "ipc_call_system_devices_begin_feature"); 71} 72 73static xrt_result_t 74ipc_client_system_devices_feature_dec(struct xrt_system_devices *xsysd, enum xrt_device_feature_type type) 75{ 76 struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); 77 xrt_result_t xret; 78 79 assert(type < XRT_DEVICE_FEATURE_MAX_ENUM); 80 81 // If it is not zero we are done. 82 if (!xrt_reference_dec_and_is_zero(&usysd->feature_use[type])) { 83 return XRT_SUCCESS; 84 } 85 86 xret = ipc_call_system_devices_end_feature(usysd->ipc_c, type); 87 IPC_CHK_ALWAYS_RET(usysd->ipc_c, xret, "ipc_call_system_devices_end_feature"); 88} 89 90 91static void 92ipc_client_system_devices_destroy(struct xrt_system_devices *xsysd) 93{ 94 struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); 95 96 u_system_devices_close(&usysd->base.base); 97 98 free(usysd); 99} 100 101 102/* 103 * 104 * 'Exported' functions. 105 * 106 */ 107 108struct xrt_system_devices * 109ipc_client_system_devices_create(struct ipc_connection *ipc_c) 110{ 111 struct ipc_client_system_devices *icsd = U_TYPED_CALLOC(struct ipc_client_system_devices); 112 icsd->base.base.get_roles = ipc_client_system_devices_get_roles; 113 icsd->base.base.destroy = ipc_client_system_devices_destroy; 114 icsd->base.base.feature_inc = ipc_client_system_devices_feature_inc; 115 icsd->base.base.feature_dec = ipc_client_system_devices_feature_dec; 116 icsd->ipc_c = ipc_c; 117 118 return &icsd->base.base; 119}