[PATCH 5/5] winebus.sys: Move mouse and keyboard devices to unixlib.c.

Rémi Bernon rbernon at codeweavers.com
Mon Aug 30 04:22:55 CDT 2021


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/winebus.sys/bus.h          |  24 +----
 dlls/winebus.sys/hid.c          |   4 +-
 dlls/winebus.sys/main.c         | 152 ++---------------------------
 dlls/winebus.sys/unix_private.h |  20 ++++
 dlls/winebus.sys/unixlib.c      | 167 ++++++++++++++++++++++++++++++++
 dlls/winebus.sys/unixlib.h      |   7 ++
 6 files changed, 208 insertions(+), 166 deletions(-)

diff --git a/dlls/winebus.sys/bus.h b/dlls/winebus.sys/bus.h
index 6d9090d8603..8f36959d4e1 100644
--- a/dlls/winebus.sys/bus.h
+++ b/dlls/winebus.sys/bus.h
@@ -25,6 +25,8 @@
 #include <ddk/hidclass.h>
 #include <hidusage.h>
 
+#include "unixlib.h"
+
 typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
 
 /* Native device function table */
@@ -56,23 +58,5 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid) DECLSPEC_HIDDEN;
 extern HANDLE driver_key DECLSPEC_HIDDEN;
 extern DEVICE_OBJECT *bus_pdo DECLSPEC_HIDDEN;
 
-struct hid_descriptor
-{
-    BYTE  *data;
-    SIZE_T size;
-    SIZE_T max_size;
-};
-
-extern BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
-extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
-
-extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
-                                       USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
-                                    const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
-
-extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
+extern const platform_vtbl mouse_vtbl DECLSPEC_HIDDEN;
+extern const platform_vtbl keyboard_vtbl DECLSPEC_HIDDEN;
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c
index 1a245031d4d..e4623fab664 100644
--- a/dlls/winebus.sys/hid.c
+++ b/dlls/winebus.sys/hid.c
@@ -27,9 +27,9 @@
 #include "hidusage.h"
 #include "ddk/wdm.h"
 
-#include "bus.h"
+#include "unix_private.h"
 
-BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size)
+static BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size)
 {
     BYTE *tmp = desc->data;
 
diff --git a/dlls/winebus.sys/main.c b/dlls/winebus.sys/main.c
index 20efa3cfb17..a1062bb822d 100644
--- a/dlls/winebus.sys/main.c
+++ b/dlls/winebus.sys/main.c
@@ -95,9 +95,7 @@ static const struct product_desc XBOX_CONTROLLERS[] = {
 static DRIVER_OBJECT *driver_obj;
 
 static DEVICE_OBJECT *mouse_obj;
-static struct hid_descriptor mouse_desc;
 static DEVICE_OBJECT *keyboard_obj;
-static struct hid_descriptor keyboard_desc;
 
 /* The root-enumerated device stack. */
 DEVICE_OBJECT *bus_pdo;
@@ -467,157 +465,23 @@ static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp)
     return status;
 }
 
-static void mouse_free_device(DEVICE_OBJECT *device)
-{
-}
-
-static NTSTATUS mouse_start_device(DEVICE_OBJECT *device)
-{
-    if (!hid_descriptor_begin(&mouse_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE))
-        return STATUS_NO_MEMORY;
-    if (!hid_descriptor_add_buttons(&mouse_desc, HID_USAGE_PAGE_BUTTON, 1, 3))
-        return STATUS_NO_MEMORY;
-    if (!hid_descriptor_end(&mouse_desc))
-        return STATUS_NO_MEMORY;
-
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS mouse_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
-{
-    TRACE("buffer %p, length %u.\n", buffer, length);
-
-    *ret_length = mouse_desc.size;
-    if (length < mouse_desc.size) return STATUS_BUFFER_TOO_SMALL;
-
-    memcpy(buffer, mouse_desc.data, mouse_desc.size);
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS mouse_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
-{
-    static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','m','o','u','s','e',0};
-    if (index != HID_STRING_ID_IPRODUCT)
-        return STATUS_NOT_IMPLEMENTED;
-    if (length < ARRAY_SIZE(nameW))
-        return STATUS_BUFFER_TOO_SMALL;
-    strcpyW(buffer, nameW);
-    return STATUS_SUCCESS;
-}
-
-static void mouse_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
-}
-
-static void mouse_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
-}
-
-static void mouse_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
-}
-
-static const platform_vtbl mouse_vtbl =
-{
-    .free_device = mouse_free_device,
-    .start_device = mouse_start_device,
-    .get_reportdescriptor = mouse_get_reportdescriptor,
-    .get_string = mouse_get_string,
-    .set_output_report = mouse_set_output_report,
-    .get_feature_report = mouse_get_feature_report,
-    .set_feature_report = mouse_set_feature_report,
-};
-
 static void mouse_device_create(void)
 {
     static const WCHAR busidW[] = {'W','I','N','E','M','O','U','S','E',0};
-    mouse_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &mouse_vtbl, 0);
-    IoInvalidateDeviceRelations(bus_pdo, BusRelations);
-}
-
-static void keyboard_free_device(DEVICE_OBJECT *device)
-{
-}
-
-static NTSTATUS keyboard_start_device(DEVICE_OBJECT *device)
-{
-    if (!hid_descriptor_begin(&keyboard_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD))
-        return STATUS_NO_MEMORY;
-    if (!hid_descriptor_add_buttons(&keyboard_desc, HID_USAGE_PAGE_KEYBOARD, 0, 101))
-        return STATUS_NO_MEMORY;
-    if (!hid_descriptor_end(&keyboard_desc))
-        return STATUS_NO_MEMORY;
-
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS keyboard_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
-{
-    TRACE("buffer %p, length %u.\n", buffer, length);
-
-    *ret_length = keyboard_desc.size;
-    if (length < keyboard_desc.size) return STATUS_BUFFER_TOO_SMALL;
-
-    memcpy(buffer, keyboard_desc.data, keyboard_desc.size);
-    return STATUS_SUCCESS;
-}
-
-static NTSTATUS keyboard_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
-{
-    static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','k','e','y','b','o','a','r','d',0};
-    if (index != HID_STRING_ID_IPRODUCT)
-        return STATUS_NOT_IMPLEMENTED;
-    if (length < ARRAY_SIZE(nameW))
-        return STATUS_BUFFER_TOO_SMALL;
-    strcpyW(buffer, nameW);
-    return STATUS_SUCCESS;
-}
-
-static void keyboard_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
-}
-
-static void keyboard_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
-}
+    struct device_create_params params = {0};
 
