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

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



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-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 70d1adc..d5f9c45 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -497,14 +497,12 @@ gboolean gvir_connection_open_finish(GVirConnection *conn,
                                      GError **err)
 {
     g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
-    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
+    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+                                                        gvir_connection_open_async),
+                         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_connection_open_async);
-        if (g_simple_async_result_propagate_error(simple, err))
-            return FALSE;
-    }
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+        return FALSE;
 
     return TRUE;
 }
@@ -904,14 +902,12 @@ gboolean gvir_connection_fetch_domains_finish(GVirConnection *conn,
                                               GError **err)
 {
     g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
-    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
+    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+                                                        gvir_connection_fetch_domains_async),
+                         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_connection_fetch_domains_async);
-        if (g_simple_async_result_propagate_error(simple, err))
-            return FALSE;
-    }
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+        return FALSE;
 
     return TRUE;
 }
@@ -965,15 +961,12 @@ gboolean gvir_connection_fetch_storage_pools_finish(GVirConnection *conn,
                                                     GError **err)
 {
     g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
-    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), FALSE);
+    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+                                                        gvir_connection_fetch_storage_pools_async),
+                         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_connection_fetch_storage_pools_async);
-        if (g_simple_async_result_propagate_error(simple, err))
-            return FALSE;
-    }
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+        return FALSE;
 
     return TRUE;
 }
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 4148a78..967ff67 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -812,15 +812,12 @@ 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_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_domain_save_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(dom),
+                                                        gvir_domain_save_async),
+                         FALSE);
+
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+        return FALSE;
 
     return TRUE;
 }
diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c
index 6b9f075..733049b 100644
--- a/libvirt-gobject/libvirt-gobject-input-stream.c
+++ b/libvirt-gobject/libvirt-gobject-input-stream.c
@@ -188,12 +188,13 @@ static gssize gvir_input_stream_read_finish(GInputStream *stream,
     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_object_get(input_stream->priv->stream, "handle", &handle, NULL);
 
     simple = G_SIMPLE_ASYNC_RESULT(result);
 
-    g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == gvir_input_stream_read_async);
-
     count = g_simple_async_result_get_op_res_gssize(simple);
 
     virStreamEventRemoveCallback(handle);
diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c
index 741b2bc..bb82bd3 100644
--- a/libvirt-gobject/libvirt-gobject-output-stream.c
+++ b/libvirt-gobject/libvirt-gobject-output-stream.c
@@ -188,12 +188,13 @@ static gssize gvir_output_stream_write_finish(GOutputStream *stream,
     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_object_get(output_stream->priv->stream, "handle", &handle, NULL);
 
     simple = G_SIMPLE_ASYNC_RESULT(result);
 
-    g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == gvir_output_stream_write_async);
-
     count = g_simple_async_result_get_op_res_gssize(simple);
 
     virStreamEventRemoveCallback(handle);
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);
+
+    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);
+
+    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);
+
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
+                                              err))
+        return FALSE;
 
     return TRUE;
 }
-- 
1.7.7.5


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