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