winebus.sys: Create the IOHID bus thread in main.c.

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-08-23 10:49:38 +02:00 committed by Alexandre Julliard
parent 9d7f1eefa1
commit b4d8cd3891
3 changed files with 49 additions and 38 deletions

View File

@ -28,9 +28,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;
extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_stop(void *) DECLSPEC_HIDDEN;
@ -39,6 +36,10 @@ extern NTSTATUS udev_bus_init(void *) DECLSPEC_HIDDEN;
extern NTSTATUS udev_bus_wait(void *) DECLSPEC_HIDDEN;
extern NTSTATUS udev_bus_stop(void *) DECLSPEC_HIDDEN;
extern NTSTATUS iohid_bus_init(void *) DECLSPEC_HIDDEN;
extern NTSTATUS iohid_bus_wait(void *) DECLSPEC_HIDDEN;
extern NTSTATUS iohid_bus_stop(void *) DECLSPEC_HIDDEN;
/* Native device function table */
typedef struct
{

View File

@ -96,7 +96,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
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 +384,61 @@ 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 iohid_bus_init(void *args)
{
if (!(hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L)))
{
ERR("IOHID manager creation failed\n");
return STATUS_UNSUCCESSFUL;
}
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;
}
NTSTATUS iohid_driver_init(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;
}
TRACE("Initialization successful\n");
return STATUS_SUCCESS;
}
void iohid_driver_unload( void )
NTSTATUS iohid_bus_wait(void *args)
{
TRACE("Unloading Driver\n");
CFRunLoopRun();
if (!run_loop_handle)
return;
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRunLoopStop(run_loop);
WaitForSingleObject(run_loop_handle, INFINITE);
CloseHandle(run_loop_handle);
TRACE("IOHID main loop exiting\n");
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
CFRelease(hid_manager);
TRACE("Driver Unloaded\n");
return STATUS_SUCCESS;
}
NTSTATUS iohid_bus_stop(void *args)
{
if (!run_loop) return STATUS_SUCCESS;
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRunLoopStop(run_loop);
return STATUS_SUCCESS;
}
#else
NTSTATUS iohid_driver_init(void)
NTSTATUS iohid_bus_init(void *args)
{
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
void iohid_driver_unload( void )
NTSTATUS iohid_bus_wait(void *args)
{
TRACE("Stub: Unload Driver\n");
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS iohid_bus_stop(void *args)
{
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
#endif /* HAVE_IOHIDMANAGERCREATE */

View File

@ -699,6 +699,19 @@ static NTSTATUS udev_driver_init(void)
return bus_main_thread_start(&bus);
}
static NTSTATUS iohid_driver_init(void)
{
static const WCHAR bus_name[] = {'I','O','H','I','D'};
struct bus_main_params bus =
{
.name = bus_name,
.init_func = iohid_bus_init,
.wait_func = iohid_bus_wait,
};
return bus_main_thread_start(&bus);
}
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};
@ -727,9 +740,9 @@ static NTSTATUS fdo_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
irp->IoStatus.Status = STATUS_SUCCESS;
break;
case IRP_MN_REMOVE_DEVICE:
iohid_driver_unload();
sdl_bus_stop(NULL);
udev_bus_stop(NULL);
iohid_bus_stop(NULL);
WaitForMultipleObjects(bus_count, bus_thread, TRUE, INFINITE);
while (bus_count--) CloseHandle(bus_thread[bus_count]);