// Copyright 2022, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Helpers for system objects like @ref xrt_system_devices. * @author Jakob Bornecrantz * @ingroup aux_util */ #include "xrt/xrt_device.h" #include "xrt/xrt_prober.h" #include "util/u_misc.h" #include "util/u_device.h" #include "util/u_system_helpers.h" #include /* * * Internal functions. * */ 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); } /* * * 'Exported' functions. * */ struct u_system_devices * u_system_devices_allocate(void) { struct u_system_devices *usysd = U_TYPED_CALLOC(struct u_system_devices); usysd->base.destroy = destroy; return usysd; } xrt_result_t u_system_devices_create_from_prober(struct xrt_instance *xinst, struct xrt_system_devices **out_xsysd) { int ret = 0; assert(out_xsysd != NULL); assert(*out_xsysd == NULL); /* * Create the devices. */ struct xrt_prober *xp = NULL; ret = xrt_instance_get_prober(xinst, &xp); if (ret < 0) { return XRT_ERROR_ALLOCATION; } ret = xrt_prober_probe(xp); if (ret < 0) { return XRT_ERROR_ALLOCATION; } return xrt_prober_create_system(xp, out_xsysd); }