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

[libvirt] [libvirt-glib 08/23] Implement gvir_config_domain_set_name



---
 libvirt-gconfig/libvirt-gconfig-domain.c |   27 +++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.h |    1 +
 libvirt-gconfig/libvirt-gconfig.sym      |    1 +
 3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 7ae10b8..06fc3fa 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -130,3 +130,30 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain)
     return gvir_config_xml_get_child_element_content_glib(node, "name");
 
 }
+
+void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name)
+{
+    xmlNodePtr parent_node;
+    xmlNodePtr old_node;
+    xmlNodePtr new_node;
+    xmlChar *encoded_name;
+
+    parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain),
+                                                  NULL);
+    encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc,
+                                              (xmlChar *)name);
+    new_node = xmlNewDocNode(parent_node->doc, NULL,
+                             (xmlChar *)"name", encoded_name);
+    xmlFree(encoded_name);
+
+    old_node = gvir_config_xml_get_element(parent_node, "name", NULL);
+
+    if (old_node) {
+        old_node = xmlReplaceNode(old_node, new_node);
+        xmlFreeNode(old_node);
+    } else {
+        xmlAddChild(parent_node, new_node);
+    }
+
+    g_object_notify(G_OBJECT(domain), "name");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index baa94c6..f6ceef1 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -63,6 +63,7 @@ GVirConfigDomain *gvir_config_domain_new_from_xml(const gchar *xml);
 GVirConfigDomain *gvir_config_domain_new(void);
 
 char *gvir_config_domain_get_name(GVirConfigDomain *domain);
+void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 8702a76..2571c05 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -7,6 +7,7 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_domain_new;
 	gvir_config_domain_new_from_xml;
 	gvir_config_domain_get_name;
+	gvir_config_domain_set_name;
 
 	gvir_config_domain_snapshot_get_type;
 	gvir_config_domain_snapshot_new;
-- 
1.7.6.4


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