[Wine-patches] [eterhack 15/23] usbhub.sys: Use function which does not depend on version of libusb for starting device drivers.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пт Июн 5 13:00:15 MSD 2009


---
 dlls/usbhub.sys/usbhub.c |  105 ++++++++++++++++++++--------------------------
 1 files changed, 45 insertions(+), 60 deletions(-)

diff --git a/dlls/usbhub.sys/usbhub.c b/dlls/usbhub.sys/usbhub.c
index 81e5aa8..b94c1cc 100644
--- a/dlls/usbhub.sys/usbhub.c
+++ b/dlls/usbhub.sys/usbhub.c
@@ -1169,9 +1169,47 @@ fail:
     return FALSE;
 }
 
-static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
+static void start_device_drivers( DRIVER_OBJECT *hubdrv )
 {
     static const WCHAR grdkeyW[] = {'G','r','d','K','e','y',0};
+
+    struct DeviceInstance *instance;
+    DRIVER_OBJECT *driver;
+    DEVICE_OBJECT *pdo;
+    NTSTATUS status;
+
+    LIST_FOR_EACH_ENTRY( instance, &Devices, struct DeviceInstance, entry )
+    {
+        if (instance->dev == NULL) continue;
+        /* HACK for grdkey.sys */
+        if (instance->vid == 0xa89 && start_service( grdkeyW ))
+        {
+            status = IoCreateDevice( hubdrv, 0, NULL, 0, 0, FALSE, &pdo );
+            if (status == STATUS_SUCCESS)
+            {
+                while (!(driver = __wine_get_driver_object( grdkeyW )))
+                    Sleep( 100 );
+                status = __wine_add_device( driver, pdo );
+                if (status == STATUS_SUCCESS && pdo->AttachedDevice != NULL)
+                    __wine_start_device( pdo->AttachedDevice );
+            }
+        }
+        if (start_service( instance->service ))
+        {
+            pdo = create_pdo( instance, hubdrv );
+            if (pdo == NULL) continue;
+            while (!(driver = __wine_get_driver_object(
+                    instance->service )))
+                Sleep( 100 );
+            status = __wine_add_device( driver, pdo );
+            if (status == STATUS_SUCCESS && pdo->AttachedDevice != NULL)
+                __wine_start_device( pdo->AttachedDevice );
+        }
+    }
+}
+
+static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
+{
     static const WCHAR usbhub_started_eventW[] = {'_','_','w','i','n','e',
                                                   '_','U','s','b','h','u','b',
                                                   'S','t','a','r','t','e','d',0};
@@ -1186,10 +1224,6 @@ static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
     struct usb_device_descriptor *desc;
 #endif
     struct DeviceInstance *instance;
-    DEVICE_OBJECT *pdo;
-    DRIVER_OBJECT *driver;
-    DRIVER_OBJECT *hubdrv = usbhubdrv;
-    NTSTATUS status;
     HANDLE event;
 
     if (!enum_reg_usb_devices())
@@ -1216,10 +1250,10 @@ static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
             ERR( "failed to get USB device descriptor\n" );
             continue;
         }
+        libusb_ref_device( dev );
         if (libusb_get_device_address( dev ) == 1)
         {
-            libusb_ref_device( dev );
-            create_root_hub_device( desc.idVendor, desc.idProduct, dev, hubdrv );
+            create_root_hub_device( desc.idVendor, desc.idProduct, dev, usbhubdrv );
             continue;
         }
         LIST_FOR_EACH_ENTRY( instance, &Devices, struct DeviceInstance, entry )
@@ -1227,32 +1261,7 @@ static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
             if (instance->dev == NULL && desc.idVendor == instance->vid &&
                 desc.idProduct == instance->pid)
             {
-                /* HACK for grdkey.sys */
-                if (instance->vid == 0xa89 && start_service( grdkeyW ))
-                {
-                    status = IoCreateDevice( hubdrv, 0, NULL, 0, 0, FALSE, &pdo );
-                    if (status != STATUS_SUCCESS) break;
-                    while (!(driver = __wine_get_driver_object( grdkeyW )))
-                        Sleep( 100 );
-                    status = __wine_add_device( driver, pdo );
-                    if (status != STATUS_SUCCESS) break;
-                    if (pdo->AttachedDevice)
-                        __wine_start_device( pdo->AttachedDevice );
-                }
-                if (start_service( instance->service ))
-                {
-                    pdo = create_pdo( instance, hubdrv );
-                    if (pdo == NULL) break;
-                    instance->dev = dev;
-                    libusb_ref_device( dev );
-                    while (!(driver = __wine_get_driver_object(
-                            instance->service )))
-                        Sleep( 100 );
-                    status = __wine_add_device( driver, pdo );
-                    if (status != STATUS_SUCCESS) break;
-                    if (pdo->AttachedDevice)
-                        __wine_start_device( pdo->AttachedDevice );
-                }
+                instance->dev = dev;
                 break;
             }
         }
@@ -1267,7 +1276,7 @@ static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
     {
         desc = &bus->devices->descriptor;
         create_root_hub_device( desc->idVendor, desc->idProduct,
-                bus->devices, hubdrv );
+                bus->devices, usbhubdrv );
     }
     for (bus = usb_busses; bus; bus = bus->next)
         for (dev = bus->devices->next; dev; dev = dev->next)
@@ -1277,36 +1286,12 @@ static DWORD CALLBACK enum_usb_devices( void *usbhubdrv )
                     dev->descriptor.idVendor == instance->vid &&
                     dev->descriptor.idProduct == instance->pid)
                 {
-                    /* HACK for grdkey.sys */
-                    if (instance->vid == 0xa89 && start_service( grdkeyW ))
-                    {
-                        status = IoCreateDevice( hubdrv, 0, NULL, 0, 0, FALSE, &pdo );
-                        if (status != STATUS_SUCCESS) break;
-                        while (!(driver = __wine_get_driver_object( grdkeyW )))
-                            Sleep( 100 );
-                        status = __wine_add_device( driver, pdo );
-                        if (status != STATUS_SUCCESS) break;
-                        if (pdo->AttachedDevice)
-                            __wine_start_device( pdo->AttachedDevice );
-                    }
-                    if (start_service( instance->service ))
-                    {
-                        pdo = create_pdo( instance, hubdrv );
-                        if (pdo == NULL) break;
-                        instance->dev = dev;
-                        while (!(driver = __wine_get_driver_object(
-                                instance->service )))
-                            Sleep( 100 );
-                        status = __wine_add_device( driver, pdo );
-                        if (status != STATUS_SUCCESS) break;
-                        if (pdo->AttachedDevice)
-                            __wine_start_device( pdo->AttachedDevice );
-                    }
+                    instance->dev = dev;
                     break;
                 }
             }
 #endif
-
+    start_device_drivers( usbhubdrv );
 end:
     event = CreateEventW( NULL, TRUE, FALSE, usbhub_started_eventW );
     SetEvent( event );
-- 
1.6.3.1



Подробная информация о списке рассылки Wine-patches