Blame SOURCES/0032-utils-Drop-type-member-from-OvirtXmlElement-struct.patch

7cfb7a
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
7cfb7a
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
7cfb7a
Date: Thu, 18 May 2017 17:21:10 -0300
7cfb7a
Subject: [PATCH] utils: Drop 'type' member from OvirtXmlElement struct
7cfb7a
7cfb7a
Instead of passing the type, it is possible to get it using by calling
7cfb7a
g_object_class_find_property(). All users have been updated accordingly.
7cfb7a
7cfb7a
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
7cfb7a
---
7cfb7a
 govirt/ovirt-cluster.c        | 2 --
7cfb7a
 govirt/ovirt-host.c           | 2 --
7cfb7a
 govirt/ovirt-storage-domain.c | 8 --------
7cfb7a
 govirt/ovirt-utils.c          | 8 ++++++--
7cfb7a
 govirt/ovirt-utils.h          | 1 -
7cfb7a
 govirt/ovirt-vm.c             | 4 ----
7cfb7a
 6 files changed, 6 insertions(+), 19 deletions(-)
7cfb7a
7cfb7a
diff --git a/govirt/ovirt-cluster.c b/govirt/ovirt-cluster.c
7cfb7a
index 4aaf6b1..ae25d63 100644
7cfb7a
--- a/govirt/ovirt-cluster.c
7cfb7a
+++ b/govirt/ovirt-cluster.c
7cfb7a
@@ -115,12 +115,10 @@ static gboolean ovirt_cluster_init_from_xml(OvirtResource *resource,
7cfb7a
     OvirtResourceClass *parent_class;
7cfb7a
     OvirtXmlElement cluster_elements[] = {
7cfb7a
         { .prop_name = "data-center-href",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "data_center",
7cfb7a
           .xml_attr = "href",
7cfb7a
         },
7cfb7a
         { .prop_name = "data-center-id",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "data_center",
7cfb7a
           .xml_attr = "id",
7cfb7a
         },
7cfb7a
diff --git a/govirt/ovirt-host.c b/govirt/ovirt-host.c
7cfb7a
index 191b360..1570cba 100644
7cfb7a
--- a/govirt/ovirt-host.c
7cfb7a
+++ b/govirt/ovirt-host.c
7cfb7a
@@ -116,12 +116,10 @@ static gboolean ovirt_host_init_from_xml(OvirtResource *resource,
7cfb7a
     OvirtResourceClass *parent_class;
7cfb7a
     OvirtXmlElement host_elements[] = {
7cfb7a
         { .prop_name = "cluster-href",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "cluster",
7cfb7a
           .xml_attr = "href",
7cfb7a
         },
7cfb7a
         { .prop_name = "cluster-id",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "cluster",
7cfb7a
           .xml_attr = "id",
7cfb7a
         },
7cfb7a
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
7cfb7a
index 718c1d2..a9078f4 100644
7cfb7a
--- a/govirt/ovirt-storage-domain.c
7cfb7a
+++ b/govirt/ovirt-storage-domain.c
7cfb7a
@@ -153,35 +153,27 @@ static gboolean ovirt_storage_domain_init_from_xml(OvirtResource *resource,
7cfb7a
     OvirtResourceClass *parent_class;
7cfb7a
     OvirtXmlElement storage_domain_elements[] = {
7cfb7a
         { .prop_name = "type",
7cfb7a
-          .type = OVIRT_TYPE_STORAGE_DOMAIN_TYPE,
7cfb7a
           .xml_path = "type",
7cfb7a
         },
7cfb7a
         { .prop_name = "master",
7cfb7a
-          .type = G_TYPE_BOOLEAN,
7cfb7a
           .xml_path = "master",
7cfb7a
         },
7cfb7a
         { .prop_name = "available",
7cfb7a
-          .type = G_TYPE_UINT64,
7cfb7a
           .xml_path = "available",
7cfb7a
         },
7cfb7a
         { .prop_name = "used",
7cfb7a
-          .type = G_TYPE_UINT64,
7cfb7a
           .xml_path = "used",
7cfb7a
         },
7cfb7a
         { .prop_name = "committed",
7cfb7a
-          .type = G_TYPE_UINT64,
7cfb7a
           .xml_path = "committed",
7cfb7a
         },
7cfb7a
         { .prop_name = "version",
7cfb7a
-          .type = OVIRT_TYPE_STORAGE_DOMAIN_FORMAT_VERSION,
7cfb7a
           .xml_path = "storage_format",
7cfb7a
         },
7cfb7a
         { .prop_name = "state",
7cfb7a
-          .type = OVIRT_TYPE_STORAGE_DOMAIN_STATE,
7cfb7a
           .xml_path = "status/state",
7cfb7a
         },
7cfb7a
         { .prop_name = "data-center-ids",
7cfb7a
-          .type = G_TYPE_STRV,
7cfb7a
           .xml_path = "data_centers",
7cfb7a
           .xml_attr = "id",
7cfb7a
         },
7cfb7a
diff --git a/govirt/ovirt-utils.c b/govirt/ovirt-utils.c
7cfb7a
index 1898862..501acb9 100644
7cfb7a
--- a/govirt/ovirt-utils.c
7cfb7a
+++ b/govirt/ovirt-utils.c
7cfb7a
@@ -207,9 +207,13 @@ ovirt_rest_xml_node_parse(RestXmlNode *node,
7cfb7a
 
7cfb7a
     for (;elements->xml_path != NULL; elements++) {
7cfb7a
         GValue value = { 0, };
7cfb7a
+        GParamSpec *prop;
7cfb7a
 
7cfb7a
-        g_value_init(&value, elements->type);
7cfb7a
-        if (_set_property_value_from_type(&value, elements->type, elements->xml_path, elements->xml_attr, node))
7cfb7a
+        prop = g_object_class_find_property(G_OBJECT_GET_CLASS(object), elements->prop_name);
7cfb7a
+        g_return_val_if_fail(prop != NULL, FALSE);
7cfb7a
+
7cfb7a
+        g_value_init(&value, prop->value_type);
7cfb7a
+        if (_set_property_value_from_type(&value, prop->value_type, elements->xml_path, elements->xml_attr, node))
7cfb7a
             g_object_set_property(object, elements->prop_name, &value);
7cfb7a
         g_value_unset(&value);
7cfb7a
     }
7cfb7a
diff --git a/govirt/ovirt-utils.h b/govirt/ovirt-utils.h
7cfb7a
index 545847a..e03f453 100644
7cfb7a
--- a/govirt/ovirt-utils.h
7cfb7a
+++ b/govirt/ovirt-utils.h
7cfb7a
@@ -31,7 +31,6 @@ typedef struct _OvirtXmlElement OvirtXmlElement;
7cfb7a
 struct _OvirtXmlElement
7cfb7a
 {
7cfb7a
     const char *prop_name;
7cfb7a
-    GType type;
7cfb7a
     const char *xml_path;
7cfb7a
     const char *xml_attr; /* if NULL, retrieve node content instead of attribute */
7cfb7a
 };
7cfb7a
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
7cfb7a
index 70b6f3a..36ffd35 100644
7cfb7a
--- a/govirt/ovirt-vm.c
7cfb7a
+++ b/govirt/ovirt-vm.c
7cfb7a
@@ -184,22 +184,18 @@ static gboolean ovirt_vm_init_from_xml(OvirtResource *resource,
7cfb7a
     OvirtResourceClass *parent_class;
7cfb7a
     OvirtXmlElement vm_elements[] = {
7cfb7a
         { .prop_name = "host-href",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "host",
7cfb7a
           .xml_attr = "href",
7cfb7a
         },
7cfb7a
         { .prop_name = "host-id",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "host",
7cfb7a
           .xml_attr = "id",
7cfb7a
         },
7cfb7a
         { .prop_name = "cluster-href",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "cluster",
7cfb7a
           .xml_attr = "href",
7cfb7a
         },
7cfb7a
         { .prop_name = "cluster-id",
7cfb7a
-          .type = G_TYPE_STRING,
7cfb7a
           .xml_path = "cluster",
7cfb7a
           .xml_attr = "id",
7cfb7a
         },