[Spice-commits] 5 commits - gtk/spice-option.c gtk/usb-device-manager.c

Hans de Goede jwrdegoede at kemper.freedesktop.org
Thu Oct 11 00:47:25 PDT 2012


 gtk/spice-option.c       |   20 ++++++--
 gtk/usb-device-manager.c |  117 ++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 120 insertions(+), 17 deletions(-)

New commits:
commit 08dea4ecc88be681504e5bcc52934f1d616f6f99
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Sep 21 15:32:25 2012 +0000

    UsbDeviceManager: Don't warn on EINTR
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 539cefe..3684485 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -915,7 +915,7 @@ static gpointer spice_usb_device_manager_usb_ev_thread(gpointer user_data)
 
     while (priv->event_thread_run) {
         rc = libusb_handle_events(priv->context);
-        if (rc) {
+        if (rc && rc != LIBUSB_ERROR_INTERRUPTED) {
             const char *desc = spice_usbutil_libusb_strerror(rc);
             g_warning("Error handling USB events: %s [%i]", desc, rc);
         }
commit 74c80aa37b27436311eb02451f98186207fa43ff
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Sep 21 15:32:24 2012 +0000

    UsbDeviceManager: Hookup redirect-on-connect property
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index c30e67b..539cefe 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -147,6 +147,8 @@ static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
                                                gpointer         user_data);
 static void spice_usb_device_manager_add_dev(SpiceUsbDeviceManager  *self,
                                              GUdevDevice            *udev);
+static void spice_usb_device_manager_check_redir_on_connect(
+    SpiceUsbDeviceManager *self, SpiceChannel *channel);
 
 static SpiceUsbDeviceInfo *spice_usb_device_new(libusb_device *libdev);
 static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *device);
@@ -611,6 +613,8 @@ static void channel_new(SpiceSession *session, SpiceChannel *channel,
                                            self->priv->context);
         spice_channel_connect(channel);
         g_ptr_array_add(self->priv->channels, channel);
+
+        spice_usb_device_manager_check_redir_on_connect(self, channel);
     }
 }
 
@@ -962,6 +966,49 @@ void spice_usb_device_manager_stop_event_listening(
         priv->event_thread_run = FALSE;
 }
 
+static void spice_usb_device_manager_check_redir_on_connect(
+    SpiceUsbDeviceManager *self, SpiceChannel *channel)
+{
+    SpiceUsbDeviceManagerPrivate *priv = self->priv;
+    GSimpleAsyncResult *result;
+    SpiceUsbDevice *device;
+    libusb_device *libdev;
+    guint i;
+
+    if (priv->redirect_on_connect == NULL)
+        return;
+
+    for (i = 0; i < priv->devices->len; i++) {
+        device = g_ptr_array_index(priv->devices, i);
+
+        if (spice_usb_device_manager_is_device_connected(self, device))
+            continue;
+
+        libdev = spice_usb_device_manager_device_to_libdev(self, device);
+
+        if (usbredirhost_check_device_filter(
+                            priv->redirect_on_connect_rules,
+                            priv->redirect_on_connect_rules_count,
+                            libdev, 0) == 0) {
+            /* Note: re-uses spice_usb_device_manager_connect_device_async's
+               completion handling code! */
+            result = g_simple_async_result_new(G_OBJECT(self),
+                               spice_usb_device_manager_auto_connect_cb,
+                               spice_usb_device_ref(device),
+                               spice_usb_device_manager_connect_device_async);
+            spice_usbredir_channel_connect_device_async(
+                               SPICE_USBREDIR_CHANNEL(channel),
+                               libdev, device, NULL,
+                               spice_usb_device_manager_channel_connect_cb,
+                               result);
+            libusb_unref_device(libdev);
+            return; /* We've taken the channel! */
+        }
+
+        libusb_unref_device(libdev);
+    }
+}
+
 void spice_usb_device_manager_device_error(
     SpiceUsbDeviceManager *self, SpiceUsbDevice *device, GError *err)
 {
commit ae423609ed9838fd4c09a04e260d33bb9b29ff42
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Sep 21 15:32:23 2012 +0000

    UsbDeviceManager: Build channel list after building the device list
    
    This is necessary for redirect-on-connect
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 6a7f10a..c30e67b 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -249,17 +249,6 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
         return FALSE;
     }
 
