[libvirt-glib 18/23] Add gvir_config_object_get_node_content

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

 



There will be quite a few getter functions returning a string
contained in one of the nodes of a GVirConfigObject, so better to
make it a one-liner to achieve this.
---
 libvirt-gconfig/libvirt-gconfig-domain.c |    9 ++-------
 libvirt-gconfig/libvirt-gconfig-object.c |   12 ++++++++++++
 libvirt-gconfig/libvirt-gconfig-object.h |    2 ++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 210b3fa..66ea7cb 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -140,13 +140,8 @@ GVirConfigDomain *gvir_config_domain_new(void)
 
 char *gvir_config_domain_get_name(GVirConfigDomain *domain)
 {
-    xmlNodePtr node;
-
-    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain));
-    if (node == NULL)
-        return NULL;
-
-    return gvir_config_xml_get_child_element_content_glib(node, "name");
+    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(domain),
+                                               "name");
 }
 
 void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name)
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 6fd5473..8855ff8 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -280,3 +280,15 @@ xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config)
 {
     return config->priv->node;
 }
+
+char *gvir_config_object_get_node_content(GVirConfigObject *object,
+                                          const char *node_name)
+{
+    xmlNodePtr node;
+
+    node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(object));
+    if (node == NULL)
+        return NULL;
+
+    return gvir_config_xml_get_child_element_content_glib(node, node_name);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h
index 133ca9f..1a82490 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.h
+++ b/libvirt-gconfig/libvirt-gconfig-object.h
@@ -66,6 +66,8 @@ gchar *gvir_config_object_to_xml(GVirConfigObject *config);
 
 const gchar *gvir_config_object_get_schema(GVirConfigObject *config);
 xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config);
+char *gvir_config_object_get_node_content(GVirConfigObject *object,
+                                          const char *node_name);
 
 /* FIXME: move to a libvirt-gconfig-helpers.h file? */
 xmlNodePtr gvir_config_object_parse(const char *xml, const char *root_node, GError **err);
-- 
1.7.6.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]