The open source OpenXR runtime
1// Copyright 2020-2024, Collabora, Ltd.
2// Copyright 2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief IPC Client device.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Korcan Hussein <korcan.hussein@collabora.com>
9 * @ingroup ipc_client
10 */
11
12#include "xrt/xrt_device.h"
13
14#include "os/os_time.h"
15
16#include "math/m_api.h"
17
18#include "util/u_var.h"
19#include "util/u_misc.h"
20#include "util/u_debug.h"
21#include "util/u_device.h"
22
23#include "client/ipc_client.h"
24#include "client/ipc_client_connection.h"
25#include "client/ipc_client_xdev.h"
26#include "ipc_client_generated.h"
27
28#include <math.h>
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <assert.h>
33
34
35/*
36 *
37 * Structs and defines.
38 *
39 */
40
41/*!
42 * An IPC client proxy for an controller or other non-MHD @ref xrt_device and
43 * @ref ipc_client_xdev. Using a typedef reduce impact of refactor change.
44 *
45 * @implements ipc_client_xdev
46 * @ingroup ipc_client
47 */
48typedef struct ipc_client_xdev ipc_client_device_t;
49
50
51/*
52 *
53 * Functions
54 *
55 */
56
57static inline ipc_client_device_t *
58ipc_client_device(struct xrt_device *xdev)
59{
60 return (ipc_client_device_t *)xdev;
61}
62
63static void
64ipc_client_device_destroy(struct xrt_device *xdev)
65{
66 ipc_client_device_t *icd = ipc_client_device(xdev);
67
68 // Remove the variable tracking.
69 u_var_remove_root(icd);
70
71 // Free and de-init the shared things.
72 ipc_client_xdev_fini(icd);
73
74 // Free this device with the helper.
75 u_device_free(&icd->base);
76}
77
78/*!
79 * @public @memberof ipc_client_device
80 */
81struct xrt_device *
82ipc_client_device_create(struct ipc_connection *ipc_c, struct xrt_tracking_origin *xtrack, uint32_t device_id)
83{
84 // Allocate and setup the basics.
85 enum u_device_alloc_flags flags = (enum u_device_alloc_flags)(U_DEVICE_ALLOC_HMD);
86 ipc_client_device_t *icd = U_DEVICE_ALLOCATE(ipc_client_device_t, flags, 0, 0);
87
88 // Fills in almost everything a regular device needs.
89 ipc_client_xdev_init(icd, ipc_c, xtrack, device_id, ipc_client_device_destroy);
90
91 // Setup variable tracker.
92 u_var_add_root(icd, icd->base.str, true);
93 u_var_add_ro_u32(icd, &icd->device_id, "device_id");
94
95 return &icd->base;
96}