mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
ipc: Add support for dynamic device roles
This commit is contained in:
parent
5a38cbc4f0
commit
60ae73f571
|
@ -64,6 +64,7 @@ add_library(
|
||||||
client/ipc_client_hmd.c
|
client/ipc_client_hmd.c
|
||||||
client/ipc_client_instance.c
|
client/ipc_client_instance.c
|
||||||
client/ipc_client_space_overseer.c
|
client/ipc_client_space_overseer.c
|
||||||
|
client/ipc_client_system_devices.c
|
||||||
)
|
)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
ipc_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
ipc_client PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* @brief Common client side code.
|
* @brief Common client side code.
|
||||||
* @author Pete Black <pblack@collabora.com>
|
* @author Pete Black <pblack@collabora.com>
|
||||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||||
|
* @author Korcan Hussein <korcan.hussein@collabora.com>
|
||||||
* @ingroup ipc_client
|
* @ingroup ipc_client
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -118,3 +119,6 @@ ipc_client_device_create(struct ipc_connection *ipc_c, struct xrt_tracking_origi
|
||||||
|
|
||||||
struct xrt_space_overseer *
|
struct xrt_space_overseer *
|
||||||
ipc_client_space_overseer_create(struct ipc_connection *ipc_c);
|
ipc_client_space_overseer_create(struct ipc_connection *ipc_c);
|
||||||
|
|
||||||
|
struct xrt_system_devices *
|
||||||
|
ipc_client_system_devices_create(struct ipc_connection *ipc_c);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* @file
|
* @file
|
||||||
* @brief Client side wrapper of instance.
|
* @brief Client side wrapper of instance.
|
||||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||||
|
* @author Korcan Hussein <korcan.hussein@collabora.com>
|
||||||
* @ingroup ipc_client
|
* @ingroup ipc_client
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
|
|
||||||
DEBUG_GET_ONCE_LOG_OPTION(ipc_log, "IPC_LOG", U_LOGGING_WARN)
|
DEBUG_GET_ONCE_LOG_OPTION(ipc_log, "IPC_LOG", U_LOGGING_WARN)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Struct and helpers.
|
* Struct and helpers.
|
||||||
|
@ -130,24 +132,24 @@ ipc_client_instance_create_system(struct xrt_instance *xinst,
|
||||||
assert(*out_xsysd == NULL);
|
assert(*out_xsysd == NULL);
|
||||||
assert(out_xsysc == NULL || *out_xsysc == NULL);
|
assert(out_xsysc == NULL || *out_xsysc == NULL);
|
||||||
|
|
||||||
// Allocate a helper u_system_devices struct.
|
// Allocate a helper xrt_system_devices struct.
|
||||||
struct u_system_devices *usysd = u_system_devices_allocate();
|
struct xrt_system_devices *xsysd = ipc_client_system_devices_create(&ii->ipc_c);
|
||||||
|
|
||||||
// Take the devices from this instance.
|
// Take the devices from this instance.
|
||||||
for (uint32_t i = 0; i < ii->xdev_count; i++) {
|
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;
|
ii->xdevs[i] = NULL;
|
||||||
}
|
}
|
||||||
usysd->base.xdev_count = ii->xdev_count;
|
xsysd->xdev_count = ii->xdev_count;
|
||||||
ii->xdev_count = 0;
|
ii->xdev_count = 0;
|
||||||
|
|
||||||
#define SET_ROLE(ROLE) \
|
#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(head);
|
||||||
SET_ROLE(left);
|
|
||||||
SET_ROLE(right);
|
|
||||||
SET_ROLE(gamepad);
|
|
||||||
SET_ROLE(eyes);
|
SET_ROLE(eyes);
|
||||||
SET_ROLE(hand_tracking.left);
|
SET_ROLE(hand_tracking.left);
|
||||||
SET_ROLE(hand_tracking.right);
|
SET_ROLE(hand_tracking.right);
|
||||||
|
@ -165,25 +167,25 @@ ipc_client_instance_create_system(struct xrt_instance *xinst,
|
||||||
|
|
||||||
// Done here now.
|
// Done here now.
|
||||||
if (out_xsysc == NULL) {
|
if (out_xsysc == NULL) {
|
||||||
*out_xsysd = &usysd->base;
|
*out_xsysd = xsysd;
|
||||||
*out_xso = ipc_client_space_overseer_create(&ii->ipc_c);
|
*out_xso = ipc_client_space_overseer_create(&ii->ipc_c);
|
||||||
return XRT_SUCCESS;
|
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!");
|
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;
|
return XRT_ERROR_IPC_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xrt_system_compositor *xsysc = NULL;
|
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) {
|
if (xret != XRT_SUCCESS) {
|
||||||
u_system_devices_destroy(&usysd);
|
xrt_system_devices_destroy(&xsysd);
|
||||||
return xret;
|
return xret;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_xsysd = &usysd->base;
|
*out_xsysd = xsysd;
|
||||||
*out_xso = ipc_client_space_overseer_create(&ii->ipc_c);
|
*out_xso = ipc_client_space_overseer_create(&ii->ipc_c);
|
||||||
*out_xsysc = xsysc;
|
*out_xsysc = xsysc;
|
||||||
|
|
||||||
|
|
80
src/xrt/ipc/client/ipc_client_system_devices.c
Normal file
80
src/xrt/ipc/client/ipc_client_system_devices.c
Normal 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;
|
||||||
|
}
|
|
@ -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);
|
*out_available = xrt_device_is_form_factor_available(xdev, form_factor);
|
||||||
return XRT_SUCCESS;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -359,13 +359,10 @@ init_shm(struct ipc_server *s)
|
||||||
s->ism->isdev_count = count;
|
s->ism->isdev_count = count;
|
||||||
|
|
||||||
// Assign all of the roles.
|
// Assign all of the roles.
|
||||||
ism->roles.head = find_xdev_index(s, s->xsysd->roles.head);
|
ism->roles.head = find_xdev_index(s, s->xsysd->static_roles.head);
|
||||||
ism->roles.left = find_xdev_index(s, s->xsysd->roles.left);
|
ism->roles.eyes = find_xdev_index(s, s->xsysd->static_roles.eyes);
|
||||||
ism->roles.right = find_xdev_index(s, s->xsysd->roles.right);
|
ism->roles.hand_tracking.left = find_xdev_index(s, s->xsysd->static_roles.hand_tracking.left);
|
||||||
ism->roles.gamepad = find_xdev_index(s, s->xsysd->roles.gamepad);
|
ism->roles.hand_tracking.right = find_xdev_index(s, s->xsysd->static_roles.hand_tracking.right);
|
||||||
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);
|
|
||||||
|
|
||||||
// Fill out git version info.
|
// Fill out git version info.
|
||||||
snprintf(s->ism->u_git_tag, IPC_VERSION_NAME_LEN, "%s", u_git_tag);
|
snprintf(s->ism->u_git_tag, IPC_VERSION_NAME_LEN, "%s", u_git_tag);
|
||||||
|
|
|
@ -50,6 +50,12 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"system_devices_get_roles": {
|
||||||
|
"out": [
|
||||||
|
{"name": "system_roles", "type": "struct xrt_system_roles"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
"system_compositor_get_info": {
|
"system_compositor_get_info": {
|
||||||
"out": [
|
"out": [
|
||||||
{"name": "info", "type": "struct xrt_system_compositor_info"}
|
{"name": "info", "type": "struct xrt_system_compositor_info"}
|
||||||
|
|
Loading…
Reference in a new issue