[libgovirt] Return XML data from ovirt_resource_rest_call()
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgovirt] Return XML data from ovirt_resource_rest_call()
- Date: Thu, 26 Jun 2014 23:22:00 +0000 (UTC)
commit e3a55b64356bee91a9017faacefa5cb57e1511b6
Author: Christophe Fergeau <cfergeau redhat com>
Date: Thu May 22 16:14:03 2014 +0200
Return XML data from ovirt_resource_rest_call()
In order to implement ovirt_resource_refresh(), we will need the XML
data to parse rather than just a boolean indicating if the call was
successful or not.
govirt/ovirt-cdrom.c | 11 ++++++++---
govirt/ovirt-resource-private.h | 2 +-
govirt/ovirt-resource.c | 39 +++++++++++++++++++++++----------------
3 files changed, 32 insertions(+), 20 deletions(-)
---
diff --git a/govirt/ovirt-cdrom.c b/govirt/ovirt-cdrom.c
index 16ee833..2b8d7a0 100644
--- a/govirt/ovirt-cdrom.c
+++ b/govirt/ovirt-cdrom.c
@@ -190,7 +190,7 @@ gboolean ovirt_cdrom_update(OvirtCdrom *cdrom,
GError **error)
{
OvirtRestCall *call;
- gboolean success;
+ RestXmlNode *root;
call = OVIRT_REST_CALL(ovirt_resource_rest_call_new(REST_PROXY(proxy),
OVIRT_RESOURCE(cdrom)));
@@ -199,11 +199,16 @@ gboolean ovirt_cdrom_update(OvirtCdrom *cdrom,
if (current) {
rest_proxy_call_add_param(REST_PROXY_CALL(call), "current", NULL);
}
- success = ovirt_resource_rest_call_sync(call, error);
+ root = ovirt_resource_rest_call_sync(call, error);
g_object_unref(G_OBJECT(call));
- return success;
+ if (root != NULL) {
+ rest_xml_node_unref(root);
+ return TRUE;
+ }
+
+ return FALSE;
}
diff --git a/govirt/ovirt-resource-private.h b/govirt/ovirt-resource-private.h
index e409920..33e3543 100644
--- a/govirt/ovirt-resource-private.h
+++ b/govirt/ovirt-resource-private.h
@@ -30,7 +30,7 @@ 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_sync(OvirtRestCall *call, GError **error);
+RestXmlNode *ovirt_resource_rest_call_sync(OvirtRestCall *call, GError **error);
typedef gboolean (*ActionResponseParser)(RestXmlNode *node, OvirtResource *resource, GError **error);
gboolean ovirt_resource_action(OvirtResource *resource, OvirtProxy *proxy,
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index c20a88b..172caa3 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -474,11 +474,11 @@ char *ovirt_resource_to_xml(OvirtResource *resource)
}
-G_GNUC_INTERNAL gboolean ovirt_resource_rest_call_sync(OvirtRestCall *call,
- GError **error)
+G_GNUC_INTERNAL RestXmlNode *ovirt_resource_rest_call_sync(OvirtRestCall *call,
+ GError **error)
{
+ RestXmlNode *root = NULL;
if (!rest_proxy_call_sync(REST_PROXY_CALL(call), error)) {
- RestXmlNode *root;
GError *local_error = NULL;
root = ovirt_rest_xml_node_from_call(REST_PROXY_CALL(call));
@@ -489,31 +489,34 @@ G_GNUC_INTERNAL gboolean ovirt_resource_rest_call_sync(OvirtRestCall *call,
g_warning("message: %s", local_error->message);
g_propagate_error(error, local_error);
}
+ if (root != NULL) {
+ rest_xml_node_unref(root);
+ }
- return FALSE;
+ return NULL;
}
- return TRUE;
+ return root;
}
-static gboolean ovirt_resource_rest_call(OvirtResource *resource,
- OvirtProxy *proxy,
- const char *method,
- GError **error)
+static RestXmlNode *ovirt_resource_rest_call(OvirtResource *resource,
+ OvirtProxy *proxy,
+ const char *method,
+ GError **error)
{
OvirtRestCall *call;
- gboolean success;
+ RestXmlNode *root;
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);
+ root = ovirt_resource_rest_call_sync(call, error);
g_object_unref(G_OBJECT(call));
- return success;
+ return root;
}
@@ -521,16 +524,20 @@ gboolean ovirt_resource_update(OvirtResource *resource,
OvirtProxy *proxy,
GError **error)
{
- gboolean call_successful;
+ RestXmlNode *xml;
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);
- call_successful = ovirt_resource_rest_call(resource, proxy,
- "PUT", error);
+ xml = ovirt_resource_rest_call(resource, proxy,
+ "PUT", error);
+ if (xml != NULL) {
+ rest_xml_node_unref(xml);
+ return TRUE;
+ }
- return call_successful;
+ return FALSE;
}
static gboolean ovirt_resource_update_async_cb(OvirtProxy *proxy, RestProxyCall *call,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]