-    /* Start listening for usb channels connect/disconnect */
-    g_signal_connect(priv->session, "channel-new",
-                     G_CALLBACK(channel_new), self);
-    g_signal_connect(priv->session, "channel-destroy",
-                     G_CALLBACK(channel_destroy), self);
-    list = spice_session_get_channels(priv->session);
-    for (it = g_list_first(list); it != NULL; it = g_list_next(it)) {
-        channel_new(priv->session, it->data, (gpointer*)self);
-    }
-    g_list_free(list);
-
     /* Start listening for usb devices plug / unplug */
     priv->udev = g_udev_client_new(subsystems);
     g_signal_connect(G_OBJECT(priv->udev), "uevent",
@@ -276,6 +265,17 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
     libusb_free_device_list(priv->coldplug_list, 1);
     priv->coldplug_list = NULL;
 
+    /* Start listening for usb channels connect/disconnect */
+    g_signal_connect(priv->session, "channel-new",
+                     G_CALLBACK(channel_new), self);
+    g_signal_connect(priv->session, "channel-destroy",
+                     G_CALLBACK(channel_destroy), self);
+    list = spice_session_get_channels(priv->session);
+    for (it = g_list_first(list); it != NULL; it = g_list_next(it)) {
+        channel_new(priv->session, it->data, (gpointer*)self);
+    }
+    g_list_free(list);
+
     return TRUE;
 #else
     g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
commit f0194e08578c6bce33da57d33b7f23c93aa41b1b
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Sep 21 15:32:22 2012 +0000

    UsbDeviceManager: Add a redirect-on-connect property
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/spice-option.c b/gtk/spice-option.c
index 1333766..85c9e55 100644
--- a/gtk/spice-option.c
+++ b/gtk/spice-option.c
@@ -33,6 +33,7 @@ static char *host_subject = NULL;
 static char *smartcard_db = NULL;
 static char *smartcard_certificates = NULL;
 static char *usbredir_auto_redirect_filter = NULL;
+static char *usbredir_redirect_on_connect = NULL;
 static gboolean smartcard = FALSE;
 static gboolean disable_audio = FALSE;
 static gboolean disable_usbredir = FALSE;
@@ -133,6 +134,8 @@ GOptionGroup* spice_get_option_group(void)
           N_("Disable USB redirection support"), NULL },
         { "spice-usbredir-auto-redirect-filter", '\0', 0, G_OPTION_ARG_STRING, &usbredir_auto_redirect_filter,
           N_("Filter selecting USB devices to be auto-redirected when plugged in"), N_("<filter-string>") },
+        { "spice-usbredir-redirect-on-connect", '\0', 0, G_OPTION_ARG_STRING, &usbredir_redirect_on_connect,
+          N_("Filter selecting USB devices to redirect on connect"), N_("<filter-string>") },
         { "spice-cache-size", '\0', 0, G_OPTION_ARG_INT, &cache_size,
           N_("Image cache size"), N_("<bytes>") },
         { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size,
@@ -201,6 +204,12 @@ void spice_set_session_option(SpiceSession *session)
             g_object_set(m, "auto-connect-filter",
                          usbredir_auto_redirect_filter, NULL);
     }
+    if (usbredir_redirect_on_connect) {
+        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session, NULL);
+        if (m)
+            g_object_set(m, "redirect-on-connect",
+                         usbredir_redirect_on_connect, NULL);
+    }
     if (disable_usbredir)
         g_object_set(session, "enable-usbredir", FALSE, NULL);
     if (disable_audio)
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index c05ede8..6a7f10a 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -81,6 +81,7 @@ enum {
     PROP_SESSION,
     PROP_AUTO_CONNECT,
     PROP_AUTO_CONNECT_FILTER,
+    PROP_REDIRECT_ON_CONNECT,
 };
 
 enum
