[Spice-devel,spice-gtk,4/9] usb-device-manager: find_device: use a match function

Submitted by Uri Lublin on March 25, 2013, 10:01 a.m.

Details

Message ID 1364205690-12784-5-git-send-email-uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin March 25, 2013, 10:01 a.m.
Instead of comparing directly against <bus, address>

In preparation of comparing against vid:pid for Windows clients.
---
 gtk/usb-device-manager.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 4421c48..d58fb72 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -655,9 +655,17 @@  static void spice_usb_device_manager_auto_connect_cb(GObject      *gobject,
     spice_usb_device_unref(device);
 }

+static gboolean
+spice_usb_device_manager_device_match(SpiceUsbDevice *device,
+                                      const int bus, const int address)
+{
+    return (spice_usb_device_get_busnum(device) == bus &&
+            spice_usb_device_get_devaddr(device) == address);
+}
+
 static SpiceUsbDevice*
 spice_usb_device_manager_find_device(SpiceUsbDeviceManager *self,
-                                     guint8 bus, guint8 address)
+                                     const int bus, const int address)
 {
     SpiceUsbDeviceManagerPrivate *priv = self->priv;
     SpiceUsbDevice *curr, *device = NULL;
@@ -665,8 +673,7 @@  spice_usb_device_manager_find_device(SpiceUsbDeviceManager *self,

     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) {
+        if (spice_usb_device_manager_device_match(curr, bus, address)) {
             device = curr;
             break;
         }