|
|
7cfb7a |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
7cfb7a |
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
|
|
|
7cfb7a |
Date: Thu, 13 Jul 2017 16:56:34 -0300
|
|
|
7cfb7a |
Subject: [PATCH] Introduce ovirt_resource_new*() functions
|
|
|
7cfb7a |
|
|
|
7cfb7a |
These functions should be used to replace usage of g_initable_new()
|
|
|
7cfb7a |
around the codebase, as it avoids code duplication by combining all
|
|
|
7cfb7a |
different ways of creating a resource in a single function.
|
|
|
7cfb7a |
|
|
|
7cfb7a |
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
|
|
|
7cfb7a |
---
|
|
|
7cfb7a |
govirt/ovirt-resource-private.h | 4 +++
|
|
|
7cfb7a |
govirt/ovirt-resource.c | 47 +++++++++++++++++++++++++++++++++
|
|
|
7cfb7a |
2 files changed, 51 insertions(+)
|
|
|
7cfb7a |
|
|
|
7cfb7a |
diff --git a/govirt/ovirt-resource-private.h b/govirt/ovirt-resource-private.h
|
|
|
7cfb7a |
index ff4e705..ef47557 100644
|
|
|
7cfb7a |
--- a/govirt/ovirt-resource-private.h
|
|
|
7cfb7a |
+++ b/govirt/ovirt-resource-private.h
|
|
|
7cfb7a |
@@ -27,6 +27,10 @@
|
|
|
7cfb7a |
|
|
|
7cfb7a |
G_BEGIN_DECLS
|
|
|
7cfb7a |
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new(GType type);
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new_from_id(GType type, const char *id, const char *href);
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new_from_xml(GType type, RestXmlNode *node, GError **error);
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
const char *ovirt_resource_get_action(OvirtResource *resource,
|
|
|
7cfb7a |
const char *action);
|
|
|
7cfb7a |
char *ovirt_resource_to_xml(OvirtResource *resource);
|
|
|
7cfb7a |
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
|
|
|
7cfb7a |
index 7f79ab7..1413a77 100644
|
|
|
7cfb7a |
--- a/govirt/ovirt-resource.c
|
|
|
7cfb7a |
+++ b/govirt/ovirt-resource.c
|
|
|
7cfb7a |
@@ -1065,3 +1065,50 @@ gboolean ovirt_resource_delete_finish(OvirtResource *resource,
|
|
|
7cfb7a |
|
|
|
7cfb7a |
return ovirt_rest_call_finish(result, err);
|
|
|
7cfb7a |
}
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+static OvirtResource *ovirt_resource_new_valist(GType type, GError **error, const char *prop_name, ...)
|
|
|
7cfb7a |
+{
|
|
|
7cfb7a |
+ gpointer resource;
|
|
|
7cfb7a |
+ va_list var_args;
|
|
|
7cfb7a |
+ GError *local_error = NULL;
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ g_return_val_if_fail(g_type_is_a(type, OVIRT_TYPE_RESOURCE), NULL);
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ va_start(var_args, prop_name);
|
|
|
7cfb7a |
+ resource = g_initable_new_valist(type, prop_name, var_args, NULL, &local_error);
|
|
|
7cfb7a |
+ va_end(var_args);
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ if (local_error != NULL) {
|
|
|
7cfb7a |
+ g_warning("Failed to create resource of type %s: %s", g_type_name(type), local_error->message);
|
|
|
7cfb7a |
+ g_propagate_error(error, local_error);
|
|
|
7cfb7a |
+ }
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ return OVIRT_RESOURCE(resource);
|
|
|
7cfb7a |
+}
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+G_GNUC_INTERNAL
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new(GType type)
|
|
|
7cfb7a |
+{
|
|
|
7cfb7a |
+ return ovirt_resource_new_valist(type, NULL, NULL);
|
|
|
7cfb7a |
+}
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+G_GNUC_INTERNAL
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new_from_id(GType type, const char *id, const char *href)
|
|
|
7cfb7a |
+{
|
|
|
7cfb7a |
+ g_return_val_if_fail(id != NULL, NULL);
|
|
|
7cfb7a |
+ g_return_val_if_fail(href != NULL, NULL);
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ return ovirt_resource_new_valist(type, NULL, "guid", id, "href", href, NULL);
|
|
|
7cfb7a |
+}
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+G_GNUC_INTERNAL
|
|
|
7cfb7a |
+OvirtResource *ovirt_resource_new_from_xml(GType type, RestXmlNode *node, GError **error)
|
|
|
7cfb7a |
+{
|
|
|
7cfb7a |
+ g_return_val_if_fail(node != NULL, NULL);
|
|
|
7cfb7a |
+
|
|
|
7cfb7a |
+ return ovirt_resource_new_valist(type, error, "xml-node", node, NULL);
|
|
|
7cfb7a |
+}
|