Re: [libvirt-glib v4] gobject: Port to GTask API

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

 



On Tue, Nov 24, 2015 at 4:23 PM, Zeeshan Ali (Khattak)
<zeeshanak@xxxxxxxxx> wrote:
> Drop usage of deprecated GSimpleAsyncResult API.
> ---

This version ensures that async result is returned from the main
thread in gvir_stream_close_async().

>  libvirt-gobject/libvirt-gobject-domain.c        | 290 +++++++++---------------
>  libvirt-gobject/libvirt-gobject-input-stream.c  |  77 +++----
>  libvirt-gobject/libvirt-gobject-output-stream.c |  75 +++---
>  libvirt-gobject/libvirt-gobject-storage-pool.c  | 281 ++++++++++-------------
>  libvirt-gobject/libvirt-gobject-stream.c        |  53 +++--
>  5 files changed, 322 insertions(+), 454 deletions(-)
>
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index 5509ce3..c768cd3 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom,
>      return TRUE;
>  }
>
> -typedef struct {
> -    guint flags;
> -} DomainStartData;
> -
> -static void domain_start_data_free(DomainStartData *data)
> -{
> -    g_slice_free(DomainStartData, data);
> -}
> -
>  static void
> -gvir_domain_start_helper(GSimpleAsyncResult *res,
> -                         GObject *object,
> +gvir_domain_start_helper(GTask *task,
> +                         gpointer source_object,
> +                         gpointer task_data,
>                           GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> -    DomainStartData *data;
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
> +    guint flags = GPOINTER_TO_UINT(task_data);
>      GError *err = NULL;
>
> -    data = g_simple_async_result_get_op_res_gpointer(res);
> -
> -    if (!gvir_domain_start(dom, data->flags, &err))
> -        g_simple_async_result_take_error(res, err);
> +    if (!gvir_domain_start(dom, flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom,
>                               GAsyncReadyCallback callback,
>                               gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> -    DomainStartData *data;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    data = g_slice_new0(DomainStartData);
> -    data->flags = flags;
> -
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_start_async);
> -    g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_start_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
> +    g_task_run_in_thread(task, gvir_domain_start_helper);
> +    g_object_unref(task);
>  }
>
>  gboolean gvir_domain_start_finish(GVirDomain *dom,
> @@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom,
>                                    GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom,
>  }
>
>  static void
> -gvir_domain_resume_helper(GSimpleAsyncResult *res,
> -                          GObject *object,
> +gvir_domain_resume_helper(GTask *task,
> +                          gpointer source_object,
> +                          gpointer task_data G_GNUC_UNUSED,
>                            GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
>      GError *err = NULL;
>
>      if (!gvir_domain_resume(dom, &err))
> -        g_simple_async_result_take_error(res, err);
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -497,20 +482,17 @@ void gvir_domain_resume_async(GVirDomain *dom,
>                                GAsyncReadyCallback callback,
>                                gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_resume_async);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_resume_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_run_in_thread(task, gvir_domain_resume_helper);
> +    g_object_unref(task);
>  }
>
>  gboolean gvir_domain_resume_finish(GVirDomain *dom,
> @@ -518,13 +500,10 @@ gboolean gvir_domain_resume_finish(GVirDomain *dom,
>                                     GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_resume_async), FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -556,15 +535,19 @@ gboolean gvir_domain_wakeup(GVirDomain *dom,
>  }
>
>  static void
> -gvir_domain_wakeup_helper(GSimpleAsyncResult *res,
> -                          GObject *object,
> +gvir_domain_wakeup_helper(GTask *task,
> +                          gpointer source_object,
> +                          gpointer task_data,
>                            GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
> +    guint flags = GPOINTER_TO_UINT(task_data);
>      GError *err = NULL;
>
> -    if (!gvir_domain_wakeup(dom, (guint)g_simple_async_result_get_op_res_gssize(res), &err))
> -        g_simple_async_result_take_error(res, err);
> +    if (!gvir_domain_wakeup(dom, flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -583,21 +566,18 @@ void gvir_domain_wakeup_async(GVirDomain *dom,
>                                GAsyncReadyCallback callback,
>                                gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_wakeup_async);
> -    g_simple_async_result_set_op_res_gssize (res, (gssize)flags);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_wakeup_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
> +    g_task_run_in_thread(task, gvir_domain_wakeup_helper);
> +    g_object_unref(task);
>  }
>
>  gboolean gvir_domain_wakeup_finish(GVirDomain *dom,
> @@ -605,13 +585,10 @@ gboolean gvir_domain_wakeup_finish(GVirDomain *dom,
>                                     GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_wakeup_async), FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -785,18 +762,19 @@ static void domain_save_to_file_data_free(DomainSaveToFileData *data)
>  }
>
>  static void
> -gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
> -                                GObject *object,
> +gvir_domain_save_to_file_helper(GTask *task,
> +                                gpointer source_object,
> +                                gpointer task_data,
>                                  GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> -    DomainSaveToFileData *data;
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
> +    DomainSaveToFileData *data = (DomainSaveToFileData *) task_data;
>      GError *err = NULL;
>
> -    data = g_simple_async_result_get_op_res_gpointer(res);
> -
>      if (!gvir_domain_save_to_file(dom, data->filename, data->custom_conf, data->flags, &err))
> -        g_simple_async_result_take_error(res, err);
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -819,7 +797,7 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
>                                      GAsyncReadyCallback callback,
>                                      gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>      DomainSaveToFileData *data;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
> @@ -832,19 +810,15 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
>          data->custom_conf = g_object_ref(custom_conf);
>      data->flags = flags;
>
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_save_to_file_async);
> -    g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify)
> -                                              domain_save_to_file_data_free);
> -
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_save_to_file_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task,
> +                         data,
> +                         (GDestroyNotify) domain_save_to_file_data_free);
> +    g_task_run_in_thread(task, gvir_domain_save_to_file_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -862,16 +836,10 @@ gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
>                                           GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid
> -                                  (result,
> -                                   G_OBJECT(dom),
> -                                   gvir_domain_save_to_file_async), FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -1012,22 +980,22 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
>  }
>
>  static void
> -gvir_domain_get_info_helper(GSimpleAsyncResult *res,
> -                            GObject *object,
> +gvir_domain_get_info_helper(GTask *task,
> +                            gpointer source_object,
> +                            gpointer task_data G_GNUC_UNUSED,
>                              GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
>      GVirDomainInfo *info;
>      GError *err = NULL;
>
>      info = gvir_domain_get_info(dom, &err);
>      if (err)
> -        g_simple_async_result_take_error(res, err);
> +        g_task_return_error(task, err);
>      else
> -        g_simple_async_result_set_op_res_gpointer
> -                                (res,
> -                                 info,
> -                                 (GDestroyNotify) gvir_domain_info_free);
> +        g_task_return_pointer(task,
> +                              info,
> +                              (GDestroyNotify) gvir_domain_info_free);
>  }
>
>  /**
> @@ -1044,20 +1012,17 @@ void gvir_domain_get_info_async(GVirDomain *dom,
>                                  GAsyncReadyCallback callback,
>                                  gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_get_info_async);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_get_info_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_run_in_thread(task, gvir_domain_get_info_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -1075,22 +1040,11 @@ GVirDomainInfo *gvir_domain_get_info_finish(GVirDomain *dom,
>                                              GAsyncResult *result,
>                                              GError **err)
>  {
> -    GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT(result);
> -    GVirDomainInfo *ret;
> -
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
> -    g_return_val_if_fail
> -                (g_simple_async_result_is_valid(result,
> -                                                G_OBJECT(dom),
> -                                                gvir_domain_get_info_async),
> -                 NULL);
> -
> -    if (g_simple_async_result_propagate_error(res, err))
> -        return NULL;
> -
> -    ret = g_simple_async_result_get_op_res_gpointer(res);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), NULL);
> +    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
>
> -    return gvir_domain_info_copy (ret);
> +    return g_task_propagate_pointer(G_TASK(result), err);
>  }
>
>  /**
> @@ -1365,28 +1319,20 @@ gboolean gvir_domain_save (GVirDomain *dom,
>      return TRUE;
>  }
>
> -typedef struct {
> -    guint flags;
> -} DomainSaveData;
> -
> -static void domain_save_data_free(DomainSaveData *data)
> -{
> -    g_slice_free (DomainSaveData, data);
> -}
> -
>  static void
> -gvir_domain_save_helper(GSimpleAsyncResult *res,
> -                        GObject *object,
> +gvir_domain_save_helper(GTask *task,
> +                        gpointer source_object,
> +                        gpointer task_data,
>                          GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirDomain *dom = GVIR_DOMAIN(object);
> -    DomainSaveData *data;
> +    GVirDomain *dom = GVIR_DOMAIN(source_object);
> +    guint flags = GPOINTER_TO_UINT(task_data);
>      GError *err = NULL;
>
> -    data = g_simple_async_result_get_op_res_gpointer (res);
> -
> -    if (!gvir_domain_save(dom, data->flags, &err))
> -        g_simple_async_result_take_error(res, err);
> +    if (!gvir_domain_save(dom, flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -1405,25 +1351,18 @@ void gvir_domain_save_async (GVirDomain *dom,
>                               GAsyncReadyCallback callback,
>                               gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> -    DomainSaveData *data;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_DOMAIN(dom));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    data = g_slice_new0(DomainSaveData);
> -    data->flags = flags;
> -
> -    res = g_simple_async_result_new(G_OBJECT(dom),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_domain_save_async);
> -    g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) domain_save_data_free);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_domain_save_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(dom),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
> +    g_task_run_in_thread(task, gvir_domain_save_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -1441,15 +1380,10 @@ gboolean gvir_domain_save_finish (GVirDomain *dom,
>                                    GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom),
> -                                                        gvir_domain_save_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -1682,6 +1616,7 @@ GVirDomainSnapshot *gvir_domain_create_snapshot_finish(GVirDomain  *domain,
>                                                         GError **error)
>  {
>      g_return_val_if_fail(g_task_is_valid(result, domain), NULL);
> +    g_return_val_if_fail(error == NULL || *error == NULL, NULL);
>
>      return g_task_propagate_pointer(G_TASK(result), error);
>  }
> @@ -1847,6 +1782,7 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain *dom,
>  {
>      g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
>      g_return_val_if_fail(g_task_is_valid(res, dom), FALSE);
> +    g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
>
>      return g_task_propagate_boolean(G_TASK(res), error);
>  }
> diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c
> index ff1a70c..cd107e1 100644
> --- a/libvirt-gobject/libvirt-gobject-input-stream.c
> +++ b/libvirt-gobject/libvirt-gobject-input-stream.c
> @@ -45,8 +45,7 @@ struct _GVirInputStreamPrivate
>      GVirStream *stream;
>
>      /* pending operation metadata */
> -    GSimpleAsyncResult *result;
> -    GCancellable *cancellable;
> +    GTask *task;
>      gpointer buffer;
>      gsize count;
>  };
> @@ -103,48 +102,44 @@ gvir_input_stream_read_ready(GVirStream *stream,
>  {
>      GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque);
>      GVirInputStreamPrivate *priv = input_stream->priv;
> -    GSimpleAsyncResult *simple = priv->result;
> +    GTask *task = priv->task;
> +    GCancellable *cancellable = g_task_get_cancellable(task);
>      GError *error = NULL;
>      gssize result;
>
> +    priv->task = NULL;
> +
>      if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) {
>          g_warn_if_reached();
> -        g_simple_async_result_set_error(simple,
> -                                        G_IO_ERROR,
> -                                        G_IO_ERROR_INVALID_ARGUMENT,
> -                                        "%s",
> -                                        "Expected stream to be readable");
> +        g_task_return_new_error(task,
> +                                G_IO_ERROR,
> +                                G_IO_ERROR_INVALID_ARGUMENT,
> +                                "%s",
> +                                "Expected stream to be readable");
>          goto cleanup;
>      }
>
> -    result  = gvir_stream_receive(stream, priv->buffer, priv->count,
> -                                  priv->cancellable, &error);
> +    result = gvir_stream_receive(stream, priv->buffer, priv->count,
> +                                 cancellable, &error);
> +    if (error != NULL) {
> +        if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
> +            g_warn_if_reached();
> +            g_task_return_new_error(task,
> +                                    G_IO_ERROR,
> +                                    G_IO_ERROR_INVALID_ARGUMENT,
> +                                    "%s",
> +                                    "Expected stream to be readable");
> +        } else {
> +            g_task_return_error(task, error);
> +        }
>
> -    if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
> -        g_warn_if_reached();
> -        g_simple_async_result_set_error(simple,
> -                                        G_IO_ERROR,
> -                                        G_IO_ERROR_INVALID_ARGUMENT,
> -                                        "%s",
> -                                        "Expected stream to be readable");
>          goto cleanup;
>      }
>
> -    if (result >= 0)
> -        g_simple_async_result_set_op_res_gssize(simple, result);
> -
> -    if (error)
> -        g_simple_async_result_take_error(simple, error);
> -
> -    if (priv->cancellable) {
> -        g_object_unref(priv->cancellable);
> -        priv->cancellable = NULL;
> -    }
> +    g_task_return_int(task, result);
>
>  cleanup:
> -    priv->result = NULL;
> -    g_simple_async_result_complete(simple);
> -    g_object_unref(simple);
> +    g_object_unref(task);
>      return FALSE;
>  }
>
> @@ -159,7 +154,7 @@ static void gvir_input_stream_read_async(GInputStream *stream,
>      GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream);
>
>      g_return_if_fail(GVIR_IS_INPUT_STREAM(stream));
> -    g_return_if_fail(input_stream->priv->result == NULL);
> +    g_return_if_fail(input_stream->priv->task == NULL);
>
>      gvir_stream_add_watch_full(input_stream->priv->stream,
>                                 G_PRIORITY_DEFAULT,
> @@ -168,12 +163,8 @@ static void gvir_input_stream_read_async(GInputStream *stream,
>                                 g_object_ref(stream),
>                                 (GDestroyNotify)g_object_unref);
>
> -    input_stream->priv->result =
> -        g_simple_async_result_new(G_OBJECT(stream), callback, user_data,
> -                                  gvir_input_stream_read_async);
> -    if (cancellable)
> -        g_object_ref(cancellable);
> -    input_stream->priv->cancellable = cancellable;
> +    input_stream->priv->task =
> +        g_task_new(stream, cancellable, callback, user_data);
>      input_stream->priv->buffer = buffer;
>      input_stream->priv->count = count;
>  }
> @@ -181,22 +172,18 @@ static void gvir_input_stream_read_async(GInputStream *stream,
>
>  static gssize gvir_input_stream_read_finish(GInputStream *stream,
>                                              GAsyncResult *result,
> -                                            GError **error G_GNUC_UNUSED)
> +                                            GError **error)
>  {
>      GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream);
> -    GSimpleAsyncResult *simple;
>      virStreamPtr handle;
>      gssize count;
>
>      g_return_val_if_fail(GVIR_IS_INPUT_STREAM(stream), -1);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream),
> -                                                        gvir_input_stream_read_async),
> -                         -1);
> +    g_return_val_if_fail(g_task_is_valid(result, stream), -1);
> +    g_return_val_if_fail(error == NULL || *error == NULL, -1);
>      g_object_get(input_stream->priv->stream, "handle", &handle, NULL);
>
> -    simple = G_SIMPLE_ASYNC_RESULT(result);
> -
> -    count = g_simple_async_result_get_op_res_gssize(simple);
> +    count = g_task_propagate_int(G_TASK(result), error);
>
>      virStreamFree(handle);
>
> diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c
> index f39328b..a9c1236 100644
> --- a/libvirt-gobject/libvirt-gobject-output-stream.c
> +++ b/libvirt-gobject/libvirt-gobject-output-stream.c
> @@ -45,8 +45,7 @@ struct _GVirOutputStreamPrivate
>      GVirStream *stream;
>
>      /* pending operation metadata */
> -    GSimpleAsyncResult *result;
> -    GCancellable *cancellable;
> +    GTask *task;
>      const void * buffer;
>      gsize count;
>  };
> @@ -103,48 +102,44 @@ gvir_output_stream_write_ready(GVirStream *stream,
>  {
>      GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(opaque);
>      GVirOutputStreamPrivate *priv = output_stream->priv;
> -    GSimpleAsyncResult *simple = priv->result;
> +    GTask *task = priv->task;
> +    GCancellable *cancellable = g_task_get_cancellable(task);
>      GError *error = NULL;
>      gssize result;
>
>      if (!(cond & GVIR_STREAM_IO_CONDITION_WRITABLE)) {
>          g_warn_if_reached();
> -        g_simple_async_result_set_error(simple,
> -                                        G_IO_ERROR,
> -                                        G_IO_ERROR_INVALID_ARGUMENT,
> -                                        "%s",
> -                                        "Expected stream to be writable");
> +        g_task_return_new_error(task,
> +                                G_IO_ERROR,
> +                                G_IO_ERROR_INVALID_ARGUMENT,
> +                                "%s",
> +                                "Expected stream to be readable");
>          goto cleanup;
>      }
>
>      result  = gvir_stream_send(stream, priv->buffer, priv->count,
> -                               priv->cancellable, &error);
> +                               cancellable, &error);
> +
> +    if (error != NULL) {
> +        if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
> +            g_warn_if_reached();
> +            g_task_return_new_error(task,
> +                                    G_IO_ERROR,
> +                                    G_IO_ERROR_INVALID_ARGUMENT,
> +                                    "%s",
> +                                    "Expected stream to be writable");
> +        } else {
> +            g_task_return_error(task, error);
> +        }
>
> -    if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
> -        g_warn_if_reached();
> -        g_simple_async_result_set_error(simple,
> -                                        G_IO_ERROR,
> -                                        G_IO_ERROR_INVALID_ARGUMENT,
> -                                        "%s",
> -                                        "Expected stream to be writable");
>          goto cleanup;
>      }
>
> -    if (result >= 0)
> -        g_simple_async_result_set_op_res_gssize(simple, result);
> -
> -    if (error)
> -        g_simple_async_result_take_error(simple, error);
> -
> -    if (priv->cancellable) {
> -        g_object_unref(priv->cancellable);
> -        priv->cancellable = NULL;
> -    }
> +    g_task_return_int(task, result);
>
>  cleanup:
> -    priv->result = NULL;
> -    g_simple_async_result_complete(simple);
> -    g_object_unref(simple);
> +    priv->task = NULL;
> +    g_object_unref(task);
>      return FALSE;
>  }
>
> @@ -159,7 +154,7 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
>      GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream);
>
>      g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream));
> -    g_return_if_fail(output_stream->priv->result == NULL);
> +    g_return_if_fail(output_stream->priv->task == NULL);
>
>      gvir_stream_add_watch_full(output_stream->priv->stream,
>                                 G_PRIORITY_DEFAULT,
> @@ -168,12 +163,8 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
>                                 g_object_ref(stream),
>                                 (GDestroyNotify)g_object_unref);
>
> -    output_stream->priv->result =
> -        g_simple_async_result_new(G_OBJECT(stream), callback, user_data,
> -                                  gvir_output_stream_write_async);
> -    if (cancellable)
> -        g_object_ref(cancellable);
> -    output_stream->priv->cancellable = cancellable;
> +    output_stream->priv->task =
> +        g_task_new(stream, cancellable, callback, user_data);
>      output_stream->priv->buffer = buffer;
>      output_stream->priv->count = count;
>  }
> @@ -181,22 +172,18 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
>
>  static gssize gvir_output_stream_write_finish(GOutputStream *stream,
>                                                GAsyncResult *result,
> -                                              GError **error G_GNUC_UNUSED)
> +                                              GError **error)
>  {
>      GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream);
> -    GSimpleAsyncResult *simple;
>      virStreamPtr handle;
>      gssize count;
>
>      g_return_val_if_fail(GVIR_IS_OUTPUT_STREAM(stream), -1);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream),
> -                                                        gvir_output_stream_write_async),
> -                         -1);
> +    g_return_val_if_fail(g_task_is_valid(result, stream), -1);
> +    g_return_val_if_fail(error == NULL || *error == NULL, -1);
>      g_object_get(output_stream->priv->stream, "handle", &handle, NULL);
>
> -    simple = G_SIMPLE_ASYNC_RESULT(result);
> -
> -    count = g_simple_async_result_get_op_res_gssize(simple);
> +    count = g_task_propagate_int(G_TASK(result), error);
>
>      virStreamFree(handle);
>
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
> index a0dcebc..6290fcb 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
> @@ -439,17 +439,18 @@ cleanup:
>  }
>
>  static void
> -gvir_storage_pool_refresh_helper(GSimpleAsyncResult *res,
> -                                 GObject *object,
> +gvir_storage_pool_refresh_helper(GTask *task,
> +                                 gpointer source_object,
> +                                 gpointer task_data G_GNUC_UNUSED,
>                                   GCancellable *cancellable)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
>      GError *err = NULL;
>
> -    if (!gvir_storage_pool_refresh(pool, cancellable, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> +    if (!gvir_storage_pool_refresh(pool, cancellable, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -464,20 +465,17 @@ void gvir_storage_pool_refresh_async(GVirStoragePool *pool,
>                                       GAsyncReadyCallback callback,
>                                       gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_refresh_async);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_refresh_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_run_in_thread(task, gvir_storage_pool_refresh_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -490,15 +488,10 @@ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool,
>                                            GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_refresh_async),
> -                         FALSE);
> -
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
> +    g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
> @@ -658,24 +651,25 @@ typedef struct {
>      guint flags;
>  } StoragePoolBuildData;
>
> +static void storage_pool_build_data_free(StoragePoolBuildData *data)
> +{
> +    g_slice_free(StoragePoolBuildData, data);
> +}
> +
>  static void
> -gvir_storage_pool_build_helper(GSimpleAsyncResult *res,
> -                               GObject *object,
> +gvir_storage_pool_build_helper(GTask *task,
> +                               gpointer source_object,
> +                               gpointer task_data,
>                                 GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> -    StoragePoolBuildData *data;
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
> +    StoragePoolBuildData *data = (StoragePoolBuildData *) task_data;
>      GError *err = NULL;
>
> -    data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
> -                                                      "StoragePoolBuildData");
> -
> -    if (!gvir_storage_pool_build(pool, data->flags, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> -
> -    g_slice_free (StoragePoolBuildData, data);
> +    if (!gvir_storage_pool_build(pool, data->flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -692,7 +686,7 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
>                                      GAsyncReadyCallback callback,
>                                      gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>      StoragePoolBuildData *data;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
> @@ -701,16 +695,13 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
>      data = g_slice_new0(StoragePoolBuildData);
>      data->flags = flags;
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_build_async);
> -    g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_build_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
> +    g_task_run_in_thread(task, gvir_storage_pool_build_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -726,16 +717,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool,
>                                          GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_build_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -762,17 +747,18 @@ gboolean gvir_storage_pool_undefine (GVirStoragePool *pool,
>  }
>
>  static void
> -gvir_storage_pool_undefine_helper(GSimpleAsyncResult *res,
> -                                  GObject *object,
> +gvir_storage_pool_undefine_helper(GTask *task,
> +                                  gpointer source_object,
> +                                  gpointer task_data G_GNUC_UNUSED,
>                                    GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
>      GError *err = NULL;
>
> -    if (!gvir_storage_pool_undefine(pool, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> +    if (!gvir_storage_pool_undefine(pool, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -787,20 +773,17 @@ void gvir_storage_pool_undefine_async (GVirStoragePool *pool,
>                                         GAsyncReadyCallback callback,
>                                         gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_undefine_async);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_undefine_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_run_in_thread(task, gvir_storage_pool_undefine_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -816,16 +799,10 @@ gboolean gvir_storage_pool_undefine_finish(GVirStoragePool *pool,
>                                             GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_undefine_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -854,23 +831,21 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool,
>  }
>
>  static void
> -gvir_storage_pool_start_helper(GSimpleAsyncResult *res,
> -                               GObject *object,
> +gvir_storage_pool_start_helper(GTask *task,
> +                               gpointer source_object,
> +                               gpointer task_data,
>                                 GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
>      StoragePoolBuildData *data;
>      GError *err = NULL;
>
> -    data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
> -                                                      "StoragePoolBuildData");
> +    data = (StoragePoolBuildData *) task_data;
>
> -    if (!gvir_storage_pool_start(pool, data->flags, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> -
> -    g_slice_free (StoragePoolBuildData, data);
> +    if (!gvir_storage_pool_start(pool, data->flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -887,7 +862,7 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
>                                      GAsyncReadyCallback callback,
>                                      gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>      StoragePoolBuildData *data;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
> @@ -896,16 +871,13 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
>      data = g_slice_new0(StoragePoolBuildData);
>      data->flags = flags;
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_start_async);
> -    g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_start_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
> +    g_task_run_in_thread(task, gvir_storage_pool_start_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -921,16 +893,10 @@ gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool,
>                                          GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_start_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -957,17 +923,18 @@ gboolean gvir_storage_pool_stop (GVirStoragePool *pool,
>  }
>
>  static void
> -gvir_storage_pool_stop_helper(GSimpleAsyncResult *res,
> -                              GObject *object,
> +gvir_storage_pool_stop_helper(GTask *task,
> +                              gpointer source_object,
> +                              gpointer task_data G_GNUC_UNUSED,
>                                GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
>      GError *err = NULL;
>
> -    if (!gvir_storage_pool_stop(pool, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> +    if (!gvir_storage_pool_stop(pool, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -982,20 +949,17 @@ void gvir_storage_pool_stop_async (GVirStoragePool *pool,
>                                     GAsyncReadyCallback callback,
>                                     gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
>      g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_stop_async);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_stop_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_run_in_thread(task, gvir_storage_pool_stop_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -1011,16 +975,10 @@ gboolean gvir_storage_pool_stop_finish(GVirStoragePool *pool,
>                                         GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_stop_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  /**
> @@ -1100,23 +1058,21 @@ gboolean gvir_storage_pool_set_autostart(GVirStoragePool *pool,
>  }
>
>  static void
> -gvir_storage_pool_delete_helper(GSimpleAsyncResult *res,
> -                                GObject *object,
> +gvir_storage_pool_delete_helper(GTask *task,
> +                                gpointer source_object,
> +                                gpointer task_data,
>                                  GCancellable *cancellable G_GNUC_UNUSED)
>  {
> -    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
>      StoragePoolBuildData *data;
>      GError *err = NULL;
>
> -    data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
> -                                                      "StoragePoolBuildData");
> +    data = (StoragePoolBuildData *) task_data;
>
> -    if (!gvir_storage_pool_delete(pool, data->flags, &err)) {
> -        g_simple_async_result_set_from_error(res, err);
> -        g_error_free(err);
> -    }
> -
> -    g_slice_free (StoragePoolBuildData, data);
> +    if (!gvir_storage_pool_delete(pool, data->flags, &err))
> +        g_task_return_error(task, err);
> +    else
> +        g_task_return_boolean(task, TRUE);
>  }
>
>  /**
> @@ -1133,7 +1089,7 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool,
>                                       GAsyncReadyCallback callback,
>                                       gpointer user_data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task;
>      StoragePoolBuildData *data;
>
>      g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
> @@ -1142,16 +1098,13 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool,
>      data = g_slice_new0(StoragePoolBuildData);
>      data->flags = flags;
>
> -    res = g_simple_async_result_new(G_OBJECT(pool),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_storage_pool_delete_async);
> -    g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
> -    g_simple_async_result_run_in_thread(res,
> -                                        gvir_storage_pool_delete_helper,
> -                                        G_PRIORITY_DEFAULT,
> -                                        cancellable);
> -    g_object_unref(res);
> +    task = g_task_new(G_OBJECT(pool),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
> +    g_task_run_in_thread(task, gvir_storage_pool_delete_helper);
> +    g_object_unref(task);
>  }
>
>  /**
> @@ -1167,16 +1120,10 @@ gboolean gvir_storage_pool_delete_finish(GVirStoragePool *pool,
>                                           GError **err)
>  {
>      g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> -    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> -                                                        gvir_storage_pool_delete_async),
> -                         FALSE);
> +    g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
>      g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
>
> -    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> -                                              err))
> -        return FALSE;
> -
> -    return TRUE;
> +    return g_task_propagate_boolean(G_TASK(result), err);
>  }
>
>  G_GNUC_INTERNAL void gvir_storage_pool_delete_vol(GVirStoragePool *pool,
> diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c
> index 46dbd9a..2a8fbd5 100644
> --- a/libvirt-gobject/libvirt-gobject-stream.c
> +++ b/libvirt-gobject/libvirt-gobject-stream.c
> @@ -129,14 +129,11 @@ static gboolean gvir_stream_close(GIOStream *io_stream,
>      return (i_ret && o_ret);
>  }
>
> -
> -static void gvir_stream_close_async(GIOStream *stream,
> -                                    int io_priority G_GNUC_UNUSED,
> -                                    GCancellable *cancellable,
> -                                    GAsyncReadyCallback callback,
> -                                    gpointer user_data)
> +static gboolean close_in_idle (gpointer data)
>  {
> -    GSimpleAsyncResult *res;
> +    GTask *task = G_TASK (data);
> +    GIOStream *stream = G_IO_STREAM(g_task_get_source_object (task));
> +    GCancellable *cancellable = g_task_get_cancellable (task);
>      GIOStreamClass *class;
>      GError *error;
>
> @@ -146,27 +143,41 @@ static void gvir_stream_close_async(GIOStream *stream,
>      error = NULL;
>      if (class->close_fn &&
>          !class->close_fn(stream, cancellable, &error)) {
> -        g_simple_async_report_take_gerror_in_idle(G_OBJECT (stream),
> -                                                  callback, user_data,
> -                                                  error);
> -        return;
> +        g_task_return_error(task, error);
> +        return FALSE;
>      }
>
> -    res = g_simple_async_result_new(G_OBJECT (stream),
> -                                    callback,
> -                                    user_data,
> -                                    gvir_stream_close_async);
> -    g_simple_async_result_complete_in_idle(res);
> -    g_object_unref (res);
> +    g_task_return_boolean(task, TRUE);
> +
> +    return FALSE;
>  }
>
> +static void gvir_stream_close_async(GIOStream *stream,
> +                                    int io_priority G_GNUC_UNUSED,
> +                                    GCancellable *cancellable,
> +                                    GAsyncReadyCallback callback,
> +                                    gpointer user_data)
> +{
> +    GTask *task;
> +
> +    task = g_task_new(G_OBJECT(stream),
> +                      cancellable,
> +                      callback,
> +                      user_data);
> +    g_idle_add(close_in_idle, task);
> +    g_object_unref(task);
> +}
>
>  static gboolean
> -gvir_stream_close_finish(GIOStream *stream G_GNUC_UNUSED,
> -                         GAsyncResult *result G_GNUC_UNUSED,
> -                         GError **error G_GNUC_UNUSED)
> +gvir_stream_close_finish(GIOStream *stream,
> +                         GAsyncResult *result,
> +                         GError **error)
>  {
> -    return TRUE;
> +    g_return_val_if_fail(GVIR_IS_STREAM(stream), -1);
> +    g_return_val_if_fail(g_task_is_valid(result, stream), -1);
> +    g_return_val_if_fail(error == NULL || *error == NULL, -1);
> +
> +    return g_task_propagate_boolean(G_TASK(result), error);
>  }
>
>
> --
> 2.5.0
>



-- 
Regards,

Zeeshan Ali (Khattak)
________________________________________
Befriend GNOME: http://www.gnome.org/friends/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]