ipc: Add support for dynamic device roles

This commit is contained in:
Korcan Hussein 2023-10-11 15:10:46 +01:00 committed by korejan
parent 5a38cbc4f0
commit 60ae73f571
7 changed files with 117 additions and 21 deletions

View file

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

View file

@ -5,6 +5,7 @@
* @brief Common client side code.
* @author Pete Black <pblack@collabora.com>
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Korcan Hussein <korcan.hussein@collabora.com>
* @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);

View file

@ -4,6 +4,7 @@
* @file
* @brief Client side wrapper of instance.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Korcan Hussein <korcan.hussein@collabora.com>
* @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;

View file

@ -0,0 +1,80 @@
// Copyright 2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief IPC Client system devices.
* @author Korcan Hussein <korcan.hussein@collabora.com>
* @author Jakob Bornecrantz <jakob@collabora.com>
* @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;
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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"}