[Spice-devel] [spice-gtk Win32 v4 11/17] usb-device-manager: add a helper function to find a usb device <bus, addr>

Uri Lublin uril at redhat.com
Thu Jul 5 13:44:03 PDT 2012


And use it in spice_usb_device_manager_remove_dev
---
 gtk/usb-device-manager.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index d9ed8a7..3fec521 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -582,6 +582,25 @@ static void spice_usb_device_manager_auto_connect_cb(GObject      *gobject,
     spice_usb_device_unref(device);
 }

+static SpiceUsbDevice*
+spice_usb_device_manager_find_device(SpiceUsbDeviceManager *self,
+                                     guint8 bus, guint8 address)
+{
+    SpiceUsbDeviceManagerPrivate *priv = self->priv;
+    SpiceUsbDevice *curr, *device = NULL;
+    guint i;
+
+    for (i = 0; i < priv->devices->len; i++) {
+        curr = g_ptr_array_index(priv->devices, i);
+        if (spice_usb_device_get_busnum(curr) == bus &&
+               spice_usb_device_get_devaddr(curr) == address) {
+            device = curr;
+            break;
+        }
+    }
+    return device;
+}
+
 static void spice_usb_device_manager_add_dev(SpiceUsbDeviceManager  *self,
                                              GUdevDevice            *udev)
 {
@@ -661,22 +680,13 @@ static void spice_usb_device_manager_remove_dev(SpiceUsbDeviceManager  *self,
                                                 GUdevDevice            *udev)
 {
     SpiceUsbDeviceManagerPrivate *priv = self->priv;
-    SpiceUsbDevice *curr, *device = NULL;
+    SpiceUsbDevice *device = NULL;
     int bus, address;
-    guint i;

     if (!spice_usb_device_manager_get_udev_bus_n_address(udev, &bus, &address))
         return;

-    for (i = 0; i < priv->devices->len; i++) {
-        curr = g_ptr_array_index(priv->devices, i);
-        if (spice_usb_device_get_busnum(curr) == bus &&
-               spice_usb_device_get_devaddr(curr) == address) {
-            device = curr;
-            break;
-        }
-    }
-
+    device = spice_usb_device_manager_find_device(self, bus, address);
     if (!device) {
         g_warning("Could not find USB device to remove at busnum %d devaddr %d",
                   bus, address);
-- 
1.7.7.6



More information about the Spice-devel mailing list