[libgovirt] Split ovirt_rest_call_async in 2 functions
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] Split ovirt_rest_call_async in 2 functions
- Date: Tue, 8 Oct 2013 17:05:56 +0000 (UTC)
commit 2e54a602a7b17e71b091b458b78a113e4e9678cb
Author: Christophe Fergeau <cfergeau redhat com>
Date: Thu Sep 5 17:07:26 2013 +0200
Split ovirt_rest_call_async in 2 functions
Now that we have 2 different OvirtRestCall classes, it's better to
pass the OvirtRestCall parameter to ovirt_rest_call_async so that
we can easily use it with instances of the 2 different classes.
govirt/ovirt-proxy-private.h | 9 +++---
govirt/ovirt-proxy.c | 52 ++++++++++++++++++++++++++------------
govirt/ovirt-resource-private.h | 4 +-
govirt/ovirt-resource.c | 41 ++++++++++++++++++------------
govirt/ovirt-vm.c | 9 +++++-
5 files changed, 74 insertions(+), 41 deletions(-)
---
diff --git a/govirt/ovirt-proxy-private.h b/govirt/ovirt-proxy-private.h
index 92010bc..cd5544c 100644
--- a/govirt/ovirt-proxy-private.h
+++ b/govirt/ovirt-proxy-private.h
@@ -22,10 +22,10 @@
#ifndef __OVIRT_PROXY_PRIVATE_H__
#define __OVIRT_PROXY_PRIVATE_H__
-#include <rest/rest-proxy-call.h>
#include <rest/rest-xml-node.h>
#include "ovirt-proxy.h"
+#include "ovirt-rest-call.h"
G_BEGIN_DECLS
@@ -55,9 +55,10 @@ typedef gboolean (*OvirtProxyCallAsyncCb)(OvirtProxy *proxy,
RestProxyCall *call,
gpointer user_data,
GError **error);
-void ovirt_rest_call_async(OvirtProxy *proxy,
- const char *method,
- const char *href,
+OvirtRestCall *ovirt_rest_call_new(OvirtProxy *proxy,
+ const char *method,
+ const char *href);
+void ovirt_rest_call_async(OvirtRestCall *call,
GSimpleAsyncResult *result,
GCancellable *cancellable,
OvirtProxyCallAsyncCb callback,
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index 21877ba..57eab35 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -222,33 +222,45 @@ call_async_cb(RestProxyCall *call, const GError *error,
ovirt_proxy_call_async_data_free(data);
}
-void ovirt_rest_call_async(OvirtProxy *proxy,
- const char *method,
- const char *href,
+
+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);
+ }
+ href = ovirt_utils_strip_api_base_dir(href);
+ 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,
OvirtProxyCallAsyncCb callback,
gpointer user_data,
GDestroyNotify destroy_func)
{
- RestProxyCall *call;
+ OvirtProxy *proxy;
GError *error;
OvirtProxyCallAsyncData *data;
- g_return_if_fail(OVIRT_IS_PROXY(proxy));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
-
- call = REST_PROXY_CALL(ovirt_action_rest_call_new(REST_PROXY(proxy)));
- if (method != NULL) {
- rest_proxy_call_set_method(call, method);
- }
- href = ovirt_utils_strip_api_base_dir(href);
- rest_proxy_call_set_function(call, href);
- /* FIXME: to set or not to set ?? */
- rest_proxy_call_add_header(call, "All-Content", "true");
+ g_object_get(G_OBJECT(call), "proxy", &proxy, NULL);
+ g_return_if_fail(OVIRT_IS_PROXY(proxy));
data = g_slice_new0(OvirtProxyCallAsyncData);
- data->proxy = g_object_ref(proxy);
+ data->proxy = proxy;
data->result = result;
data->call_async_cb = callback;
data->call_user_data = user_data;
@@ -259,7 +271,8 @@ void ovirt_rest_call_async(OvirtProxy *proxy,
call, NULL);
}
- if (!rest_proxy_call_async(call, call_async_cb, NULL, data, &error)) {
+ if (!rest_proxy_call_async(REST_PROXY_CALL(call), call_async_cb, NULL,
+ data, &error)) {
g_warning("Error while getting collection XML");
g_simple_async_result_set_from_error(result, error);
g_simple_async_result_complete(result);
@@ -268,6 +281,7 @@ void ovirt_rest_call_async(OvirtProxy *proxy,
}
}
+
gboolean ovirt_rest_call_finish(GAsyncResult *result, GError **err)
{
GSimpleAsyncResult *simple;
@@ -333,13 +347,17 @@ void ovirt_proxy_get_collection_xml_async(OvirtProxy *proxy,
GDestroyNotify destroy_func)
{
OvirtProxyGetCollectionAsyncData *data;
+ OvirtRestCall *call;
data = g_slice_new0(OvirtProxyGetCollectionAsyncData);
data->parser = callback;
data->user_data = user_data;
data->destroy_user_data = destroy_func;
- ovirt_rest_call_async(proxy, "GET", href, result, cancellable,
+ call = ovirt_rest_call_new(proxy, "GET", href);
+
+
+ ovirt_rest_call_async(call, result, cancellable,
get_collection_xml_async_cb, data,
(GDestroyNotify)ovirt_proxy_get_collection_async_data_destroy);
}
diff --git a/govirt/ovirt-resource-private.h b/govirt/ovirt-resource-private.h
index d0983f8..c026014 100644
--- a/govirt/ovirt-resource-private.h
+++ b/govirt/ovirt-resource-private.h
@@ -23,14 +23,14 @@
#define __OVIRT_RESOURCE_PRIVATE_H__
#include <ovirt-resource.h>
+#include <ovirt-rest-call.h>
G_BEGIN_DECLS
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, GError **error);
+gboolean ovirt_resource_rest_call_sync(OvirtRestCall *call, GError **error);
G_END_DECLS
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index d32b2bf..d28df6c 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -472,37 +472,46 @@ char *ovirt_resource_to_xml(OvirtResource *resource)
}
-G_GNUC_INTERNAL gboolean ovirt_resource_rest_call(OvirtResource *resource,
- OvirtProxy *proxy,
- const char *method,
- GError **error)
+G_GNUC_INTERNAL gboolean ovirt_resource_rest_call_sync(OvirtRestCall *call,
+ GError **error)
{
- RestProxyCall *call;
-
- call = REST_PROXY_CALL(ovirt_resource_rest_call_new(REST_PROXY(proxy), resource));
- rest_proxy_call_set_method(call, method);
- rest_proxy_call_add_param(call, "async", "false");
-
- if (!rest_proxy_call_sync(call, error)) {
+ if (!rest_proxy_call_sync(REST_PROXY_CALL(call), error)) {
RestXmlNode *root;
GError *local_error = NULL;
- root = ovirt_rest_xml_node_from_call(call);
+ root = ovirt_rest_xml_node_from_call(REST_PROXY_CALL(call));
ovirt_utils_gerror_from_xml_fault(root, &local_error);
if (local_error != NULL) {
g_clear_error(error);
+ g_warning("Error while updating resource");
+ g_warning("message: %s", local_error->message);
g_propagate_error(error, local_error);
}
- g_warning("Error while updating %p", resource);
- g_warning("message: %s", (*error)->message);
- g_object_unref(G_OBJECT(call));
return FALSE;
}
+ return TRUE;
+}
+
+
+static gboolean ovirt_resource_rest_call(OvirtResource *resource,
+ OvirtProxy *proxy,
+ const char *method,
+ GError **error)
+{
+ OvirtRestCall *call;
+ gboolean success;
+
+ call = OVIRT_REST_CALL(ovirt_resource_rest_call_new(REST_PROXY(proxy),
+ resource));
+ rest_proxy_call_set_method(REST_PROXY_CALL(call), method);
+
+ success = ovirt_resource_rest_call_sync(call, error);
+
g_object_unref(G_OBJECT(call));
- return TRUE;
+ return success;
}
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
index 07acf29..3032d34 100644
--- a/govirt/ovirt-vm.c
+++ b/govirt/ovirt-vm.c
@@ -219,6 +219,7 @@ ovirt_vm_invoke_action_async(OvirtVm *vm,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ OvirtRestCall *call;
GSimpleAsyncResult *result;
const char *function;
OvirtVmInvokeActionData *data;
@@ -239,7 +240,9 @@ ovirt_vm_invoke_action_async(OvirtVm *vm,
data->vm = vm;
data->parser = response_parser;
- ovirt_rest_call_async(proxy, "POST", function, result, cancellable,
+ call = ovirt_rest_call_new(proxy, "POST", function);
+
+ ovirt_rest_call_async(call, result, cancellable,
ovirt_vm_invoke_action_async_cb, data,
(GDestroyNotify)ovirt_vm_invoke_action_data_free);
}
@@ -515,6 +518,7 @@ void ovirt_vm_refresh_async(OvirtVm *vm, OvirtProxy *proxy,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ OvirtRestCall *call;
GSimpleAsyncResult *result;
char *href;
@@ -526,7 +530,8 @@ void ovirt_vm_refresh_async(OvirtVm *vm, OvirtProxy *proxy,
user_data,
ovirt_vm_refresh_async);
g_object_get(G_OBJECT(vm), "href", &href, NULL);
- ovirt_rest_call_async(proxy, "GET", href, result, cancellable,
+ call = ovirt_rest_call_new(proxy, "GET", href);
+ ovirt_rest_call_async(call, result, cancellable,
ovirt_vm_refresh_async_cb, vm, NULL);
g_free(href);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]