Instead of calling bus_create_hid_device.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 14 ++++---------- dlls/winebus.sys/main.c | 10 ++++++++++ dlls/winebus.sys/unix_private.h | 1 + dlls/winebus.sys/unixlib.c | 14 ++++++++++++++ dlls/winebus.sys/unixlib.h | 7 +++++++ 5 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 1f7cf237e25..80252e7e6b1 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -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) diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 6093a0b79eb..8a565bc3c46 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -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; } }
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 81c4658068b..5cf999fff86 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -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 diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index 2337cb3706d..9b0ccc0ae1a 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -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); diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index 96671de0cac..85a03dd17ee 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -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; }; };
And queued events generated from initial device enumeration.
Instead of calling bus_create_hid_device.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index cca1bf5e168..78e74de842a 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -1098,7 +1098,6 @@ static void udev_add_device(struct udev_device *dev) .input = -1, }; struct platform_private *private; - DEVICE_OBJECT *device = NULL; const char *subsystem; const char *devnode; int fd; @@ -1182,9 +1181,10 @@ static void udev_add_device(struct udev_device *dev) EnterCriticalSection(&udev_cs); list_add_tail(&device_list, &private->unix_device.entry); LeaveCriticalSection(&udev_cs); + private->udev_device = udev_device_ref(dev); + private->device_fd = fd;
- device = bus_create_hid_device(&desc, &private->unix_device); - if (!device) HeapFree(GetProcessHeap(), 0, private); + bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); } #ifdef HAS_PROPER_INPUT_HEADER else if (strcmp(subsystem, "input") == 0) @@ -1195,23 +1195,12 @@ static void udev_add_device(struct udev_device *dev) EnterCriticalSection(&udev_cs); list_add_tail(&device_list, &private->unix_device.entry); LeaveCriticalSection(&udev_cs); - - device = bus_create_hid_device(&desc, &private->unix_device); - if (!device) HeapFree(GetProcessHeap(), 0, private); - } -#endif - - if (device) - { private->udev_device = udev_device_ref(dev); private->device_fd = fd; - IoInvalidateDeviceRelations(bus_pdo, BusRelations); - } - else - { - WARN("Ignoring device %s with subsystem %s\n", debugstr_a(devnode), subsystem); - close(fd); + + bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); } +#endif }
static void try_remove_device(struct udev_device *dev)
Instead of calling bus_create_hid_device.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 2 -- dlls/winebus.sys/bus_iohid.c | 12 +++--------- dlls/winebus.sys/main.c | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 15238538328..75ff218c26d 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -30,7 +30,6 @@ struct unix_device *get_unix_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
/* HID Plug and Play Bus */ -DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct unix_device *unix_device) DECLSPEC_HIDDEN; DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) DECLSPEC_HIDDEN; void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN;
@@ -38,4 +37,3 @@ void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLS BOOL is_xbox_gamepad(WORD vid, WORD pid) DECLSPEC_HIDDEN;
extern HANDLE driver_key DECLSPEC_HIDDEN; -extern DEVICE_OBJECT *bus_pdo DECLSPEC_HIDDEN; diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 9a2a6f1ec8b..3df60a1b516 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -297,7 +297,6 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * .serial = {'0','0','0','0',0}, }; struct platform_private *private; - DEVICE_OBJECT *device; CFStringRef str = NULL;
desc.vid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDVendorIDKey))); @@ -364,15 +363,10 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * if (!(private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct platform_private)))) return; private->unix_device.vtbl = &iohid_device_vtbl; + private->device = IOHIDDevice; + private->buffer = NULL;
- device = bus_create_hid_device(&desc, &private->unix_device); - if (!device) HeapFree(GetProcessHeap(), 0, private); - else - { - private->device = IOHIDDevice; - private->buffer = NULL; - IoInvalidateDeviceRelations(bus_pdo, BusRelations); - } + bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); }
static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice) diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 8a565bc3c46..42614b09f3a 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -98,7 +98,7 @@ static DEVICE_OBJECT *mouse_obj; static DEVICE_OBJECT *keyboard_obj;
/* The root-enumerated device stack. */ -DEVICE_OBJECT *bus_pdo; +static DEVICE_OBJECT *bus_pdo; static DEVICE_OBJECT *bus_fdo;
HANDLE driver_key; @@ -341,7 +341,7 @@ static void remove_pending_irps(DEVICE_OBJECT *device) } }
-DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct unix_device *unix_device) +static DEVICE_OBJECT *bus_create_hid_device(struct device_desc *desc, struct unix_device *unix_device) { static const WCHAR device_name_fmtW[] = {'\','D','e','v','i','c','e','\','%','s','#','%','p',0}; struct device_extension *ext;