summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Moizik <kmoizik@redhat.com>2016-03-08 16:05:57 +0200
committerJonathon Jongsma <jjongsma@redhat.com>2016-03-24 11:00:02 -0500
commit9fbf679453d8dbfe797a738cb536136599d7adab (patch)
treefddd9fb4b04561bdbe88775b8c5975d5de0254ef
parent4214e76d2c8cf5f321ae95a1f49d49efe7e10fa3 (diff)
usbredir: Disconnect USB device asynchronously
Signed-off-by: Kirill Moizik <kmoizik@redhat.com> Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
-rw-r--r--src/channel-usbredir.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 3803f77..a251855 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -115,20 +115,54 @@ static void spice_usbredir_channel_init(SpiceUsbredirChannel *channel)
}
#ifdef USE_USBREDIR
+
+static void _channel_reset_finish(SpiceUsbredirChannel *channel)
+{
+ SpiceUsbredirChannelPrivate *priv = channel->priv;
+
+ spice_usbredir_channel_lock(channel);
+
+ usbredirhost_close(priv->host);
+ priv->host = NULL;
+
+ /* Call set_context to re-create the host */
+ spice_usbredir_channel_set_context(channel, priv->context);
+
+ spice_usbredir_channel_unlock(channel);
+}
+
+static void _channel_reset_cb(GObject *gobject,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ SpiceChannel *spice_channel = SPICE_CHANNEL(gobject);
+ SpiceUsbredirChannel *channel = SPICE_USBREDIR_CHANNEL(spice_channel);
+ gboolean migrating = GPOINTER_TO_UINT(user_data);
+ GError *err = NULL;
+
+ _channel_reset_finish(channel);
+
+ SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(spice_channel, migrating);
+
+ spice_usbredir_channel_disconnect_device_finish(channel, result, &err);
+ g_object_unref(result);
+}
+
static void spice_usbredir_channel_reset(SpiceChannel *c, gboolean 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 to re-create the host */
- spice_usbredir_channel_set_context(channel, priv->context);
+ if (priv->state == STATE_CONNECTED) {
+ spice_usbredir_channel_disconnect_device_async(channel, NULL,
+ _channel_reset_cb, GUINT_TO_POINTER(migrating));
+ } else {
+ _channel_reset_finish(channel);
+ }
+ } else {
+ SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(c, migrating);
}
- SPICE_CHANNEL_CLASS(spice_usbredir_channel_parent_class)->channel_reset(c, migrating);
}
#endif