Re: [PATCH v5 12/13] UsbDeviceWidget: Use asynchronous disconnect API

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

 




On 11 Feb 2016, at 01:28 AM, Jonathon Jongsma <jjongsma@xxxxxxxxxx> wrote:

On Thu, 2015-10-29 at 17:27 +0200, Dmitry Fleytman wrote:
From: Kirill Moizik <kmoizik@xxxxxxxxxx>

Signed-off-by: Kirill Moizik <kmoizik@xxxxxxxxxx>
Signed-off-by: Dmitry Fleytman <dfleytma@xxxxxxxxxx>
---
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 29967d1..b807c83 100644
--- a/src/usb-device-widget.c
+++ b/src/usb-device-widget.c
@@ -437,6 +437,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 = "" class="">+    SpiceUsbDeviceWidget *self = data->self;

This is where we would call _disconnect_device_finish() if such a function
existed.

+    spice_usb_device_widget_update_status(self);
+    g_object_unref(data->check);
+    g_object_unref(data->self);
+    g_free(data);

since there are now two functions sharing the same connect_cb_data, I think it
might make sense to create a static free function for this struct to avoid
potentially leaking parts of the struct by changing code in _disconnect_cb but
not in connect_cb. 

For example:

static void connect_cb_data_free(connect_cb_data *data)
{
}


Good idea! Done.


+}
+
static void connect_cb(GObject *gobject, GAsyncResult *res, gpointer
user_data)
{
    SpiceUsbDeviceManager *manager = SPICE_USB_DEVICE_MANAGER(gobject);
@@ -475,19 +485,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 = "" 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 = "" 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);
}


Reviewed-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://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]