st/prober: Allow "found" functions called by prober to make more than one device.

This commit is contained in:
Ryan Pavlik 2019-06-21 18:01:27 -05:00 committed by Jakob Bornecrantz
parent a673a4d469
commit 1f84814721
5 changed files with 37 additions and 13 deletions

View file

@ -446,7 +446,7 @@ int
psmv_found(struct xrt_prober *xp, psmv_found(struct xrt_prober *xp,
struct xrt_prober_device **devices, struct xrt_prober_device **devices,
size_t index, size_t index,
struct xrt_device **out_xdev) struct xrt_device **out_xdevs)
{ {
struct os_hid_device *hid = NULL; struct os_hid_device *hid = NULL;
int ret; int ret;
@ -506,6 +506,6 @@ psmv_found(struct xrt_prober *xp,
psmv_read_hid(psmv); psmv_read_hid(psmv);
// And finally done // And finally done
*out_xdev = &psmv->base; *out_xdevs = &psmv->base;
return 0; return 1;
} }

View file

@ -33,7 +33,7 @@ int
psmv_found(struct xrt_prober *xp, psmv_found(struct xrt_prober *xp,
struct xrt_prober_device **devices, struct xrt_prober_device **devices,
size_t index, size_t index,
struct xrt_device **out_xdev); struct xrt_device **out_xdevs);
/*! /*!
* @dir drivers/psmv * @dir drivers/psmv

View file

@ -27,6 +27,14 @@ extern "C" {
struct xrt_prober; struct xrt_prober;
struct xrt_prober_device; struct xrt_prober_device;
/*!
* The maximum number of devices that a single "found" function called by the
* prober can create per-call.
*
* @ingroup xrt_iface
*/
#define XRT_MAX_DEVICES_PER_PROBE 16
/*! /*!
* Entry for a single device. * Entry for a single device.
* *
@ -40,7 +48,7 @@ struct xrt_prober_entry
int (*found)(struct xrt_prober *xp, int (*found)(struct xrt_prober *xp,
struct xrt_prober_device **devices, struct xrt_prober_device **devices,
size_t index, size_t index,
struct xrt_device **out_xdev); struct xrt_device **out_xdevs);
const char *name; const char *name;
}; };

View file

@ -444,14 +444,28 @@ select_device(struct xrt_prober* xp,
continue; continue;
} }
struct xrt_device* xdev = NULL; struct xrt_device*
entry->found(xp, dev_list, i, &xdev); new_xdevs[XRT_MAX_DEVICES_PER_PROBE] = {NULL};
int num_found =
entry->found(xp, dev_list, i, &(new_xdevs[0]));
if (xdev == NULL) { if (num_found <= 0) {
continue; continue;
} }
for (int created_idx = 0; created_idx < num_found;
handle_found_device(p, xdevs, num_xdevs, xdev); ++created_idx) {
if (new_xdevs[created_idx] == NULL) {
P_DEBUG(
p,
"Leaving device creation loop "
"early: found function reported %i "
"created, but only %i non-null",
num_found, created_idx);
continue;
}
handle_found_device(p, xdevs, num_xdevs,
new_xdevs[created_idx]);
}
} }
} }

View file

@ -34,11 +34,13 @@
* - `struct xrt_prober *xp` * - `struct xrt_prober *xp`
* - `struct xrt_prober_device **devices` * - `struct xrt_prober_device **devices`
* - `size_t index` * - `size_t index`
* - `struct xrt_device **out_xdev` * - `struct xrt_device **out_xdevs` (an array of XRT_MAX_DEVICES_PER_PROBE
* xrt_device pointers)
* *
* It is called when devices[index] match the VID and PID in the list. * It is called when devices[index] match the VID and PID in the list.
* It should return 0 if it decides not to create any devices, or 1 if it * It should return 0 if it decides not to create any devices, negative on
* creates one: it should assign *out_xdev to the created device. * error, and the number of devices created if it creates one or more: it should
* assign sequential elements of out_xdevs to the created devices.
*/ */
struct xrt_prober_entry target_entry_list[] = { struct xrt_prober_entry target_entry_list[] = {
#ifdef XRT_BUILD_PSVR #ifdef XRT_BUILD_PSVR