[Wine-patches] wineusb: Do not call AddDevice some times for one device.

Alexander Morozov =?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Окт 13 16:34:30 MSD 2008


----------- следующая часть -----------
From 553cfae7febf26230c8d9c5ba5a256b93922f11b Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Mon, 13 Oct 2008 15:20:40 +0400
Subject: [PATCH] wineusb: Do not call AddDevice some times for one device.

---
 programs/wineusb/main.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/programs/wineusb/main.c b/programs/wineusb/main.c
index 1aa80ee..24d0690 100644
--- a/programs/wineusb/main.c
+++ b/programs/wineusb/main.c
@@ -42,6 +42,7 @@
 #include "wine/unicode.h"
 #include "wine/server.h"
 #include "wine/debug.h"
+#include "wine/list.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(wineusb);
 
@@ -49,6 +50,15 @@ static WCHAR service_nameW[] = {'w','i','n','e','u','s','b',0};
 static SERVICE_STATUS_HANDLE service_handle;
 static HANDLE stop_event;
 
+/* List of devices for which AddDevice was called */
+static struct list Devices = LIST_INIT(Devices);
+
+struct DeviceInstance
+{
+    struct list entry;
+    struct usb_device *dev;
+};
+
 static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
 {
     SERVICE_STATUS status;
@@ -106,6 +116,7 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
     set = SetupDiGetClassDevsW( NULL, usb, 0, DIGCF_ALLCLASSES );
     if (set != INVALID_HANDLE_VALUE)
     {
+        struct DeviceInstance *instance, *instance2;
         UNICODE_STRING drvname;
         UCHAR pdo_info[2 * PATH_MAX + 3] = {0};
         struct usb_device *dev;
@@ -161,6 +172,28 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
                     if (dev->descriptor.idVendor == vid &&
                             dev->descriptor.idProduct == pid)
                     {
+                        int found = 0;
+
+                        LIST_FOR_EACH_ENTRY( instance, &Devices,
+                                struct DeviceInstance, entry )
+                        {
+                            if (instance->dev == dev)
+                            {
+                                found = 1;
+                                break;
+                            }
+                        }
+                        if (found)
+                            continue;
+
+                        instance = HeapAlloc( GetProcessHeap(), 0, sizeof(*instance) );
+                        if (instance == NULL)
+                        {
+                            WINE_ERR( "insufficient memory\n" );
+                            ret = FALSE;
+                            break;
+                        }
+
                         SetupDiGetDeviceRegistryPropertyW( set, &devInfo,
                                 SPDRP_SERVICE, NULL, NULL, 0, &size );
                         buf = HeapAlloc( GetProcessHeap(), 0, size );
@@ -192,6 +225,9 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
                         }
                         SERVER_END_REQ;
 
+                        instance->dev = dev;
+                        list_add_tail( &Devices, &instance->entry );
+
                         ++pdo_info[0];
                         HeapFree( GetProcessHeap(), 0, buf );
                         ret = FALSE;
@@ -199,6 +235,13 @@ static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
                     }
         }
         SetupDiDestroyDeviceInfoList( set );
+
+        LIST_FOR_EACH_ENTRY_SAFE( instance, instance2, &Devices,
+                struct DeviceInstance, entry )
+        {
+            list_remove( &instance->entry );
+            HeapFree( GetProcessHeap(), 0, instance );
+        }
     }
     else
         WINE_ERR( "SetupDiGetClassDevsW failed\n" );
-- 
1.5.6.5.GIT



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