u/system_helpers: Make system devices easier to embed

This commit is contained in:
Jakob Bornecrantz 2023-10-06 14:44:03 +01:00
parent 54ce551d75
commit 0b7deed16f
2 changed files with 24 additions and 9 deletions

View file

@ -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,

View file

@ -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.