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

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

 



ACK

Christophe

On Thu, Apr 19, 2012 at 05:17:04PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |   80 ++++++++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-domain.h |    7 +++
>  libvirt-gobject/libvirt-gobject.sym      |    4 +-
>  3 files changed, 90 insertions(+), 1 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
> index 350a5b0..67ca257 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -572,6 +572,86 @@ 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,
> +                                 (GDestroyNotify) gvir_domain_info_free);
> +}
> +
> +/**
> + * gvir_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);
> +}
> +
> +/**
> + * gvir_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);
> +    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);
> +
> +    return gvir_domain_info_copy (ret);
> +}
> +
>  /**
>   * 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..f43836f 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -1,4 +1,4 @@
> -LIBVIRT_GOBJECT_0.0.7 {
> +LIBVIRT_GOBJECT_0.0.8 {
>    global:
>          gvir_init_object;
>          gvir_init_object_check;
> @@ -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@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpEQthbAVKIH.pgp
Description: PGP signature

--
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]