libfxlink: basic device enumeration without hotplug [Windows]

This commit is contained in:
Lephenixnoir 2024-08-26 19:04:09 +02:00
parent c3d7fd6efa
commit 9de441d0f4
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 10 additions and 1 deletions

View file

@ -817,13 +817,16 @@ bool fxlink_device_list_track(struct fxlink_device_list *list,
libusb_context *ctx)
{
memset(list, 0, sizeof *list);
list->ctx = ctx;
if(!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
elog("libusb doesn't handle hotplug; devices may not be detected\n");
list->hotplug_supported = false;
enumerate_devices(ctx, list);
return false;
}
list->ctx = ctx;
list->hotplug_supported = true;
libusb_hotplug_register_callback(ctx,
/* Both arriving and departing devices */
LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
@ -839,6 +842,9 @@ bool fxlink_device_list_track(struct fxlink_device_list *list,
void fxlink_device_list_refresh(struct fxlink_device_list *list)
{
if(!list->hotplug_supported)
enumerate_devices(list->ctx, list);
for(int i = 0; i < list->count; i++) {
struct fxlink_device *fdev = &list->devices[i];
/* Finish analysis */

View file

@ -299,6 +299,9 @@ struct fxlink_device_list {
libusb_context *ctx;
/* Callback handle */
libusb_hotplug_callback_handle hotplug_handle;
/* Whether the hotplug callback could be installed. If not, refreshes
will be made manually. */
bool hotplug_supported;
/* Array of connected devices */
struct fxlink_device *devices;
/* Number of elements in `devices` */