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

Submitted by Uri Lublin on July 5, 2012, 8:44 p.m.

Details

Message ID 1341521049-4562-12-git-send-email-uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin July 5, 2012, 8:44 p.m.
And use it in spice_usb_device_manager_remove_dev
---
 gtk/usb-device-manager.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

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);