Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus.h | 4 --- dlls/winebus.sys/bus_iohid.c | 62 ++++++++++++++++----------------- dlls/winebus.sys/main.c | 35 ++++++++++++++++++- dlls/winebus.sys/unix_private.h | 4 +++ dlls/winebus.sys/unixlib.c | 3 ++ dlls/winebus.sys/unixlib.h | 8 +++++ 6 files changed, 80 insertions(+), 36 deletions(-)
diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h index 4618dea1396..1e4f37ae896 100644 --- a/dlls/winebus.sys/bus.h +++ b/dlls/winebus.sys/bus.h @@ -27,10 +27,6 @@
typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
-/* Buses */ -NTSTATUS iohid_driver_init(void) DECLSPEC_HIDDEN; -void iohid_driver_unload( void ) DECLSPEC_HIDDEN; - /* Native device function table */ typedef struct { diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 4eb0ea0e4b3..e21c58b7c84 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -90,13 +90,16 @@ #include "wine/debug.h"
#include "bus.h" +#include "unix_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay); + #ifdef HAVE_IOHIDMANAGERCREATE
+static struct iohid_bus_options options; + static IOHIDManagerRef hid_manager; static CFRunLoopRef run_loop; -static HANDLE run_loop_handle;
static const WCHAR busidW[] = {'I','O','H','I','D',0};
@@ -385,63 +388,60 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, } }
-/* This puts the relevant run loop for event handling into a WINE thread */ -static DWORD CALLBACK runloop_thread(void *args) +NTSTATUS WINAPI iohid_bus_init(void *args) { + TRACE("args %p\n", args); + + options = *(struct iohid_bus_options *)args; + + hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L); run_loop = CFRunLoopGetCurrent();
IOHIDManagerSetDeviceMatching(hid_manager, NULL); IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, handle_DeviceMatchingCallback, NULL); IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, handle_RemovalCallback, NULL); IOHIDManagerScheduleWithRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode); - - CFRunLoopRun(); - TRACE("Run Loop exiting\n"); - return 1; - + return STATUS_SUCCESS; }
-NTSTATUS iohid_driver_init(void) +NTSTATUS WINAPI iohid_bus_wait(void) { - hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L); - if (!(run_loop_handle = CreateThread(NULL, 0, runloop_thread, NULL, 0, NULL))) - { - ERR("Failed to initialize IOHID Manager thread\n"); - CFRelease(hid_manager); - return STATUS_UNSUCCESSFUL; - } + CFRunLoopRun();
- TRACE("Initialization successful\n"); + TRACE("IOHID main loop exiting\n"); + IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL); + IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL); + CFRelease(hid_manager); return STATUS_SUCCESS; }
-void iohid_driver_unload( void ) +NTSTATUS WINAPI iohid_bus_stop(void) { - TRACE("Unloading Driver\n"); - - if (!run_loop_handle) - return; + if (!run_loop) return STATUS_SUCCESS;
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode); CFRunLoopStop(run_loop); - WaitForSingleObject(run_loop_handle, INFINITE); - CloseHandle(run_loop_handle); - IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL); - IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL); - CFRelease(hid_manager); - TRACE("Driver Unloaded\n"); + return STATUS_SUCCESS; }
#else
-NTSTATUS iohid_driver_init(void) +NTSTATUS WINAPI iohid_bus_init(void *args) +{ + WARN("IOHID support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; +} + +NTSTATUS WINAPI iohid_bus_wait(void) { + WARN("IOHID support not compiled in!\n"); return STATUS_NOT_IMPLEMENTED; }
-void iohid_driver_unload( void ) +NTSTATUS WINAPI iohid_bus_stop(void) { - TRACE("Stub: Unload Driver\n"); + WARN("IOHID support not compiled in!\n"); + return STATUS_NOT_IMPLEMENTED; }
#endif /* HAVE_IOHIDMANAGERCREATE */ diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c index 36a281bec9d..2b7566d25df 100644 --- a/dlls/winebus.sys/main.c +++ b/dlls/winebus.sys/main.c @@ -747,6 +747,39 @@ static NTSTATUS udev_driver_init(void) return STATUS_SUCCESS; }
+static NTSTATUS iohid_driver_init(void) +{ + static const WCHAR iohid_bus_name[] = {'I','O','H','I','D',0}; + struct iohid_bus_options iohid_params; + struct bus_main_params params = + { + .name = iohid_bus_name, + .bus_init = unix_funcs->iohid_bus_init, + .bus_wait = unix_funcs->iohid_bus_wait, + .bus_params = &iohid_params, + }; + DWORD i = bus_count++; + + if (!(params.init = CreateEventW(NULL, FALSE, FALSE, NULL))) + { + ERR("failed to create IOHID bus event.\n"); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + if (!(bus_thread[i] = CreateThread(NULL, 0, bus_main_thread, ¶ms, 0, NULL))) + { + ERR("failed to create IOHID bus thread.\n"); + CloseHandle(params.init); + bus_count--; + return STATUS_UNSUCCESSFUL; + } + + WaitForSingleObject(params.init, INFINITE); + CloseHandle(params.init); + return STATUS_SUCCESS; +} + static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) { static const WCHAR SDL_enabledW[] = {'E','n','a','b','l','e',' ','S','D','L',0}; @@ -775,7 +808,7 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) irp->IoStatus.Status = STATUS_SUCCESS; break; case IRP_MN_REMOVE_DEVICE: - iohid_driver_unload(); + unix_funcs->iohid_bus_stop(); unix_funcs->udev_bus_stop(); unix_funcs->sdl_bus_stop();
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index 8fb280ac7cd..24e42e78aa6 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -35,4 +35,8 @@ extern NTSTATUS WINAPI udev_bus_init(void *args) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI udev_bus_wait(void) DECLSPEC_HIDDEN; extern NTSTATUS WINAPI udev_bus_stop(void) DECLSPEC_HIDDEN;
+extern NTSTATUS WINAPI iohid_bus_init(void *args) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_wait(void) DECLSPEC_HIDDEN; +extern NTSTATUS WINAPI iohid_bus_stop(void) DECLSPEC_HIDDEN; + #endif /* __WINEBUS_UNIX_PRIVATE_H */ diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index cbd29ceecd1..31919e2a53b 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -39,6 +39,9 @@ static const struct unix_funcs unix_funcs = udev_bus_init, udev_bus_wait, udev_bus_stop, + iohid_bus_init, + iohid_bus_wait, + iohid_bus_stop, };
NTSTATUS CDECL __wine_init_unix_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h index cd1bce096c7..df634ad4cc3 100644 --- a/dlls/winebus.sys/unixlib.h +++ b/dlls/winebus.sys/unixlib.h @@ -38,6 +38,10 @@ struct udev_bus_options BOOL disable_input; };
+struct iohid_bus_options +{ +}; + struct unix_funcs { NTSTATUS (WINAPI *sdl_bus_init)(void *); @@ -47,6 +51,10 @@ struct unix_funcs NTSTATUS (WINAPI *udev_bus_init)(void *); NTSTATUS (WINAPI *udev_bus_wait)(void); NTSTATUS (WINAPI *udev_bus_stop)(void); + + NTSTATUS (WINAPI *iohid_bus_init)(void *); + NTSTATUS (WINAPI *iohid_bus_wait)(void); + NTSTATUS (WINAPI *iohid_bus_stop)(void); };
#endif /* __WINEBUS_UNIXLIB_H */