[libvirt-glib PATCHv2 3/5] Implement gvir_config_domain_chardev_add_source

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

 



This is used to associate a ChardevSource (pty, file, ...) with a
Chardev (console, serial, ...).
---
 libvirt-gconfig/libvirt-gconfig-domain-chardev.c |   40 ++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-chardev.h |    4 ++
 libvirt-gconfig/libvirt-gconfig.sym              |    1 +
 3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
index 525fc2b..ffa9964 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
@@ -23,6 +23,7 @@
 #include <config.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-object-private.h"
 
 #define GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardevPrivate))
@@ -46,3 +47,42 @@ static void gvir_config_domain_chardev_init(GVirConfigDomainChardev *chardev)
 
     chardev->priv = GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(chardev);
 }
+
+static void prepend_prop(xmlNodePtr node, xmlAttrPtr prop)
+{
+    if (node->properties == NULL) {
+        node->properties = prop;
+    } else {
+        prop->next = node->properties;
+        node->properties->prev = prop;
+        node->properties = prop;
+    }
+}
+
+void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev *chardev,
+                                           GVirConfigDomainChardevSource *source)
+{
+    xmlNodePtr chardev_node;
+    xmlNodePtr source_node;
+    xmlNodePtr child;
+    xmlAttrPtr attr;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CHARDEV(chardev));
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE(source));
+
+    chardev_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(chardev));
+    source_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(source));
+
+    g_return_if_fail((chardev_node != NULL) && (source_node != NULL));
+
+    for (child = source_node->children; child != NULL; child = child->next) {
+        xmlUnlinkNode(child);
+        xmlAddChild(chardev_node, child);
+    }
+
+    for (attr = source_node->properties; attr != NULL; attr = attr->next) {
+        xmlAttrPtr new_attr;
+        new_attr = xmlCopyProp(chardev_node, attr);
+        prepend_prop(chardev_node, new_attr);
+    }
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
index 91b7f4e..456c97a 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
@@ -27,6 +27,8 @@
 #ifndef __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__
 #define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__
 
+#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h>
+
 G_BEGIN_DECLS
 
 #define GVIR_TYPE_CONFIG_DOMAIN_CHARDEV            (gvir_config_domain_chardev_get_type ())
@@ -58,6 +60,8 @@ struct _GVirConfigDomainChardevClass
 
 
 GType gvir_config_domain_chardev_get_type(void);
+void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev *chardev,
+                                           GVirConfigDomainChardevSource *source);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index c337b58..6249730 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -30,6 +30,7 @@ LIBVIRT_GCONFIG_0.0.1 {
 	gvir_config_domain_virt_type_get_type;
 
 	gvir_config_domain_chardev_get_type;
+	gvir_config_domain_chardev_set_source;
 
 	gvir_config_domain_chardev_source_get_type;
 
-- 
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]