[PATCH spice-gtk 2/2] channel-usbredir: Properly reset state from reset callback

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

 



This is necesary to be able to use the usbredir channel after a
non seamless migration.

Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
---
 gtk/channel-usbredir.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gtk/channel-usbredir.c b/gtk/channel-usbredir.c
index 5f8fb16..d5f8253 100644
--- a/gtk/channel-usbredir.c
+++ b/gtk/channel-usbredir.c
@@ -66,6 +66,7 @@ enum SpiceUsbredirChannelState {
 
 struct _SpiceUsbredirChannelPrivate {
     libusb_device *device;
+    libusb_context *context;
     struct usbredirhost *host;
     /* To catch usbredirhost error messages and report them as a GError */
     GError **catch_error;
@@ -109,9 +110,20 @@ static void spice_usbredir_channel_init(SpiceUsbredirChannel *channel)
 }
 
 #ifdef USE_USBREDIR
-static void spice_usbredir_channel_reset(SpiceChannel *channel, gboolean migrating)
+static void spice_usbredir_channel_reset(SpiceChannel *c, gboolean migrating)
 {
-    SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(channel, migrating);
+    SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(c);
+    SpiceUsbredirChannelPrivate *priv = channel->priv;
+
+    if (priv->host) {
+        if (priv->state == STATE_CONNECTED)
+            spice_usbredir_channel_disconnect_device(channel);
+        usbredirhost_close(priv->host);
+        priv->host = NULL;
+        /* Call set_context the re-create the host */
+        spice_usbredir_channel_set_context(channel, priv->context);
+    }
+    SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(c, migrating);
 }
 #endif
 
@@ -190,6 +202,7 @@ void spice_usbredir_channel_set_context(SpiceUsbredirChannel *channel,
 
     g_return_if_fail(priv->host == NULL);
 
+    priv->context = context;
     priv->host = usbredirhost_open_full(
                                    context, NULL,
                                    usbredir_log,
-- 
1.7.12

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


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