winebus.sys: Return an event from SDL bus wait on device creation.

Instead of calling bus_create_hid_device.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-09-06 09:17:31 +02:00 committed by Alexandre Julliard
parent ec9892585e
commit 507a3076de
5 changed files with 36 additions and 10 deletions

View File

@ -741,7 +741,6 @@ static void sdl_add_device(unsigned int index)
.serial = {'0','0','0','0',0},
};
struct platform_private *private;
DEVICE_OBJECT *device = NULL;
char guid_str[34];
SDL_Joystick* joystick;
@ -791,16 +790,11 @@ static void sdl_add_device(unsigned int index)
if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*private))))
return;
private->unix_device.vtbl = &sdl_device_vtbl;
private->sdl_joystick = joystick;
private->sdl_controller = controller;
private->id = id;
device = bus_create_hid_device(&desc, &private->unix_device);
if (!device) HeapFree(GetProcessHeap(), 0, private);
else
{
private->sdl_joystick = joystick;
private->sdl_controller = controller;
private->id = id;
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
}
bus_event_queue_device_created(&event_queue, &private->unix_device, &desc);
}
static void process_device_event(SDL_Event *event)

View File

@ -578,6 +578,16 @@ static DWORD CALLBACK bus_main_thread(void *args)
LeaveCriticalSection(&device_list_cs);
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
break;
case BUS_EVENT_TYPE_DEVICE_CREATED:
device = bus_create_hid_device(&event->device_created.desc, event->device_created.device);
if (device) IoInvalidateDeviceRelations(bus_pdo, BusRelations);
else
{
WARN("failed to create device for %s bus device %p\n",
debugstr_w(bus.name), event->device_created.device);
winebus_call(device_remove, event->device_created.device);
}
break;
}
}

View File

@ -61,6 +61,7 @@ extern NTSTATUS iohid_bus_stop(void *) DECLSPEC_HIDDEN;
extern void bus_event_queue_destroy(struct list *queue) DECLSPEC_HIDDEN;
extern BOOL bus_event_queue_device_removed(struct list *queue, const WCHAR *bus_id, void *context) DECLSPEC_HIDDEN;
extern BOOL bus_event_queue_device_created(struct list *queue, struct unix_device *device, struct device_desc *desc) DECLSPEC_HIDDEN;
extern BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event) DECLSPEC_HIDDEN;
struct hid_descriptor

View File

@ -327,6 +327,20 @@ BOOL bus_event_queue_device_removed(struct list *queue, const WCHAR *bus_id, voi
return TRUE;
}
BOOL bus_event_queue_device_created(struct list *queue, struct unix_device *device, struct device_desc *desc)
{
ULONG size = sizeof(struct bus_event);
struct bus_event *event = HeapAlloc(GetProcessHeap(), 0, size);
if (!event) return FALSE;
event->type = BUS_EVENT_TYPE_DEVICE_CREATED;
event->device_created.device = device;
event->device_created.desc = *desc;
list_add_tail(queue, &event->entry);
return TRUE;
}
BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event)
{
struct list *entry = list_head(queue);

View File

@ -65,6 +65,7 @@ enum bus_event_type
{
BUS_EVENT_TYPE_NONE,
BUS_EVENT_TYPE_DEVICE_REMOVED,
BUS_EVENT_TYPE_DEVICE_CREATED,
};
struct bus_event
@ -79,6 +80,12 @@ struct bus_event
const WCHAR *bus_id;
void *context;
} device_removed;
struct
{
struct unix_device *device;
struct device_desc desc;
} device_created;
};
};