-static void keyboard_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
-{
-    FIXME("id %u, stub!\n", packet->reportId);
-    io->Information = 0;
-    io->Status = STATUS_NOT_IMPLEMENTED;
+    if (winebus_call(mouse_create, &params)) return;
+    mouse_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &mouse_vtbl, params.device);
+    IoInvalidateDeviceRelations(bus_pdo, BusRelations);
 }
 
-static const platform_vtbl keyboard_vtbl =
-{
-    .free_device = keyboard_free_device,
-    .start_device = keyboard_start_device,
-    .get_reportdescriptor = keyboard_get_reportdescriptor,
-    .get_string = keyboard_get_string,
-    .set_output_report = keyboard_set_output_report,
-    .get_feature_report = keyboard_get_feature_report,
-    .set_feature_report = keyboard_set_feature_report,
-};
-
 static void keyboard_device_create(void)
 {
     static const WCHAR busidW[] = {'W','I','N','E','K','E','Y','B','O','A','R','D',0};
-    keyboard_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &keyboard_vtbl, 0);
+    struct device_create_params params = {0};
+
+    if (winebus_call(keyboard_create, &params)) return;
+    keyboard_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &keyboard_vtbl, params.device);
     IoInvalidateDeviceRelations(bus_pdo, BusRelations);
 }
 
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h
index f3edef83cb7..56194503090 100644
--- a/dlls/winebus.sys/unix_private.h
+++ b/dlls/winebus.sys/unix_private.h
@@ -49,4 +49,24 @@ 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_pop(struct list *queue, struct bus_event *event) DECLSPEC_HIDDEN;
 
+struct hid_descriptor
+{
+    BYTE *data;
+    SIZE_T size;
+    SIZE_T max_size;
+};
+
+extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN;
+extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
+extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
+
+extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
+                                       USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;
+extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
+extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
+extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
+                                    const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
+
+extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
+
 #endif /* __WINEBUS_UNIX_PRIVATE_H */
diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c
index 13e2729e0c2..fdfdcc52dcb 100644
--- a/dlls/winebus.sys/unixlib.c
+++ b/dlls/winebus.sys/unixlib.c
@@ -24,13 +24,178 @@
 #include "windef.h"
 #include "winbase.h"
 #include "winternl.h"
+#include "ddk/hidtypes.h"
 
 #include "wine/debug.h"
 #include "wine/list.h"
 #include "wine/unixlib.h"
 
+#include "bus.h"
 #include "unix_private.h"
 
+WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
+
+static struct hid_descriptor mouse_desc;
+static struct hid_descriptor keyboard_desc;
+
+static void mouse_free_device(DEVICE_OBJECT *device)
+{
+}
+
+static NTSTATUS mouse_start_device(DEVICE_OBJECT *device)
+{
+    if (!hid_descriptor_begin(&mouse_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE))
+        return STATUS_NO_MEMORY;
+    if (!hid_descriptor_add_buttons(&mouse_desc, HID_USAGE_PAGE_BUTTON, 1, 3))
+        return STATUS_NO_MEMORY;
+    if (!hid_descriptor_end(&mouse_desc))
+        return STATUS_NO_MEMORY;
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS mouse_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
+{
+    TRACE("buffer %p, length %u.\n", buffer, length);
+
+    *ret_length = mouse_desc.size;
+    if (length < mouse_desc.size) return STATUS_BUFFER_TOO_SMALL;
+
+    memcpy(buffer, mouse_desc.data, mouse_desc.size);
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS mouse_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
+{
+    static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','m','o','u','s','e',0};
+    if (index != HID_STRING_ID_IPRODUCT)
+        return STATUS_NOT_IMPLEMENTED;
+    if (length < ARRAY_SIZE(nameW))
+        return STATUS_BUFFER_TOO_SMALL;
+    lstrcpyW(buffer, nameW);
+    return STATUS_SUCCESS;
+}
+
+static void mouse_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+static void mouse_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+static void mouse_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+const platform_vtbl mouse_vtbl =
+{
+    .free_device = mouse_free_device,
+    .start_device = mouse_start_device,
+    .get_reportdescriptor = mouse_get_reportdescriptor,
+    .get_string = mouse_get_string,
+    .set_output_report = mouse_set_output_report,
+    .get_feature_report = mouse_get_feature_report,
+    .set_feature_report = mouse_set_feature_report,
+};
+
+static struct unix_device mouse_device;
+
+static NTSTATUS mouse_device_create(void *args)
+{
+    struct device_create_params *params = args;
+    params->device = &mouse_device;
+    return STATUS_SUCCESS;
+}
+
+static void keyboard_free_device(DEVICE_OBJECT *device)
+{
+}
+
+static NTSTATUS keyboard_start_device(DEVICE_OBJECT *device)
+{
+    if (!hid_descriptor_begin(&keyboard_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD))
+        return STATUS_NO_MEMORY;
+    if (!hid_descriptor_add_buttons(&keyboard_desc, HID_USAGE_PAGE_KEYBOARD, 0, 101))
+        return STATUS_NO_MEMORY;
+    if (!hid_descriptor_end(&keyboard_desc))
+        return STATUS_NO_MEMORY;
+
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS keyboard_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
+{
+    TRACE("buffer %p, length %u.\n", buffer, length);
+
+    *ret_length = keyboard_desc.size;
+    if (length < keyboard_desc.size) return STATUS_BUFFER_TOO_SMALL;
+
+    memcpy(buffer, keyboard_desc.data, keyboard_desc.size);
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS keyboard_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
+{
+    static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','k','e','y','b','o','a','r','d',0};
+    if (index != HID_STRING_ID_IPRODUCT)
+        return STATUS_NOT_IMPLEMENTED;
+    if (length < ARRAY_SIZE(nameW))
+        return STATUS_BUFFER_TOO_SMALL;
+    lstrcpyW(buffer, nameW);
+    return STATUS_SUCCESS;
+}
+
+static void keyboard_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+static void keyboard_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+static void keyboard_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
+{
+    FIXME("id %u, stub!\n", packet->reportId);
+    io->Information = 0;
+    io->Status = STATUS_NOT_IMPLEMENTED;
+}
+
+const platform_vtbl keyboard_vtbl =
+{
+    .free_device = keyboard_free_device,
+    .start_device = keyboard_start_device,
+    .get_reportdescriptor = keyboard_get_reportdescriptor,
+    .get_string = keyboard_get_string,
+    .set_output_report = keyboard_set_output_report,
+    .get_feature_report = keyboard_get_feature_report,
+    .set_feature_report = keyboard_set_feature_report,
+};
+
+static struct unix_device keyboard_device;
+
+static NTSTATUS keyboard_device_create(void *args)
+{
+    struct device_create_params *params = args;
+    params->device = &keyboard_device;
+    return STATUS_SUCCESS;
+}
+
 const unixlib_entry_t __wine_unix_call_funcs[] =
 {
     sdl_bus_init,
@@ -42,6 +207,8 @@ const unixlib_entry_t __wine_unix_call_funcs[] =
     iohid_bus_init,
     iohid_bus_wait,
     iohid_bus_stop,
+    mouse_device_create,
+    keyboard_device_create,
 };
 
 void bus_event_queue_destroy(struct list *queue)
diff --git a/dlls/winebus.sys/unixlib.h b/dlls/winebus.sys/unixlib.h
index d9097ba9ca7..d70dedecb2c 100644
--- a/dlls/winebus.sys/unixlib.h
+++ b/dlls/winebus.sys/unixlib.h
@@ -68,6 +68,11 @@ struct bus_event
     };
 };
 
+struct device_create_params
+{
+    struct unix_device *device;
+};
+
 enum unix_funcs
 {
     sdl_init,
@@ -79,6 +84,8 @@ enum unix_funcs
     iohid_init,
     iohid_wait,
     iohid_stop,
+    mouse_create,
+    keyboard_create,
 };
 
 extern const unixlib_entry_t __wine_unix_call_funcs[] DECLSPEC_HIDDEN;
-- 
2.33.0




More information about the wine-devel mailing list