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

Re: [libvirt] [libvirt-glib 2/2] Async API to build & start storage pools



On Wed, Oct 26, 2011 at 07:50:54PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>
> 
> ---
>  libvirt-gobject/libvirt-gobject-storage-pool.c |  160 ++++++++++++++++++++++++
>  libvirt-gobject/libvirt-gobject-storage-pool.h |   16 +++
>  libvirt-gobject/libvirt-gobject.sym            |    4 +
>  3 files changed, 180 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
> index 74ecabc..bee0a17 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
> @@ -541,6 +541,88 @@ gboolean gvir_storage_pool_build (GVirStoragePool *pool,
>      return TRUE;
>  }
>  
> +typedef struct {
> +    guint64 flags;
> +} StoragePoolBuildData;
> +
> +static void
> +gvir_storage_pool_build_helper(GSimpleAsyncResult *res,
> +                               GObject *object,
> +                               GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    StoragePoolBuildData *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);
> +}
> +
> +/**
> + * gvir_storage_pool_build_async:
> + * @pool: the storage pool to build
> + * @flags:  the flags
> + * @cancellable: (allow-none)(transfer none): cancellation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + */
> +void gvir_storage_pool_build_async (GVirStoragePool *pool,
> +                                    guint64 flags G_GNUC_UNUSED,

flags *is* used in this method.

> +                                    GCancellable *cancellable,
> +                                    GAsyncReadyCallback callback,
> +                                    gpointer user_data)
> +{
> +    GSimpleAsyncResult *res;
> +    StoragePoolBuildData *data;
> +
> +    data = g_new0(StoragePoolBuildData, 1);
> +    data->flags = flags;
> +
> +    res = g_simple_async_result_new(G_OBJECT(pool),
> +                                    callback,
> +                                    user_data,
> +                                    gvir_storage_pool_build);
> +    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);
> +}
> +
> +/**
> + * gvir_storage_pool_build_finish:
> + * @pool: the storage pool to build
> + * @result: (transfer none): async method result
> + * @err: return location for any #GError
> + *
> + * Return value: #True on success, #False otherwise.
> + */
> +gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool,
> +                                        GAsyncResult *result,
> +                                        GError **err)
> +{
> +    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> +    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
> +
> +    if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
> +        GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
> +        g_warn_if_fail (g_simple_async_result_get_source_tag(simple) ==
> +                        gvir_storage_pool_build);
> +        if (g_simple_async_result_propagate_error(simple, err))
> +            return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> +
>  /**
>   * gvir_storage_pool_start:
>   * @pool: the storage pool to start
> @@ -562,3 +644,81 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool,
>  
>      return TRUE;
>  }
> +
> +static void
> +gvir_storage_pool_start_helper(GSimpleAsyncResult *res,
> +                               GObject *object,
> +                               GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +    GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
> +    StoragePoolBuildData *data;
> +    GError *err = NULL;
> +
> +    data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
> +                                                      "StoragePoolBuildData");
> +
> +    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);
> +}
> +
> +/**
> + * gvir_storage_pool_start_async:
> + * @pool: the storage pool to start
> + * @flags:  the flags
> + * @cancellable: (allow-none)(transfer none): cancellation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + */
> +void gvir_storage_pool_start_async (GVirStoragePool *pool,
> +                                    guint64 flags G_GNUC_UNUSED,

Likewise

> +                                    GCancellable *cancellable,
> +                                    GAsyncReadyCallback callback,
> +                                    gpointer user_data)
> +{
> +    GSimpleAsyncResult *res;
> +    StoragePoolBuildData *data;
> +
> +    data = g_new0(StoragePoolBuildData, 1);
> +    data->flags = flags;
> +
> +    res = g_simple_async_result_new(G_OBJECT(pool),
> +                                    callback,
> +                                    user_data,
> +                                    gvir_storage_pool_start);
> +    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);
> +}
> +
> +/**
> + * gvir_storage_pool_start_finish:
> + * @pool: the storage pool to start
> + * @result: (transfer none): async method result
> + * @err: return location for any #GError
> + *
> + * Return value: #True on success, #False otherwise.
> + */
> +gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool,
> +                                        GAsyncResult *result,
> +                                        GError **err)
> +{
> +    g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
> +    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
> +
> +    if (G_IS_SIMPLE_ASYNC_RESULT(result)) {
> +        GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT(result);
> +        g_warn_if_fail (g_simple_async_result_get_source_tag(simple) ==
> +                        gvir_storage_pool_start);
> +        if (g_simple_async_result_propagate_error(simple, err))
> +            return FALSE;
> +    }
> +
> +    return TRUE;
> +}
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h
> index 7b13ef9..25df1b1 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.h
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h
> @@ -91,10 +91,26 @@ GVirStorageVol *gvir_storage_pool_create_volume
>  gboolean gvir_storage_pool_build (GVirStoragePool *pool,
>                                    guint64 flags,
>                                    GError **err);
> +void gvir_storage_pool_build_async (GVirStoragePool *pool,
> +                                    guint64 flags,
> +                                    GCancellable *cancellable,
> +                                    GAsyncReadyCallback callback,
> +                                    gpointer user_data);
> +gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool,
> +                                        GAsyncResult *result,
> +                                        GError **err);
>  
>  gboolean gvir_storage_pool_start (GVirStoragePool *pool,
>                                    guint64 flags,
>                                    GError **err);
> +void gvir_storage_pool_start_async (GVirStoragePool *pool,
> +                                    guint64 flags,
> +                                    GCancellable *cancellable,
> +                                    GAsyncReadyCallback callback,
> +                                    gpointer user_data);
> +gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool,
> +                                        GAsyncResult *result,
> +                                        GError **err);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
> index 4b1b84c..f0e8402 100644
> --- a/libvirt-gobject/libvirt-gobject.sym
> +++ b/libvirt-gobject/libvirt-gobject.sym
> @@ -90,7 +90,11 @@ LIBVIRT_GOBJECT_0.0.1 {
>  	gvir_storage_pool_get_volume;
>  	gvir_storage_pool_create_volume;
>  	gvir_storage_pool_build;
> +	gvir_storage_pool_build_async;
> +	gvir_storage_pool_build_finish;
>  	gvir_storage_pool_start;
> +	gvir_storage_pool_start_async;
> +	gvir_storage_pool_start_finish;
>  
>  	gvir_storage_vol_get_type;
>  	gvir_storage_vol_handle_get_type;
> -- 

ACK with the two G_GNUC_UNUSED attributes removed

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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