Monado OpenXR Runtime
xrt_prober.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Common interface to probe for devices.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup xrt_iface
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_device.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 /*
20  *
21  * Prober and device manager.
22  *
23  */
24 
25 struct xrt_fs;
26 struct xrt_frame_context;
27 struct xrt_prober;
28 struct xrt_prober_device;
30 struct os_hid_device;
31 
32 /*!
33  * The maximum number of devices that a single "found" function called by the
34  * prober can create per-call.
35  *
36  * @ingroup xrt_iface
37  */
38 #define XRT_MAX_DEVICES_PER_PROBE 16
39 
40 /*!
41  * Entry for a single device.
42  *
43  * @ingroup xrt_iface
44  */
46 {
47  uint16_t vendor_id;
48  uint16_t product_id;
49 
50  int (*found)(struct xrt_prober *xp,
51  struct xrt_prober_device **devices,
52  size_t num_devices,
53  size_t index,
54  struct xrt_device **out_xdevs);
55 
56  const char *name;
57 };
58 
59 /*!
60  * Function for creating a auto prober.
61  *
62  * @ingroup xrt_iface
63  */
64 typedef struct xrt_auto_prober *(*xrt_auto_prober_creator)();
65 
66 /*!
67  * Main root of all of the probing device.
68  *
69  * @ingroup xrt_iface
70  */
72 {
73  /*!
74  * A a null terminated list of null terminated lists of
75  * @ref xrt_prober_entry.
76  */
78 
79  /*!
80  * A null terminated list of @ref xrt_auto_prober creation functions.
81  */
83 
84  /*!
85  * Allows you to chain multiple prober entry lists.
86  */
88 };
89 
90 /*!
91  * Bus type of a device.
92  */
94 {
95  XRT_BUS_TYPE_UNKNOWN,
96  XRT_BUS_TYPE_USB,
97  XRT_BUS_TYPE_BLUETOOTH,
98 };
99 
100 /*!
101  * String descriptor types
102  */
104 {
105  XRT_PROBER_STRING_MANUFACTURER,
106  XRT_PROBER_STRING_PRODUCT,
107  XRT_PROBER_STRING_SERIAL_NUMBER,
108 };
109 
110 const char *
111 xrt_prober_string_to_string(enum xrt_prober_string t);
112 
113 const char *
114 xrt_bus_type_to_string(enum xrt_bus_type t);
115 
116 /*!
117  * A probed device, may or may not be opened.
118  *
119  * @ingroup xrt_iface
120  */
122 {
123  uint16_t vendor_id;
124  uint16_t product_id;
125 
126  enum xrt_bus_type bus;
127 
128  uint8_t usb_dev_class;
129 };
130 
131 /*!
132  * Callback for listing video devices.
133  *
134  * @ingroup xrt_iface
135  */
136 typedef void (*xrt_prober_list_video_cb)(struct xrt_prober *xp,
137  struct xrt_prober_device *pdev,
138  const char *name,
139  void *ptr);
140 
141 /*!
142  * The main prober that probes and manages found but not opened HMD devices
143  * that are connected to the system.
144  *
145  * @ingroup xrt_iface
146  */
148 {
149  //! Factory for producing tracked objects.
151 
152  int (*probe)(struct xrt_prober *xp);
153  int (*dump)(struct xrt_prober *xp);
154  int (*select)(struct xrt_prober *xp,
155  struct xrt_device **xdevs,
156  size_t num_xdevs);
157  int (*open_hid_interface)(struct xrt_prober *xp,
158  struct xrt_prober_device *xpdev,
159  int interface,
160  struct os_hid_device **out_hid_dev);
161  int (*open_video_device)(struct xrt_prober *xp,
162  struct xrt_prober_device *xpdev,
163  struct xrt_frame_context *xfctx,
164  struct xrt_fs **out_xfs);
165  int (*list_video_devices)(struct xrt_prober *xp,
167  void *ptr);
168  int (*get_string_descriptor)(struct xrt_prober *xp,
169  struct xrt_prober_device *xpdev,
170  enum xrt_prober_string which_string,
171  unsigned char *buffer,
172  int length);
173  bool (*can_open)(struct xrt_prober *xp,
174  struct xrt_prober_device *xpdev);
175  void (*destroy)(struct xrt_prober **xp_ptr);
176 };
177 
178 /*!
179  * Helper function for @ref xrt_prober::probe.
180  *
181  * @ingroup xrt_iface
182  */
183 static inline int
184 xrt_prober_probe(struct xrt_prober *xp)
185 {
186  return xp->probe(xp);
187 }
188 
189 /*!
190  * Helper function for @ref xrt_prober::dump.
191  *
192  * @ingroup xrt_iface
193  */
194 static inline int
195 xrt_prober_dump(struct xrt_prober *xp)
196 {
197  return xp->dump(xp);
198 }
199 
200 /*!
201  * Helper function for @ref xrt_prober::select.
202  *
203  * @ingroup xrt_iface
204  */
205 static inline int
206 xrt_prober_select(struct xrt_prober *xp,
207  struct xrt_device **xdevs,
208  size_t num_xdevs)
209 {
210  return xp->select(xp, xdevs, num_xdevs);
211 }
212 
213 /*!
214  * Helper function for @ref xrt_prober::open_hid_interface.
215  *
216  * @ingroup xrt_iface
217  */
218 static inline int
219 xrt_prober_open_hid_interface(struct xrt_prober *xp,
220  struct xrt_prober_device *xpdev,
221  int interface,
222  struct os_hid_device **out_hid_dev)
223 {
224  return xp->open_hid_interface(xp, xpdev, interface, out_hid_dev);
225 }
226 
227 /*!
228  * Helper function for @ref xrt_prober::get_string_descriptor.
229  *
230  * @ingroup xrt_iface
231  */
232 static inline int
233 xrt_prober_get_string_descriptor(struct xrt_prober *xp,
234  struct xrt_prober_device *xpdev,
235  enum xrt_prober_string which_string,
236  unsigned char *buffer,
237  int length)
238 {
239  return xp->get_string_descriptor(xp, xpdev, which_string, buffer,
240  length);
241 }
242 
243 /*!
244  * Helper function for @ref xrt_prober::can_open.
245  *
246  * @ingroup xrt_iface
247  */
248 static inline bool
249 xrt_prober_can_open(struct xrt_prober *xp, struct xrt_prober_device *xpdev)
250 {
251  return xp->can_open(xp, xpdev);
252 }
253 
254 
255 /*!
256  * Helper function for @ref xrt_prober::xrt_prober_open_video_device.
257  *
258  * @ingroup xrt_iface
259  */
260 static inline int
261 xrt_prober_open_video_device(struct xrt_prober *xp,
262  struct xrt_prober_device *xpdev,
263  struct xrt_frame_context *xfctx,
264  struct xrt_fs **out_xfs)
265 {
266  return xp->open_video_device(xp, xpdev, xfctx, out_xfs);
267 }
268 
269 /*!
270  * Helper function for @ref xrt_prober::list_video_devices.
271  *
272  * @ingroup xrt_iface
273  */
274 static inline int
275 xrt_prober_list_video_devices(struct xrt_prober *xp,
277  void *ptr)
278 {
279  return xp->list_video_devices(xp, cb, ptr);
280 }
281 
282 /*!
283  * Helper function for @ref xrt_prober::destroy.
284  *
285  * @ingroup xrt_iface
286  */
287 static inline void
288 xrt_prober_destroy(struct xrt_prober **xp_ptr)
289 {
290  struct xrt_prober *xp = *xp_ptr;
291  if (xp == NULL) {
292  return;
293  }
294 
295  xp->destroy(xp_ptr);
296 }
297 
298 /*!
299  * Call this function to create the @ref xrt_prober. This function is setup in
300  * the the very small target wrapper.c for each binary.
301  *
302  * @ingroup xrt_iface
303  */
304 int
305 xrt_prober_create(struct xrt_prober **out_xp);
306 
307 /*!
308  * Used by the target binary to create the prober with a list of drivers.
309  *
310  * @ingroup xrt_iface
311  */
312 int
314  struct xrt_prober_entry_lists *list);
315 
316 bool
317 xrt_prober_match_string(struct xrt_prober *xp,
318  struct xrt_prober_device *dev,
319  enum xrt_prober_string type,
320  const char *to_match);
321 
322 /*
323  *
324  * Auto prober.
325  *
326  */
327 
328 /*!
329  * A simple prober to probe for a HMD device connected to the system.
330  *
331  * @ingroup xrt_iface
332  */
334 {
335  struct xrt_device *(*lelo_dallas_autoprobe)(struct xrt_auto_prober *xap,
336  bool no_hmds,
337  struct xrt_prober *xp);
338  void (*destroy)(struct xrt_auto_prober *xdev);
339 };
340 
341 
342 #ifdef __cplusplus
343 }
344 #endif
Tracking factory.
Definition: xrt_tracking.h:71
int xrt_prober_create_with_lists(struct xrt_prober **out_xp, struct xrt_prober_entry_lists *list)
Used by the target binary to create the prober with a list of drivers.
Definition: p_prober.c:93
int xrt_prober_create(struct xrt_prober **out_xp)
Call this function to create the xrt_prober.
Definition: cli_prober.c:43
enum xrt_device_name name
Enum identifier of the device.
Definition: xrt_device.h:206
struct xrt_prober_entry ** entries
A a null terminated list of null terminated lists of xrt_prober_entry.
Definition: xrt_prober.h:77
Header defining a xrt HMD device.
xrt_prober_string
String descriptor types.
Definition: xrt_prober.h:103
xrt_bus_type
Bus type of a device.
Definition: xrt_prober.h:93
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:147
Main root of all of the probing device.
Definition: xrt_prober.h:71
A simple prober to probe for a HMD device connected to the system.
Definition: xrt_prober.h:333
Object used to track all sinks and frame producers in a graph.
Definition: xrt_frame.h:87
Representing a single hid interface on a device.
Definition: os_hid.h:26
struct xrt_tracking_factory * tracking
Factory for producing tracked objects.
Definition: xrt_prober.h:150
Entry for a single device.
Definition: xrt_prober.h:45
struct xrt_auto_prober *(* xrt_auto_prober_creator)()
Function for creating a auto prober.
Definition: xrt_prober.h:64
xrt_auto_prober_creator * auto_probers
A null terminated list of xrt_auto_prober creation functions.
Definition: xrt_prober.h:82
void(* xrt_prober_list_video_cb)(struct xrt_prober *xp, struct xrt_prober_device *pdev, const char *name, void *ptr)
Callback for listing video devices.
Definition: xrt_prober.h:136
struct xrt_prober_entry_lists * next
Allows you to chain multiple prober entry lists.
Definition: xrt_prober.h:87
A probed device, may or may not be opened.
Definition: xrt_prober.h:121
A single HMD or input device.
Definition: xrt_device.h:203
Frameserver that generates frame, multiple subframes (like stereo and mipmaps) can be generate in one...
Definition: xrt_frameserver.h:51