[spice-gtk 07/13] usb-redir: discard cold-plug device list under Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Discard the optimization of initial device enumeration.
Just after connection to 'udev' signal request to report
all the devices  one by one as if they are inserted.
Further commits will remove device enumeration in
usb-dev-manager completely.

Signed-off-by: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>
---
 src/usb-device-manager.c | 19 +++----------------
 src/win-usb-dev.c        | 11 +++++++----
 src/win-usb-dev.h        |  2 +-
 3 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 5cf7ebb..f7b43f0 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -104,7 +104,6 @@ struct _SpiceUsbDeviceManagerPrivate {
     int redirect_on_connect_rules_count;
 #ifdef G_OS_WIN32
     GUdevClient *udev;
-    libusb_device **coldplug_list; /* Avoid needless reprobing during init */
 #else
     gboolean redirecting; /* Handled by GUdevClient in the gudev case */
     libusb_hotplug_callback_handle hp_handle;
@@ -307,15 +306,7 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
     g_signal_connect(G_OBJECT(priv->udev), "uevent",
                      G_CALLBACK(spice_usb_device_manager_uevent_cb), self);
     /* Do coldplug (detection of already connected devices) */
-    libusb_get_device_list(priv->context, &priv->coldplug_list);
-    list = g_udev_client_query_by_subsystem(priv->udev, "usb");
-    for (it = g_list_first(list); it; it = g_list_next(it)) {
-        spice_usb_device_manager_add_udev(self, it->data);
-        g_object_unref(it->data);
-    }
-    g_list_free(list);
-    libusb_free_device_list(priv->coldplug_list, 1);
-    priv->coldplug_list = NULL;
+    g_udev_client_report_devices(priv->udev);
 #else
     rc = libusb_hotplug_register_callback(priv->context,
         LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
@@ -1049,10 +1040,7 @@ static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
         return;
     }
 
-    if (priv->coldplug_list)
-        dev_list = priv->coldplug_list;
-    else
-        libusb_get_device_list(priv->context, &dev_list);
+    libusb_get_device_list(priv->context, &dev_list);
 
     for (i = 0; dev_list && dev_list[i]; i++) {
         if (spice_usb_device_manager_libdev_match(self, dev_list[i], bus, address)) {
@@ -1067,8 +1055,7 @@ static void spice_usb_device_manager_add_udev(SpiceUsbDeviceManager  *self,
         g_warning("Could not find USB device to add " DEV_ID_FMT,
                   (guint) bus, (guint) address);
 
-    if (!priv->coldplug_list)
-        libusb_free_device_list(dev_list, 1);
+    libusb_free_device_list(dev_list, 1);
 }
 
 static void spice_usb_device_manager_remove_udev(SpiceUsbDeviceManager  *self,
diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
index 85ffd26..2c122cf 100644
--- a/src/win-usb-dev.c
+++ b/src/win-usb-dev.c
@@ -247,11 +247,14 @@ static void g_udev_client_initable_iface_init(GInitableIface *iface)
     iface->init = g_udev_client_initable_init;
 }
 
-GList *g_udev_client_query_by_subsystem(GUdevClient *self, const gchar *subsystem)
+static void report_one_device(gpointer data, gpointer self)
 {
-    GList *l = g_list_copy(self->priv->udev_list);
-    g_list_foreach(l, (GFunc)g_object_ref, NULL);
-    return l;
+    g_signal_emit(self, signals[UEVENT_SIGNAL], 0, "add", data);
+}
+
+void g_udev_client_report_devices(GUdevClient *self)
+{
+    g_list_foreach(self->priv->udev_list, report_one_device, self);
 }
 
 static void g_udev_client_init(GUdevClient *self)
diff --git a/src/win-usb-dev.h b/src/win-usb-dev.h
index b7b7eda..bca8285 100644
--- a/src/win-usb-dev.h
+++ b/src/win-usb-dev.h
@@ -81,7 +81,7 @@ struct _GUdevClientClass
 GType g_udev_client_get_type(void) G_GNUC_CONST;
 GUdevClient *g_udev_client_new(void);
 libusb_context *g_udev_client_get_context(GUdevClient *client);
-GList *g_udev_client_query_by_subsystem(GUdevClient *client, const gchar *subsystem);
+void g_udev_client_report_devices(GUdevClient *client);
 
 GType g_udev_device_get_type(void) G_GNUC_CONST;
 const gchar *g_udev_device_get_property(GUdevDevice *udev, const gchar *property);
-- 
2.17.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]