[libgovirt] OvirtResourceRestCall: Set function from resource URI



commit 39130b4a6ec7397586f9bd40899db51b988e745e
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Sep 5 18:59:38 2013 +0200

    OvirtResourceRestCall: Set function from resource URI
    
    When instantiating an OvirtResourceRestCall, we can get
    the href of the object we want to interact with from the
    OvirtResource we are manipulating, this saves a few lines from
    calling code ;)

 govirt/ovirt-resource-private.h   |    3 +--
 govirt/ovirt-resource-rest-call.c |   10 +++++++++-
 govirt/ovirt-resource.c           |   17 ++---------------
 3 files changed, 12 insertions(+), 18 deletions(-)
---
diff --git a/govirt/ovirt-resource-private.h b/govirt/ovirt-resource-private.h
index 4485589..d0983f8 100644
--- a/govirt/ovirt-resource-private.h
+++ b/govirt/ovirt-resource-private.h
@@ -30,8 +30,7 @@ const char *ovirt_resource_get_action(OvirtResource *resource,
                                       const char *action);
 char *ovirt_resource_to_xml(OvirtResource *resource);
 gboolean ovirt_resource_rest_call(OvirtResource *resource, OvirtProxy *proxy,
-                                  const char *method, const char *href,
-                                  GError **error);
+                                  const char *method, GError **error);
 
 G_END_DECLS
 
diff --git a/govirt/ovirt-resource-rest-call.c b/govirt/ovirt-resource-rest-call.c
index d04054e..011e83e 100644
--- a/govirt/ovirt-resource-rest-call.c
+++ b/govirt/ovirt-resource-rest-call.c
@@ -28,6 +28,7 @@
 #include "ovirt-resource-private.h"
 #include "ovirt-resource-rest-call.h"
 #include "ovirt-rest-call-error.h"
+#include "ovirt-utils.h"
 #include <rest/rest-params.h>
 
 #define OVIRT_RESOURCE_REST_CALL_GET_PRIVATE(obj)                         \
@@ -69,9 +70,16 @@ static void ovirt_resource_rest_call_set_property(GObject *object,
     OvirtResourceRestCall *call = OVIRT_RESOURCE_REST_CALL(object);
 
     switch (prop_id) {
-    case PROP_RESOURCE:
+    case PROP_RESOURCE: {
+        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);
         break;
+    }
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index 9234506..d32b2bf 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -475,19 +475,12 @@ char *ovirt_resource_to_xml(OvirtResource *resource)
 G_GNUC_INTERNAL gboolean ovirt_resource_rest_call(OvirtResource *resource,
                                                   OvirtProxy *proxy,
                                                   const char *method,
-                                                  const char *href,
                                                   GError **error)
 {
     RestProxyCall *call;
-    const char *function;
-
-    g_return_val_if_fail(href != NULL, FALSE);
-
-    function = ovirt_utils_strip_api_base_dir(href);
 
     call = REST_PROXY_CALL(ovirt_resource_rest_call_new(REST_PROXY(proxy), resource));
     rest_proxy_call_set_method(call, method);
-    rest_proxy_call_set_function(call, function);
     rest_proxy_call_add_param(call, "async", "false");
 
     if (!rest_proxy_call_sync(call, error)) {
@@ -500,7 +493,7 @@ G_GNUC_INTERNAL gboolean ovirt_resource_rest_call(OvirtResource *resource,
             g_clear_error(error);
             g_propagate_error(error, local_error);
         }
-        g_warning("Error while updating %p (%s)", resource, function);
+        g_warning("Error while updating %p", resource);
         g_warning("message: %s", (*error)->message);
         g_object_unref(G_OBJECT(call));
 
@@ -517,20 +510,14 @@ gboolean ovirt_resource_update(OvirtResource *resource,
                                OvirtProxy *proxy,
                                GError **error)
 {
-    char *href;
     gboolean call_successful;
 
     g_return_val_if_fail(OVIRT_IS_RESOURCE(resource), FALSE);
     g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
     g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
 
-
-    g_object_get(G_OBJECT(resource), "href", &href, NULL);
-    g_return_val_if_fail(href != NULL, FALSE);
     call_successful = ovirt_resource_rest_call(resource, proxy,
-                                               "PUT", href,
-                                               error);
-    g_free(href);
+                                               "PUT", error);
 
     return call_successful;
 }


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