[libvirt-glib 11/13] Return a GVirConfigObject from gvir_config_object_add_child

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

 



This makes it possible to use the other GVirConfigObject helpers
with the new child, and hides libxml from one more place in our API.
---
 libvirt-gconfig/libvirt-gconfig-domain-disk.c    |   29 ++++++++++++----------
 libvirt-gconfig/libvirt-gconfig-object-private.h |    4 +-
 libvirt-gconfig/libvirt-gconfig-object.c         |   13 +++++++--
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index dfdb381..0c42384 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -142,44 +142,47 @@ void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk,
 void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk,
                                              const char *driver_name)
 {
-    xmlNodePtr node;
+    GVirConfigObject *node;
 
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
     node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "driver");
-    g_return_if_fail(node != NULL);
-    xmlNewProp(node, (xmlChar*)"name", (xmlChar*)driver_name);
-
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "name", driver_name, NULL);
+    g_object_unref(G_OBJECT(node));
 }
 
 void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk,
                                              const char *driver_type)
 {
-    xmlNodePtr node;
+    GVirConfigObject *node;
 
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
     node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "driver");
-    g_return_if_fail(node != NULL);
-    xmlNewProp(node, (xmlChar*)"type", (xmlChar*)driver_type);
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "type", driver_type, NULL);
+    g_object_unref(G_OBJECT(node));
 }
 
 void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk,
                                             const char *bus)
 {
-    xmlNodePtr node;
+    GVirConfigObject *node;
 
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
     node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "target");
-    g_return_if_fail(node != NULL);
-    xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus);
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "bus", bus, NULL);
+    g_object_unref(G_OBJECT(node));
 }
 
 void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
                                             const char *dev)
 {
-    xmlNodePtr node;
+    GVirConfigObject *node;
 
     g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk));
     node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(disk), "target");
-    g_return_if_fail(node != NULL);
-    xmlNewProp(node, (xmlChar*)"dev", (xmlChar*)dev);
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "dev", dev, NULL);
+    g_object_unref(G_OBJECT(node));
 }
diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gconfig/libvirt-gconfig-object-private.h
index 071d45c..8f9b943 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -35,8 +35,8 @@ void gvir_config_object_set_node_content(GVirConfigObject *object,
 void gvir_config_object_set_node_content_uint64(GVirConfigObject *object,
                                                 const char *node_name,
                                                 guint64 value);
-xmlNodePtr gvir_config_object_add_child(GVirConfigObject *object,
-                                        const char *child_name);
+GVirConfigObject *gvir_config_object_add_child(GVirConfigObject *object,
+                                               const char *child_name);
 xmlNodePtr gvir_config_object_replace_child(GVirConfigObject *object,
                                             const char *child_name);
 void gvir_config_object_set_child(GVirConfigObject *object,
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 67507d8..70d0608 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -341,7 +341,7 @@ gvir_config_object_set_child(GVirConfigObject *object, xmlNodePtr child)
     gvir_config_object_set_child_internal(object, child, TRUE);
 }
 
-G_GNUC_INTERNAL xmlNodePtr
+G_GNUC_INTERNAL GVirConfigObject *
 gvir_config_object_add_child(GVirConfigObject *object,
                              const char *child_name)
 {
@@ -349,16 +349,23 @@ gvir_config_object_add_child(GVirConfigObject *object,
     xmlNodePtr old_node;
 
     g_return_val_if_fail(GVIR_IS_CONFIG_OBJECT(object), NULL);
+    g_return_val_if_fail(child_name != NULL, NULL);
 
     new_node = xmlNewDocNode(NULL, NULL, (xmlChar *)child_name, NULL);
     old_node = gvir_config_object_set_child_internal(object, new_node,
                                                      FALSE);
     if (old_node != NULL) {
         xmlFreeNode(new_node);
-        return old_node;
+        return GVIR_CONFIG_OBJECT(g_object_new(GVIR_TYPE_CONFIG_OBJECT,
+                                               "doc", object->priv->doc,
+                                               "node", old_node,
+                                               NULL));
     }
 
-    return new_node;
+    return GVIR_CONFIG_OBJECT(g_object_new(GVIR_TYPE_CONFIG_OBJECT,
+                                           "doc", object->priv->doc,
+                                           "node", new_node,
+                                           NULL));
 }
 
 G_GNUC_INTERNAL xmlNodePtr
-- 
1.7.7.3

--
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]