[libgovirt] Use ovirt_rest_call_new in ovirt_proxy_get_collection_xml



commit bd4fb2c8a12053cb68c0f7f4a56e1020d31a6f21
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Tue Apr 29 12:43:05 2014 +0200

    Use ovirt_rest_call_new in ovirt_proxy_get_collection_xml
    
    It makes more sense to use an OvirtResourceResCall than an
    OvirtActionRestCall there.

 govirt/ovirt-proxy-private.h      |    3 --
 govirt/ovirt-proxy.c              |   48 +++++++++++++++++-------------------
 govirt/ovirt-resource-rest-call.c |   10 ++++---
 govirt/ovirt-vm.c                 |   14 ++++++----
 4 files changed, 37 insertions(+), 38 deletions(-)
---
diff --git a/govirt/ovirt-proxy-private.h b/govirt/ovirt-proxy-private.h
index 647d235..b9cc153 100644
--- a/govirt/ovirt-proxy-private.h
+++ b/govirt/ovirt-proxy-private.h
@@ -61,9 +61,6 @@ typedef gboolean (*OvirtProxyCallAsyncCb)(OvirtProxy *proxy,
                                           RestProxyCall *call,
                                           gpointer user_data,
                                           GError **error);
-OvirtRestCall *ovirt_rest_call_new(OvirtProxy *proxy,
-                                   const char *method,
-                                   const char *href);
 void ovirt_rest_call_async(OvirtRestCall *call,
                            GSimpleAsyncResult *result,
                            GCancellable *cancellable,
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index 123c986..8ca78af 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -139,6 +139,26 @@ static void dump_vm(OvirtVm *vm)
 #endif
 
 
+static RestProxyCall *ovirt_rest_call_new(OvirtProxy *proxy,
+                                          const char *method,
+                                          const char *href)
+{
+    RestProxyCall *call;
+
+    g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
+
+    call = REST_PROXY_CALL(ovirt_action_rest_call_new(REST_PROXY(proxy)));
+    if (method != NULL) {
+        rest_proxy_call_set_method(call, method);
+    }
+    rest_proxy_call_set_function(call, href);
+    /* FIXME: to set or not to set ?? */
+    rest_proxy_call_add_header(call, "All-Content", "true");
+
+    return call;
+}
+
+
 RestXmlNode *ovirt_proxy_get_collection_xml(OvirtProxy *proxy,
                                             const char *href,
                                             GError **error)
@@ -148,9 +168,7 @@ RestXmlNode *ovirt_proxy_get_collection_xml(OvirtProxy *proxy,
 
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
 
-    call = REST_PROXY_CALL(ovirt_action_rest_call_new(REST_PROXY(proxy)));
-    rest_proxy_call_set_function(call, href);
-    rest_proxy_call_add_header(call, "All-Content", "true");
+    call = ovirt_rest_call_new(proxy, "GET", href);
 
     if (!rest_proxy_call_sync(call, error)) {
         if ((error != NULL) && (*error != NULL)) {
@@ -234,26 +252,6 @@ call_async_cb(RestProxyCall *call, const GError *error,
 }
 
 
-OvirtRestCall *ovirt_rest_call_new(OvirtProxy *proxy,
-                                   const char *method,
-                                   const char *href)
-{
-    OvirtRestCall *call;
-
-    g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
-
-    call = OVIRT_REST_CALL(ovirt_action_rest_call_new(REST_PROXY(proxy)));
-    if (method != NULL) {
-        rest_proxy_call_set_method(REST_PROXY_CALL(call), method);
-    }
-    rest_proxy_call_set_function(REST_PROXY_CALL(call), href);
-    /* FIXME: to set or not to set ?? */
-    rest_proxy_call_add_header(REST_PROXY_CALL(call), "All-Content", "true");
-
-    return call;
-}
-
-
 void ovirt_rest_call_async(OvirtRestCall *call,
                            GSimpleAsyncResult *result,
                            GCancellable *cancellable,
@@ -356,7 +354,7 @@ void ovirt_proxy_get_collection_xml_async(OvirtProxy *proxy,
                                           GDestroyNotify destroy_func)
 {
     OvirtProxyGetCollectionAsyncData *data;
-    OvirtRestCall *call;
+    RestProxyCall *call;
 
     data = g_slice_new0(OvirtProxyGetCollectionAsyncData);
     data->parser = callback;
@@ -365,7 +363,7 @@ void ovirt_proxy_get_collection_xml_async(OvirtProxy *proxy,
 
     call = ovirt_rest_call_new(proxy, "GET", href);
 
-    ovirt_rest_call_async(call, result, cancellable,
+    ovirt_rest_call_async(OVIRT_REST_CALL(call), result, cancellable,
                           get_collection_xml_async_cb, data,
                           (GDestroyNotify)ovirt_proxy_get_collection_async_data_destroy);
     g_object_unref(call);
diff --git a/govirt/ovirt-resource-rest-call.c b/govirt/ovirt-resource-rest-call.c
index 41ac0f4..5f82c47 100644
--- a/govirt/ovirt-resource-rest-call.c
+++ b/govirt/ovirt-resource-rest-call.c
@@ -77,10 +77,12 @@ static void ovirt_resource_rest_call_set_property(GObject *object,
         char *href;
 
         call->priv->resource = g_value_dup_object(value);
-        g_object_get(G_OBJECT(call->priv->resource), "href", &href, NULL);
-        g_return_if_fail(href != NULL);
-        g_object_set(object, "href", href, NULL);
-        g_free(href);
+        if (call->priv->resource != NULL) {
+            g_object_get(G_OBJECT(call->priv->resource), "href", &href, NULL);
+            g_return_if_fail(href != NULL);
+            g_object_set(object, "href", href, NULL);
+            g_free(href);
+        }
         break;
     }
     default:
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
index 5f562c7..71ff51b 100644
--- a/govirt/ovirt-vm.c
+++ b/govirt/ovirt-vm.c
@@ -314,9 +314,8 @@ void ovirt_vm_refresh_async(OvirtVm *vm, OvirtProxy *proxy,
                             GAsyncReadyCallback callback,
                             gpointer user_data)
 {
-    OvirtRestCall *call;
+    OvirtResourceRestCall *call;
     GSimpleAsyncResult *result;
-    char *href;
 
     g_return_if_fail(OVIRT_IS_VM(vm));
     g_return_if_fail(OVIRT_IS_PROXY(proxy));
@@ -325,12 +324,15 @@ void ovirt_vm_refresh_async(OvirtVm *vm, OvirtProxy *proxy,
     result = g_simple_async_result_new(G_OBJECT(vm), callback,
                                        user_data,
                                        ovirt_vm_refresh_async);
-    g_object_get(G_OBJECT(vm), "href", &href, NULL);
-    call = ovirt_rest_call_new(proxy, "GET", href);
-    ovirt_rest_call_async(call, result, cancellable,
+    call = ovirt_resource_rest_call_new(REST_PROXY(proxy),
+                                        OVIRT_RESOURCE(vm));
+    /* FIXME: to set or not to set ?? */
+    rest_proxy_call_add_header(REST_PROXY_CALL(call),
+                               "All-Content", "true");
+    rest_proxy_call_set_method(REST_PROXY_CALL(call), "GET");
+    ovirt_rest_call_async(OVIRT_REST_CALL(call), result, cancellable,
                           ovirt_vm_refresh_async_cb, vm, NULL);
     g_object_unref(G_OBJECT(call));
-    g_free(href);
 }
 
 gboolean ovirt_vm_refresh_finish(OvirtVm *vm,


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