The open source OpenXR runtime
1// Copyright 2022-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Remote driver builder.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup xrt_iface
8 */
9
10#include "xrt/xrt_config_drivers.h"
11#include "xrt/xrt_prober.h"
12
13#include "util/u_misc.h"
14#include "util/u_builders.h"
15#include "util/u_config_json.h"
16#include "util/u_system_helpers.h"
17
18#include "target_builder_interface.h"
19
20#include "remote/r_interface.h"
21
22#include <assert.h>
23
24
25#ifndef XRT_BUILD_DRIVER_REMOTE
26#error "Must only be built with XRT_BUILD_DRIVER_REMOTE set"
27#endif
28
29
30/*
31 *
32 * Helper functions.
33 *
34 */
35
36static bool
37get_settings(cJSON *json, int *port, uint32_t *view_count)
38{
39 struct u_config_json config_json = {0};
40 u_config_json_open_or_create_main_file(&config_json);
41
42 bool bret = u_config_json_get_remote_settings(&config_json, port, view_count);
43
44 u_config_json_close(&config_json);
45
46 return bret;
47}
48
49static const char *driver_list[] = {
50 "remote",
51};
52
53
54/*
55 *
56 * Member functions.
57 *
58 */
59
60static xrt_result_t
61remote_estimate_system(struct xrt_builder *xb,
62 cJSON *config,
63 struct xrt_prober *xp,
64 struct xrt_builder_estimate *estimate)
65{
66 estimate->certain.head = true;
67 estimate->certain.left = true;
68 estimate->certain.right = true;
69 estimate->priority = -50;
70
71 return XRT_SUCCESS;
72}
73
74static xrt_result_t
75remote_open_system(struct xrt_builder *xb,
76 cJSON *config,
77 struct xrt_prober *xp,
78 struct xrt_session_event_sink *broadcast,
79 struct xrt_system_devices **out_xsysd,
80 struct xrt_space_overseer **out_xso)
81{
82 assert(out_xsysd != NULL);
83 assert(*out_xsysd == NULL);
84
85
86 int port = 4242;
87 uint32_t view_count = 2;
88 if (!get_settings(config, &port, &view_count)) {
89 port = 4242;
90 view_count = 2;
91 }
92
93 return r_create_devices(port, view_count, broadcast, out_xsysd, out_xso);
94}
95
96static void
97remote_destroy(struct xrt_builder *xb)
98{
99 free(xb);
100}
101
102
103/*
104 *
105 * 'Exported' functions.
106 *
107 */
108
109struct xrt_builder *
110t_builder_remote_create(void)
111{
112 struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder);
113 xb->estimate_system = remote_estimate_system;
114 xb->open_system = remote_open_system;
115 xb->destroy = remote_destroy;
116 xb->identifier = "remote";
117 xb->name = "Remote simulation devices builder";
118 xb->driver_identifiers = driver_list;
119 xb->driver_identifier_count = ARRAY_SIZE(driver_list);
120 xb->exclude_from_automatic_discovery = true;
121
122 return xb;
123}