@@ -96,6 +97,7 @@ struct _SpiceUsbDeviceManagerPrivate {
     SpiceSession *session;
     gboolean auto_connect;
     gchar *auto_connect_filter;
+    gchar *redirect_on_connect;
 #ifdef USE_USBREDIR
     libusb_context *context;
     GUdevClient *udev;
@@ -104,7 +106,9 @@ struct _SpiceUsbDeviceManagerPrivate {
     gboolean event_thread_run;
     libusb_device **coldplug_list; /* Avoid needless reprobing during init */
     struct usbredirfilter_rule *auto_conn_filter_rules;
+    struct usbredirfilter_rule *redirect_on_connect_rules;
     int auto_conn_filter_rules_count;
+    int redirect_on_connect_rules_count;
 #endif
     GPtrArray *devices;
     GPtrArray *channels;
@@ -328,6 +332,9 @@ static void spice_usb_device_manager_get_property(GObject     *gobject,
     case PROP_AUTO_CONNECT_FILTER:
         g_value_set_string(value, priv->auto_connect_filter);
         break;
+    case PROP_REDIRECT_ON_CONNECT:
+        g_value_set_string(value, priv->redirect_on_connect);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -371,6 +378,30 @@ static void spice_usb_device_manager_set_property(GObject       *gobject,
         priv->auto_connect_filter = g_strdup(filter);
         break;
     }
+    case PROP_REDIRECT_ON_CONNECT: {
+        const gchar *filter = g_value_get_string(value);
+#ifdef USE_USBREDIR
+        struct usbredirfilter_rule *rules = NULL;
+        int r = 0, count = 0;
+
+        if (filter)
+            r = usbredirfilter_string_to_rules(filter, ",", "|",
+                                               &rules, &count);
+        if (r) {
+            if (r == -ENOMEM)
+                g_error("Failed to allocate memory for redirect-on-connect");
+            g_warning("Error parsing redirect-on-connect string, keeping old filter\n");
+            break;
+        }
+
+        free(priv->redirect_on_connect_rules);
+        priv->redirect_on_connect_rules = rules;
+        priv->redirect_on_connect_rules_count = count;
+#endif
+        g_free(priv->redirect_on_connect);
+        priv->redirect_on_connect = g_strdup(filter);
+        break;
+    }
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -446,6 +477,21 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
                                     pspec);
 
     /**
+     * SpiceUsbDeviceManager:redirect-on-connect:
+     *
+     * Set a string specifying a filter selecting USB devices to automatically
+     * redirect after a Spice connection has been established.
+     *
+     * See SpiceUsbDeviceManager:auto-connect-filter: for the filter string
+     * format.
+     */
+    pspec = g_param_spec_string("redirect-on-connect", "Redirect on connect",
+               "Filter selecting USB devices to redirect on connect", NULL,
+               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(gobject_class, PROP_REDIRECT_ON_CONNECT,
+                                    pspec);
+
+    /**
      * SpiceUsbDeviceManager::device-added:
      * @manager: the #SpiceUsbDeviceManager that emitted the signal
      * @device: #SpiceUsbDevice boxed object corresponding to the added device
commit cc1e4046d068bcb90c4eeac2598eb774611a35d7
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Sep 21 15:32:21 2012 +0000

    Rename spice-usbredir-filter option to spice-usbredir-auto-redirect-filter
    
    The spice-usbredir-filter cmdline option was not chosen well, as it does
    not indicate what it filters. Now that we are also getting a filter for
    selecting already plugged in devices to redirect when a spice connection gets
    established, it needs to be renamed to make its function more clear.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/gtk/spice-option.c b/gtk/spice-option.c
index 715e84a..1333766 100644
--- a/gtk/spice-option.c
+++ b/gtk/spice-option.c
@@ -32,7 +32,7 @@ static char *ca_file = NULL;
 static char *host_subject = NULL;
 static char *smartcard_db = NULL;
 static char *smartcard_certificates = NULL;
-static char *usbredir_filter = NULL;
+static char *usbredir_auto_redirect_filter = NULL;
 static gboolean smartcard = FALSE;
 static gboolean disable_audio = FALSE;
 static gboolean disable_usbredir = FALSE;
@@ -131,8 +131,8 @@ GOptionGroup* spice_get_option_group(void)
           N_("Path to the local certificate database to use for software smartcard certificates"), N_("<certificate-db>") },
         { "spice-disable-usbredir", '\0', 0, G_OPTION_ARG_NONE, &disable_usbredir,
           N_("Disable USB redirection support"), NULL },
-        { "spice-usbredir-filter", '\0', 0, G_OPTION_ARG_STRING, &usbredir_filter,
-          N_("Filter for excluding USB devices from auto redirection"), N_("<filter-string>") },
+        { "spice-usbredir-auto-redirect-filter", '\0', 0, G_OPTION_ARG_STRING, &usbredir_auto_redirect_filter,
+          N_("Filter selecting USB devices to be auto-redirected when plugged in"), N_("<filter-string>") },
         { "spice-cache-size", '\0', 0, G_OPTION_ARG_INT, &cache_size,
           N_("Image cache size"), N_("<bytes>") },
         { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size,
@@ -195,10 +195,11 @@ void spice_set_session_option(SpiceSession *session)
         if (smartcard_db)
             g_object_set(session, "smartcard-db", smartcard_db, NULL);
     }
-    if (usbredir_filter) {
+    if (usbredir_auto_redirect_filter) {
         SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session, NULL);
         if (m)
-            g_object_set(m, "auto-connect-filter", usbredir_filter, NULL);
+            g_object_set(m, "auto-connect-filter",
+                         usbredir_auto_redirect_filter, NULL);
     }
     if (disable_usbredir)
         g_object_set(session, "enable-usbredir", FALSE, NULL);


More information about the Spice-commits mailing list