On Mon, Jan 18, 2016 at 10:05:45AM +0100, Fabiano Fidêncio wrote: > Instead of using GSimpleAsyncResult, use the new GTask API, which is > much more straightforward. > --- > src/usb-acl-helper.c | 76 ++++++++++++++++++++++++---------------------------- > 1 file changed, 35 insertions(+), 41 deletions(-) > > diff --git a/src/usb-acl-helper.c b/src/usb-acl-helper.c > index 6a49627..17e2b3c 100644 > --- a/src/usb-acl-helper.c > +++ b/src/usb-acl-helper.c > @@ -35,10 +35,9 @@ > (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SPICE_TYPE_USB_ACL_HELPER, SpiceUsbAclHelperPrivate)) > > struct _SpiceUsbAclHelperPrivate { > - GSimpleAsyncResult *result; > + GTask *task; > GIOChannel *in_ch; > GIOChannel *out_ch; > - GCancellable *cancellable; > gulong cancellable_id; > }; > > @@ -53,11 +52,11 @@ static void spice_usb_acl_helper_cleanup(SpiceUsbAclHelper *self) > { > SpiceUsbAclHelperPrivate *priv = self->priv; > > - g_cancellable_disconnect(priv->cancellable, priv->cancellable_id); > - priv->cancellable = NULL; > + g_cancellable_disconnect(g_task_get_cancellable(priv->task), > + priv->cancellable_id); > priv->cancellable_id = 0; > > - g_clear_object(&priv->result); > + g_clear_object(&priv->task); > > if (priv->in_ch) { > g_io_channel_unref(priv->in_ch); > @@ -90,9 +89,9 @@ static void spice_usb_acl_helper_class_init(SpiceUsbAclHelperClass *klass) > /* ------------------------------------------------------------------ */ > /* callbacks */ > > -static void async_result_set_cancelled(GSimpleAsyncResult *result) > +static void async_result_set_cancelled(GTask *task) > { > - g_simple_async_result_set_error(result, > + g_task_return_new_error(task, > G_IO_ERROR, G_IO_ERROR_CANCELLED, > "Setting USB device node ACL cancelled"); > } > @@ -105,12 +104,13 @@ static gboolean cb_out_watch(GIOChannel *channel, > SpiceUsbAclHelperPrivate *priv = self->priv; > gboolean success = FALSE; > GError *err = NULL; > + GCancellable *cancellable; > GIOStatus status; > gchar *string; > gsize size; > > /* Check that we've not been cancelled */ > - if (priv->result == NULL) > + if (priv->task == NULL) > goto done; > > g_return_val_if_fail(channel == priv->out_ch, FALSE); > @@ -121,10 +121,11 @@ static gboolean cb_out_watch(GIOChannel *channel, > string[strlen(string) - 1] = 0; > if (!strcmp(string, "SUCCESS")) { > success = TRUE; > + g_task_return_boolean(priv->task, TRUE); > } else if (!strcmp(string, "CANCELED")) { > - async_result_set_cancelled(priv->result); > + async_result_set_cancelled(priv->task); > } else { > - g_simple_async_result_set_error(priv->result, > + g_task_return_new_error(priv->task, > SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, > "Error setting USB device node ACL: '%s'", > string); > @@ -132,10 +133,10 @@ static gboolean cb_out_watch(GIOChannel *channel, > g_free(string); > break; > case G_IO_STATUS_ERROR: > - g_simple_async_result_take_error(priv->result, err); > + g_task_return_error(priv->task, err); > break; > case G_IO_STATUS_EOF: > - g_simple_async_result_set_error(priv->result, > + g_task_return_new_error(priv->task, > SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED, > "Unexpected EOF reading from acl helper stdout"); > break; > @@ -143,16 +144,16 @@ static gboolean cb_out_watch(GIOChannel *channel, > return TRUE; /* Wait for more input */ > } > > - g_cancellable_disconnect(priv->cancellable, priv->cancellable_id); > - priv->cancellable = NULL; > + cancellable = g_task_get_cancellable(priv->task); > + g_cancellable_disconnect(cancellable, priv->cancellable_id); > + cancellable = NULL; I forgot to mention in my previous mail that setting cancellable to NULL is probably not needed. Christophe
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel