The open source OpenXR runtime
1// Copyright 2019-2023, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief OpenHMD prober code.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup drv_ohmd
8 */
9
10#include "xrt/xrt_prober.h"
11
12#include "util/u_misc.h"
13#include "util/u_debug.h"
14
15#include "oh_interface.h"
16#include "oh_device.h"
17
18#include "openhmd.h"
19
20#include <stdio.h>
21#include <stdlib.h>
22
23
24/*!
25 * @implements xrt_auto_prober
26 */
27struct oh_prober
28{
29 struct xrt_auto_prober base;
30 ohmd_context *ctx;
31};
32
33//! @private @memberof oh_prober
34static inline struct oh_prober *
35oh_prober(struct xrt_auto_prober *p)
36{
37 return (struct oh_prober *)p;
38}
39
40//! @public @memberof oh_prober
41static void
42oh_prober_destroy(struct xrt_auto_prober *p)
43{
44 struct oh_prober *ohp = oh_prober(p);
45
46 if (ohp->ctx != NULL) {
47 ohmd_ctx_destroy(ohp->ctx);
48 ohp->ctx = NULL;
49 }
50
51 free(ohp);
52}
53
54//! @public @memberof oh_prober
55static int
56oh_prober_autoprobe(struct xrt_auto_prober *xap,
57 cJSON *attached_data,
58 bool no_hmds,
59 struct xrt_prober *xp,
60 struct xrt_device **out_xdevs)
61{
62 struct oh_prober *ohp = oh_prober(xap);
63
64 int num_created = oh_device_create(ohp->ctx, no_hmds, out_xdevs);
65 return num_created;
66}
67
68struct xrt_auto_prober *
69oh_create_auto_prober(void)
70{
71 struct oh_prober *ohp = U_TYPED_CALLOC(struct oh_prober);
72 ohp->base.name = "OpenHMD";
73 ohp->base.destroy = oh_prober_destroy;
74 ohp->base.lelo_dallas_autoprobe = oh_prober_autoprobe;
75 ohp->ctx = ohmd_ctx_create();
76
77 return &ohp->base;
78}