[Spice-devel] [PATCH v3 12/13] UsbDeviceWidget: use async disconnect

Kirill Moizik kirill at daynix.com
Mon Aug 3 06:10:52 PDT 2015


From: Kirill Moizik <kmoizik at redhat.com>

---
 src/usb-device-widget.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
index fcafc92..edc1d4d 100644
--- a/src/usb-device-widget.c
+++ b/src/usb-device-widget.c
@@ -438,6 +438,16 @@ typedef struct _connect_cb_data {
     SpiceUsbDeviceWidget *self;
 } connect_cb_data;
 
+static void disconnect_cb(GObject *gobject, GAsyncResult *res, gpointer user_data)
+{
+    connect_cb_data *data = user_data;
+    SpiceUsbDeviceWidget *self = data->self;
+    spice_usb_device_widget_update_status(self);
+    g_object_unref(data->check);
+    g_object_unref(data->self);
+    g_free(data);
+}
+
 static void connect_cb(GObject *gobject, GAsyncResult *res, gpointer user_data)
 {
     SpiceUsbDeviceManager *manager = SPICE_USB_DEVICE_MANAGER(gobject);
@@ -476,19 +486,23 @@ static void checkbox_clicked_cb(GtkWidget *check, gpointer user_data)
     SpiceUsbDevice *device;
 
     device = g_object_get_data(G_OBJECT(check), "usb-device");
+    connect_cb_data *data = g_new(connect_cb_data, 1);
+    data->check = g_object_ref(check);
+    data->self  = g_object_ref(self);
 
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
-        connect_cb_data *data = g_new(connect_cb_data, 1);
-        data->check = g_object_ref(check);
-        data->self  = g_object_ref(self);
         spice_usb_device_manager_connect_device_async(priv->manager,
                                                       device,
                                                       NULL,
                                                       connect_cb,
                                                       data);
     } else {
-        spice_usb_device_manager_disconnect_device(priv->manager,
-                                                   device);
+        spice_usb_device_manager_disconnect_device_async(priv->manager,
+                                                         device,
+                                                         NULL,
+                                                         disconnect_cb,
+                                                         data);
+
     }
     spice_usb_device_widget_update_status(self);
 }
-- 
2.4.3



More information about the Spice-devel mailing list