Re: [libvirt-glib 2/2] Use g_simple_async_result_is_valid in _finish functions

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

 



On Mon, Jan 09, 2012 at 10:11:12AM +0100, Christophe Fergeau wrote:
> The _finish functions for async operations can be simplified by
> using g_simple_async_result_is_valid instead of doing the checks
> it does by ourselves.
> ---
>  libvirt-gobject/libvirt-gobject-connection.c    |   37 +++++++----------
>  libvirt-gobject/libvirt-gobject-domain.c        |   15 +++----
>  libvirt-gobject/libvirt-gobject-input-stream.c  |    5 +-
>  libvirt-gobject/libvirt-gobject-output-stream.c |    5 +-
>  libvirt-gobject/libvirt-gobject-storage-pool.c  |   48 ++++++++++-------------
>  5 files changed, 48 insertions(+), 62 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
> index 488f146..c0b32a5 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-pool.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
> @@ -455,15 +455,13 @@ 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_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_refresh_async);
> -        if (g_simple_async_result_propagate_error(simple, err))
> -            return FALSE;
> -    }
> +    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> +                                                        gvir_storage_pool_refresh_async),
> +                         -1);

s/-1/FALSE/


> +
> +    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> +                                              err))
> +        return FALSE;
>  
>      return TRUE;
>  }
> @@ -649,15 +647,13 @@ 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_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_async);
> -        if (g_simple_async_result_propagate_error(simple, err))
> -            return FALSE;
> -    }
> +    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> +                                                        gvir_storage_pool_build_async),
> +                         -1);

s/-1/FALSE/


> +
> +    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> +                                              err))
> +        return FALSE;
>  
>      return TRUE;
>  }
> @@ -749,15 +745,13 @@ 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_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_async);
> -        if (g_simple_async_result_propagate_error(simple, err))
> -            return FALSE;
> -    }
> +    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
> +                                                        gvir_storage_pool_start_async),
> +                         -1);


s/-1/FALSE/


> +
> +    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
> +                                              err))
> +        return FALSE;
>  
>      return TRUE;
>  }


ACK, if those 3 return values are fixed

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

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