From 60ae73f5712b64def2348305bd77d3bed8d4dc0d Mon Sep 17 00:00:00 2001 From: Korcan Hussein Date: Wed, 11 Oct 2023 15:10:46 +0100 Subject: [PATCH] ipc: Add support for dynamic device roles --- src/xrt/ipc/CMakeLists.txt | 1 + src/xrt/ipc/client/ipc_client.h | 4 + src/xrt/ipc/client/ipc_client_instance.c | 30 +++---- .../ipc/client/ipc_client_system_devices.c | 80 +++++++++++++++++++ src/xrt/ipc/server/ipc_server_handler.c | 6 ++ src/xrt/ipc/server/ipc_server_process.c | 11 +-- src/xrt/ipc/shared/proto.json | 6 ++ 7 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 src/xrt/ipc/client/ipc_client_system_devices.c diff --git a/src/xrt/ipc/CMakeLists.txt b/src/xrt/ipc/CMakeLists.txt index 54d0336c2..8a0c83769 100644 --- a/src/xrt/ipc/CMakeLists.txt +++ b/src/xrt/ipc/CMakeLists.txt @@ -64,6 +64,7 @@ add_library( client/ipc_client_hmd.c client/ipc_client_instance.c client/ipc_client_space_overseer.c + client/ipc_client_system_devices.c ) target_include_directories( ipc_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/xrt/ipc/client/ipc_client.h b/src/xrt/ipc/client/ipc_client.h index 6f2922ea5..82e3742f5 100644 --- a/src/xrt/ipc/client/ipc_client.h +++ b/src/xrt/ipc/client/ipc_client.h @@ -5,6 +5,7 @@ * @brief Common client side code. * @author Pete Black * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup ipc_client */ @@ -118,3 +119,6 @@ ipc_client_device_create(struct ipc_connection *ipc_c, struct xrt_tracking_origi struct xrt_space_overseer * ipc_client_space_overseer_create(struct ipc_connection *ipc_c); + +struct xrt_system_devices * +ipc_client_system_devices_create(struct ipc_connection *ipc_c); diff --git a/src/xrt/ipc/client/ipc_client_instance.c b/src/xrt/ipc/client/ipc_client_instance.c index 4d49c6305..da37517c6 100644 --- a/src/xrt/ipc/client/ipc_client_instance.c +++ b/src/xrt/ipc/client/ipc_client_instance.c @@ -4,6 +4,7 @@ * @file * @brief Client side wrapper of instance. * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup ipc_client */ @@ -57,6 +58,7 @@ DEBUG_GET_ONCE_LOG_OPTION(ipc_log, "IPC_LOG", U_LOGGING_WARN) + /* * * Struct and helpers. @@ -130,24 +132,24 @@ ipc_client_instance_create_system(struct xrt_instance *xinst, assert(*out_xsysd == NULL); assert(out_xsysc == NULL || *out_xsysc == NULL); - // Allocate a helper u_system_devices struct. - struct u_system_devices *usysd = u_system_devices_allocate(); + // Allocate a helper xrt_system_devices struct. + struct xrt_system_devices *xsysd = ipc_client_system_devices_create(&ii->ipc_c); // Take the devices from this instance. for (uint32_t i = 0; i < ii->xdev_count; i++) { - usysd->base.xdevs[i] = ii->xdevs[i]; + xsysd->xdevs[i] = ii->xdevs[i]; ii->xdevs[i] = NULL; } - usysd->base.xdev_count = ii->xdev_count; + xsysd->xdev_count = ii->xdev_count; ii->xdev_count = 0; #define SET_ROLE(ROLE) \ - usysd->base.roles.ROLE = ii->ipc_c.ism->roles.ROLE >= 0 ? usysd->base.xdevs[ii->ipc_c.ism->roles.ROLE] : NULL; + do { \ + int32_t index = ii->ipc_c.ism->roles.ROLE; \ + xsysd->static_roles.ROLE = index >= 0 ? xsysd->xdevs[index] : NULL; \ + } while (false) SET_ROLE(head); - SET_ROLE(left); - SET_ROLE(right); - SET_ROLE(gamepad); SET_ROLE(eyes); SET_ROLE(hand_tracking.left); SET_ROLE(hand_tracking.right); @@ -165,25 +167,25 @@ ipc_client_instance_create_system(struct xrt_instance *xinst, // Done here now. if (out_xsysc == NULL) { - *out_xsysd = &usysd->base; + *out_xsysd = xsysd; *out_xso = ipc_client_space_overseer_create(&ii->ipc_c); return XRT_SUCCESS; } - if (usysd->base.roles.head == NULL) { + if (xsysd->static_roles.head == NULL) { IPC_ERROR((&ii->ipc_c), "No head device found but asking for system compositor!"); - u_system_devices_destroy(&usysd); + xrt_system_devices_destroy(&xsysd); return XRT_ERROR_IPC_FAILURE; } struct xrt_system_compositor *xsysc = NULL; - xret = create_system_compositor(ii, usysd->base.roles.head, &xsysc); + xret = create_system_compositor(ii, xsysd->static_roles.head, &xsysc); if (xret != XRT_SUCCESS) { - u_system_devices_destroy(&usysd); + xrt_system_devices_destroy(&xsysd); return xret; } - *out_xsysd = &usysd->base; + *out_xsysd = xsysd; *out_xso = ipc_client_space_overseer_create(&ii->ipc_c); *out_xsysc = xsysc; diff --git a/src/xrt/ipc/client/ipc_client_system_devices.c b/src/xrt/ipc/client/ipc_client_system_devices.c new file mode 100644 index 000000000..fc7fb1e88 --- /dev/null +++ b/src/xrt/ipc/client/ipc_client_system_devices.c @@ -0,0 +1,80 @@ +// Copyright 2023, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief IPC Client system devices. + * @author Korcan Hussein + * @author Jakob Bornecrantz + * @ingroup ipc_client + */ + +#include "ipc_client.h" +#include "ipc_client_generated.h" + +#include "util/u_system_helpers.h" + + +struct ipc_client_system_devices +{ + //! @public Base + struct u_system_devices base; + + //! Connection to service. + struct ipc_connection *ipc_c; +}; + + +/* + * + * Helpers + * + */ + +static inline struct ipc_client_system_devices * +ipc_system_devices(struct xrt_system_devices *xsysd) +{ + return (struct ipc_client_system_devices *)xsysd; +} + + +/* + * + * Member functions. + * + */ + +static xrt_result_t +ipc_client_system_devices_get_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles) +{ + struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); + + return ipc_call_system_devices_get_roles(usysd->ipc_c, out_roles); +} + +static void +ipc_client_system_devices_destroy(struct xrt_system_devices *xsysd) +{ + struct ipc_client_system_devices *usysd = ipc_system_devices(xsysd); + + u_system_devices_close(&usysd->base.base); + + free(usysd); +} + + +/* + * + * 'Exported' functions. + * + */ + +struct xrt_system_devices * +ipc_client_system_devices_create(struct ipc_connection *ipc_c) +{ + struct ipc_client_system_devices *icsd = U_TYPED_CALLOC(struct ipc_client_system_devices); + icsd->base.base.get_roles = ipc_client_system_devices_get_roles; + icsd->base.base.destroy = ipc_client_system_devices_destroy; + icsd->ipc_c = ipc_c; + + return &icsd->base.base; +} diff --git a/src/xrt/ipc/server/ipc_server_handler.c b/src/xrt/ipc/server/ipc_server_handler.c index 352da2868..c7c316753 100644 --- a/src/xrt/ipc/server/ipc_server_handler.c +++ b/src/xrt/ipc/server/ipc_server_handler.c @@ -1489,3 +1489,9 @@ ipc_handle_device_is_form_factor_available(volatile struct ipc_client_state *ics *out_available = xrt_device_is_form_factor_available(xdev, form_factor); return XRT_SUCCESS; } + +xrt_result_t +ipc_handle_system_devices_get_roles(volatile struct ipc_client_state *ics, struct xrt_system_roles *out_roles) +{ + return xrt_system_devices_get_roles(ics->server->xsysd, out_roles); +} diff --git a/src/xrt/ipc/server/ipc_server_process.c b/src/xrt/ipc/server/ipc_server_process.c index a38a69eb2..a008e2229 100644 --- a/src/xrt/ipc/server/ipc_server_process.c +++ b/src/xrt/ipc/server/ipc_server_process.c @@ -359,13 +359,10 @@ init_shm(struct ipc_server *s) s->ism->isdev_count = count; // Assign all of the roles. - ism->roles.head = find_xdev_index(s, s->xsysd->roles.head); - ism->roles.left = find_xdev_index(s, s->xsysd->roles.left); - ism->roles.right = find_xdev_index(s, s->xsysd->roles.right); - ism->roles.gamepad = find_xdev_index(s, s->xsysd->roles.gamepad); - ism->roles.hand_tracking.left = find_xdev_index(s, s->xsysd->roles.hand_tracking.left); - ism->roles.hand_tracking.right = find_xdev_index(s, s->xsysd->roles.hand_tracking.right); - ism->roles.eyes = find_xdev_index(s, s->xsysd->roles.eyes); + ism->roles.head = find_xdev_index(s, s->xsysd->static_roles.head); + ism->roles.eyes = find_xdev_index(s, s->xsysd->static_roles.eyes); + ism->roles.hand_tracking.left = find_xdev_index(s, s->xsysd->static_roles.hand_tracking.left); + ism->roles.hand_tracking.right = find_xdev_index(s, s->xsysd->static_roles.hand_tracking.right); // Fill out git version info. snprintf(s->ism->u_git_tag, IPC_VERSION_NAME_LEN, "%s", u_git_tag); diff --git a/src/xrt/ipc/shared/proto.json b/src/xrt/ipc/shared/proto.json index dbc68ef7c..da8179f9e 100644 --- a/src/xrt/ipc/shared/proto.json +++ b/src/xrt/ipc/shared/proto.json @@ -50,6 +50,12 @@ ] }, + "system_devices_get_roles": { + "out": [ + {"name": "system_roles", "type": "struct xrt_system_roles"} + ] + }, + "system_compositor_get_info": { "out": [ {"name": "info", "type": "struct xrt_system_compositor_info"}