From 0b7deed16f835d09e9a2ce0c821afc856ca175cf Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 6 Oct 2023 14:44:03 +0100 Subject: [PATCH] u/system_helpers: Make system devices easier to embed --- src/xrt/auxiliary/util/u_system_helpers.c | 23 ++++++++++++++--------- src/xrt/auxiliary/util/u_system_helpers.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/xrt/auxiliary/util/u_system_helpers.c b/src/xrt/auxiliary/util/u_system_helpers.c index 6125b73f9..634739c3d 100644 --- a/src/xrt/auxiliary/util/u_system_helpers.c +++ b/src/xrt/auxiliary/util/u_system_helpers.c @@ -26,15 +26,8 @@ static void destroy(struct xrt_system_devices *xsysd) { - struct u_system_devices *usysd = u_system_devices(xsysd); - - for (uint32_t i = 0; i < ARRAY_SIZE(usysd->base.xdevs); i++) { - xrt_device_destroy(&usysd->base.xdevs[i]); - } - - xrt_frame_context_destroy_nodes(&usysd->xfctx); - - free(usysd); + u_system_devices_close(xsysd); + free(xsysd); } @@ -53,6 +46,18 @@ u_system_devices_allocate(void) return usysd; } +void +u_system_devices_close(struct xrt_system_devices *xsysd) +{ + struct u_system_devices *usysd = u_system_devices(xsysd); + + for (uint32_t i = 0; i < ARRAY_SIZE(usysd->base.xdevs); i++) { + xrt_device_destroy(&usysd->base.xdevs[i]); + } + + xrt_frame_context_destroy_nodes(&usysd->xfctx); +} + xrt_result_t u_system_devices_create_from_prober(struct xrt_instance *xinst, struct xrt_system_devices **out_xsysd, diff --git a/src/xrt/auxiliary/util/u_system_helpers.h b/src/xrt/auxiliary/util/u_system_helpers.h index 45b461046..7720187dc 100644 --- a/src/xrt/auxiliary/util/u_system_helpers.h +++ b/src/xrt/auxiliary/util/u_system_helpers.h @@ -61,6 +61,16 @@ u_system_devices(struct xrt_system_devices *xsysd) struct u_system_devices * u_system_devices_allocate(void); +/*! + * Destroys all devices and clears out the frame context, doesn't free the + * struct itself, useful for code embedding the system devices struct into + * other objects where it's not the first member or C++ classes. + * + * @ingroup aux_util + */ +void +u_system_devices_close(struct xrt_system_devices *xsysd); + /*! * Takes a @ref xrt_instance, gets the prober from it and then uses the prober * to allocate a filled in @ref u_system_devices.