[Spice-devel,spice-gtk,7/9] usb-device-manager: Windows: spice_usb_device_equal_libdev: compare vid:pid

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

Details

Message ID 1364205690-12784-8-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.
When comparing spice_usb_device with a libusb_device on Windows clients,
use vid:pid instead of bus.address

It seems that a device bus.address may change when WinUSB driver
is being installed.
---
 gtk/usb-device-manager.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Patch hide | download patch | download mbox

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 0a561f1..a1399ee 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1608,6 +1608,7 @@  static void spice_usb_device_unref(SpiceUsbDevice *device)
     }
 }

+#ifndef G_OS_WIN32 /* Linux -- compare bus.addr */
 static gboolean
 spice_usb_device_equal_libdev(SpiceUsbDevice *device,
                               libusb_device  *libdev)
@@ -1624,6 +1625,26 @@  spice_usb_device_equal_libdev(SpiceUsbDevice *device,

     return ((bus1 == bus2) && (addr1 == addr2));
 }
+#else /* Windows -- compare vid:pid of device and libdev */
+static gboolean
+spice_usb_device_equal_libdev(SpiceUsbDevice *device,
+                              libusb_device  *libdev)
+{
+    int vid1, vid2, pid1, pid2;
+
+    if ((device == NULL) || (libdev == NULL))
+        return FALSE;
+
+    vid1 = spice_usb_device_get_vid(device);
+    pid1 = spice_usb_device_get_pid(device);
+
+    if (!spice_usb_device_manager_get_libdev_vid_pid(libdev, &vid2, &pid2)) {
+        return FALSE;
+    }
+
+    return ((vid1 == vid2) && (pid1 == pid2));
+}
+#endif

 /*
  * Caller must libusb_unref_device the libusb_device returned by this function.