From 43b1acaffb79b3e30245051ff85e29ae14d36600 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Fri, 21 Sep 2012 15:32:22 +0000 Subject: [PATCH 08/21] UsbDeviceManager: Add a redirect-on-connect property Signed-off-by: Hans de Goede Resolves: rhbz#820964 --- gtk/spice-option.c | 9 +++++++++ gtk/usb-device-manager.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/gtk/spice-option.c b/gtk/spice-option.c index 538c2de..56ec795 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; @@ -147,6 +148,8 @@ GOptionGroup* spice_get_option_group(void) NULL, 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_("") }, + { "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_("") }, { "spice-cache-size", '\0', 0, G_OPTION_ARG_INT, &cache_size, N_("Image cache size"), N_("") }, { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size, @@ -215,6 +218,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 -- 1.7.12.1