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

Re: [libvirt] [libvirt-glib] Add async variant of gvir_domain_get_info()



On Thu, Apr 19, 2012 at 03:12:01AM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |   74 ++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h |    7 +++
>  libvirt-gobject/libvirt-gobject.sym      |    2 +
>  3 files changed, 83 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index 0bafa7e..896aae1 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -572,6 +572,80 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
>      return ret;
>  }
>  
> +static void
> +gvir_domain_get_info_helper(GSimpleAsyncResult *res,
> +                            GObject *object,
> +                            GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirDomain *dom = GVIR_DOMAIN(object);
> +    GVirDomainInfo *info;
> +    GError *err = NULL;
> +
> +    info = gvir_domain_get_info(dom, &err);
> +    if (err)
> +        g_simple_async_result_take_error(res, err);
> +    else
> +        g_simple_async_result_set_op_res_gpointer(res, info, NULL);

Shouldn't the last parameter be gvir_domain_info_free?

> +}
> +
> +/**
> + * gir_domain_get_info_async:
> + * @dom: the domain
> + * @cancellable: (allow-none)(transfer none): cancellation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + *
> + * Asynchronous variant of #gvir_domain_get_info.
> + */
> +void gvir_domain_get_info_async(GVirDomain *dom,
> +                                GCancellable *cancellable,
> +                                GAsyncReadyCallback callback,
> +                                gpointer user_data)
> +{
> +    GSimpleAsyncResult *res;
> +
> +    g_return_if_fail(GVIR_IS_DOMAIN(dom));
> +
> +    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);
> +}
> +
> +/**
> + * gir_domain_get_info_finish:
> + * @dom: the domain
> + * @result: (transfer none): async method result
> + * @err: Place-holder for possible errors
> + *
> + * Finishes the operation started by #gvir_domain_get_info_async.
> + *
> + * Returns: (transfer full): the info
> + */
> +GVirDomainInfo *gvir_domain_get_info_finish(GVirDomain *dom,
> +                                            GAsyncResult *result,
> +                                            GError **err)
> +{
> +    GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT(result);
> +
> +    g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);

FALSE -> NULL

> +    g_return_val_if_fail
> +                (g_simple_async_result_is_valid(result,
> +                                                G_OBJECT(dom),
> +                                                gvir_domain_get_info_async),
> +                 FALSE);

Same here

> +
> +    if (g_simple_async_result_propagate_error(res, err))
> +        return NULL;
> +
> +    return g_simple_async_result_get_op_res_gpointer(res);
> +}
> +
>  /**
>   * gvir_domain_screenshot:
>   * @stream: stream to use as output
> diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
> index 8a4836e..677fbe6 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.h
> +++ b/libvirt-gobject/libvirt-gobject-domain.h
> @@ -141,6 +141,13 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
>  
>  GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
>                                       GError **err);
> +void gvir_domain_get_info_async(GVirDomain *dom,
> +                                GCancellable *cancellable,
> +                                GAsyncReadyCallback callback,
> +                                gpointer user_data);
> +GVirDomainInfo *gvir_domain_get_info_finish(GVirDomain *dom,
> +                                            GAsyncResult *result,
> +                                            GError **err);
>  
>  GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom,
>                                           guint flags,
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 64c91cc..00b32d4 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -70,6 +70,8 @@ LIBVIRT_GOBJECT_0.0.7 {
>  	gvir_domain_set_config;
>  	gvir_domain_get_devices;
>  	gvir_domain_get_info;
> +	gvir_domain_get_info_async;
> +	gvir_domain_get_info_finish;
>  	gvir_domain_get_persistent;
>  	gvir_domain_get_saved;
>  	gvir_domain_screenshot;
> -- 
> 1.7.7.6
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpAk74OImAft.pgp
Description: PGP signature


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