Commit b4d8cd38 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

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

parent 9d7f1eef
......@@ -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
{
......
......@@ -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;
return STATUS_SUCCESS;
}
NTSTATUS iohid_driver_init(void)
NTSTATUS iohid_bus_wait(void *args)
{
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 iohid_bus_stop(void *args)
{
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 iohid_bus_init(void *args)
{
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
NTSTATUS iohid_bus_wait(void *args)
{
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
void iohid_driver_unload( void )
NTSTATUS iohid_bus_stop(void *args)
{
TRACE("Stub: Unload Driver\n");
WARN("IOHID support not compiled in!\n");
return STATUS_NOT_IMPLEMENTED;
}
#endif /* HAVE_IOHIDMANAGERCREATE */
......@@ -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]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment