[Spice-devel] [PATCH v3 4/7] Add SpiceUsbDeviceManager parameter to device comparison functions

Kirill Moizik kirill at daynix.com
Mon Jun 15 02:57:16 PDT 2015


From: Christophe Fergeau <cfergeau at redhat.com>

This additional parameter is currently unused, but this is in
preparation for the next commits.
---
 src/usb-device-manager.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index ab2a8cd..adee0fc 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -184,8 +184,9 @@ static guint8 spice_usb_device_get_state(SpiceUsbDevice *device);
 static void  spice_usb_device_set_state(SpiceUsbDevice *device, guint8 s);
 #endif
 
-static gboolean spice_usb_device_equal_libdev(SpiceUsbDevice *device,
-                                              libusb_device *libdev);
+static gboolean spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
+                                                      SpiceUsbDevice *device,
+                                                      libusb_device *libdev);
 static libusb_device *
 spice_usb_device_manager_device_to_libdev(SpiceUsbDeviceManager *self,
                                           SpiceUsbDevice *device);
@@ -639,7 +640,8 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
 
 #ifdef USE_GUDEV
 static gboolean spice_usb_device_manager_get_udev_bus_n_address(
-    GUdevDevice *udev, int *bus, int *address)
+    SpiceUsbDeviceManager *manager, GUdevDevice *udev,
+    int *bus, int *address)
 {
     const gchar *bus_str, *address_str;
 
@@ -790,7 +792,7 @@ static void spice_usb_device_manager_auto_connect_cb(GObject      *gobject,
 
 #ifndef G_OS_WIN32 /* match functions for Linux -- match by bus.addr */
 static gboolean
-spice_usb_device_manager_device_match(SpiceUsbDevice *device,
+spice_usb_device_manager_device_match(SpiceUsbDeviceManager *self, SpiceUsbDevice *device,
                                       const int bus, const int address)
 {
     return (spice_usb_device_get_busnum(device) == bus &&
@@ -799,7 +801,7 @@ spice_usb_device_manager_device_match(SpiceUsbDevice *device,
 
 #ifdef USE_GUDEV
 static gboolean
-spice_usb_device_manager_libdev_match(libusb_device *libdev,
+spice_usb_device_manager_libdev_match(SpiceUsbDeviceManager *self, libusb_device *libdev,
                                       const int bus, const int address)
 {
     return (libusb_get_bus_number(libdev) == bus &&
@@ -809,7 +811,7 @@ spice_usb_device_manager_libdev_match(libusb_device *libdev,
 
 #else /* Win32 -- match functions for Windows -- match by vid:pid */
 static gboolean
-spice_usb_device_manager_device_match(SpiceUsbDevice *device,
+spice_usb_device_manager_device_match(SpiceUsbDeviceManager *self, SpiceUsbDevice *device,
                                       const int vid, const int pid)
 {
     return (spice_usb_device_get_vid(device) == vid &&
@@ -817,7 +819,7 @@ spice_usb_device_manager_device_match(SpiceUsbDevice *device,
 }
 
 static gboolean
-spice_usb_device_manager_libdev_match(libusb_device *libdev,
+spice_usb_device_manager_libdev_match(SpiceUsbDeviceManager *self, libusb_device *libdev,
                                       const int vid, const int pid)
 {
     int vid2, pid2;
@@ -839,7 +841,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_manager_device_match(curr, bus, address)) {
+        if (spice_usb_device_manager_device_match(self, curr, bus, address)) {
             device = curr;
             break;
         }
@@ -936,7 +938,7 @@ static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
     if (!devtype || strcmp(devtype, "usb_device"))
         return;
 
-    if (!spice_usb_device_manager_get_udev_bus_n_address(udev, &bus, &address)) {
+    if (!spice_usb_device_manager_get_udev_bus_n_address(self, udev, &bus, &address)) {
         g_warning("USB device without bus number or device address");
         return;
     }
@@ -957,7 +959,7 @@ static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
         libusb_get_device_list(priv->context, &dev_list);
 
     for (i = 0; dev_list && dev_list[i]; i++) {
-        if (spice_usb_device_manager_libdev_match(dev_list[i], bus, address)) {
+        if (spice_usb_device_manager_libdev_match(self, dev_list[i], bus, address)) {
             libdev = dev_list[i];
             break;
         }
@@ -978,7 +980,7 @@ static void spice_usb_device_manager_remove_udev(SpiceUsbDeviceManager  *self,
 {
     int bus, address;
 
-    if (!spice_usb_device_manager_get_udev_bus_n_address(udev, &bus, &address))
+    if (!spice_usb_device_manager_get_udev_bus_n_address(self, udev, &bus, &address))
         return;
 
     spice_usb_device_manager_remove_dev(self, bus, address);
@@ -1281,7 +1283,7 @@ static SpiceUsbredirChannel *spice_usb_device_manager_get_channel_for_dev(
     for (i = 0; i < priv->channels->len; i++) {
         SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
         libusb_device *libdev = spice_usbredir_channel_get_device(channel);
-        if (spice_usb_device_equal_libdev(device, libdev))
+        if (spice_usb_manager_device_equal_libdev(manager, device, libdev))
             return channel;
     }
 #endif
@@ -1822,8 +1824,9 @@ static void spice_usb_device_unref(SpiceUsbDevice *device)
 
 #ifndef G_OS_WIN32 /* Linux -- directly compare libdev */
 static gboolean
-spice_usb_device_equal_libdev(SpiceUsbDevice *device,
-                              libusb_device  *libdev)
+spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
+                                      SpiceUsbDevice *device,
+                                      libusb_device  *libdev)
 {
     SpiceUsbDeviceInfo *info = (SpiceUsbDeviceInfo *)device;
 
@@ -1834,8 +1837,9 @@ spice_usb_device_equal_libdev(SpiceUsbDevice *device,
 }
 #else /* Windows -- compare vid:pid of device and libdev */
 static gboolean
-spice_usb_device_equal_libdev(SpiceUsbDevice *device,
-                              libusb_device  *libdev)
+spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager *manager,
+                                      SpiceUsbDevice *device,
+                                      libusb_device  *libdev)
 {
     int vid, pid;
 
@@ -1844,7 +1848,7 @@ spice_usb_device_equal_libdev(SpiceUsbDevice *device,
 
     vid = spice_usb_device_get_vid(device);
     pid = spice_usb_device_get_pid(device);
-    return spice_usb_device_manager_libdev_match(libdev, vid, pid);
+    return spice_usb_device_manager_libdev_match(manager, libdev, vid, pid);
 }
 #endif
 
@@ -1877,7 +1881,7 @@ spice_usb_device_manager_device_to_libdev(SpiceUsbDeviceManager *self,
         return NULL;
 
     for (i = 0; (d = devlist[i]) != NULL; i++) {
-        if (spice_usb_device_equal_libdev(device, d)) {
+        if (spice_usb_manager_device_equal_libdev(self, device, d)) {
             libusb_ref_device(d);
             break;
         }
-- 
2.1.0



More information about the Spice-devel mailing list