From: "Daniel P. Berrange" <berrange(a)redhat.com>
Enable apps to determine the current source path of a chardev
with a pty based source.
---
.../libvirt-gconfig-domain-chardev-source-pty.c | 23 +++++++++++++++++++++
.../libvirt-gconfig-domain-chardev-source-pty.h | 2 ++
.../libvirt-gconfig-domain-chardev-source.c | 21 +++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-chardev.c | 24 ++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-chardev.h | 3 +++
libvirt-gconfig/libvirt-gconfig-object-private.h | 2 ++
libvirt-gconfig/libvirt-gconfig-object.c | 8 ++++++++
libvirt-gconfig/libvirt-gconfig.sym | 3 +++
8 files changed, 86 insertions(+)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c
b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c
index d24385e..a965417 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c
@@ -24,6 +24,7 @@
#include "libvirt-gconfig/libvirt-gconfig.h"
#include "libvirt-gconfig/libvirt-gconfig-private.h"
+#include "libvirt-gconfig/libvirt-gconfig-domain-chardev-source-private.h"
#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_PTY,
GVirConfigDomainChardevSourcePtyPrivate))
@@ -82,6 +83,19 @@ GVirConfigDomainChardevSourcePty
*gvir_config_domain_chardev_source_pty_new_from
return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(object);
}
+GVirConfigDomainChardevSource *
+gvir_config_domain_chardev_source_pty_new_from_tree(GVirConfigXmlDoc *doc,
+ xmlNodePtr tree)
+{
+ GVirConfigObject *object;
+
+ object =
gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_PTY,
+ doc, NULL, tree);
+
+ return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(object);
+}
+
+
void gvir_config_domain_chardev_source_pty_set_path(GVirConfigDomainChardevSourcePty
*pty,
const char *path)
{
@@ -92,3 +106,12 @@ void
gvir_config_domain_chardev_source_pty_set_path(GVirConfigDomainChardevSourc
"path",
path);
}
+
+
+const gchar *
gvir_config_domain_chardev_source_pty_get_path(GVirConfigDomainChardevSourcePty *pty)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE_PTY(pty), NULL);
+
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(pty),
+ "source", "path");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h
b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h
index 96e05bc..fab3811 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h
@@ -65,6 +65,8 @@ GVirConfigDomainChardevSourcePty
*gvir_config_domain_chardev_source_pty_new_from
void gvir_config_domain_chardev_source_pty_set_path(GVirConfigDomainChardevSourcePty
*pty,
const char *path);
+const gchar *
gvir_config_domain_chardev_source_pty_get_path(GVirConfigDomainChardevSourcePty *pty);
+
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_PTY_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c
b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c
index c34a3c8..bbb4c75 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c
@@ -23,6 +23,8 @@
#include <config.h>
#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+#include "libvirt-gconfig/libvirt-gconfig-domain-chardev-source-private.h"
#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE,
GVirConfigDomainChardevSourcePrivate))
@@ -47,3 +49,22 @@ static void
gvir_config_domain_chardev_source_init(GVirConfigDomainChardevSource
source->priv = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_GET_PRIVATE(source);
}
+
+G_GNUC_INTERNAL GVirConfigDomainChardevSource *
+gvir_config_domain_chardev_source_new_from_tree(GVirConfigXmlDoc *doc,
+ xmlNodePtr tree)
+{
+ const gchar *type;
+
+ g_return_val_if_fail(GVIR_CONFIG_IS_XML_DOC(doc), NULL);
+ g_return_val_if_fail(tree != NULL, NULL);
+ g_return_val_if_fail(tree->name != NULL, NULL);
+
+ type = gvir_config_xml_get_attribute_content(tree, "type");
+
+ if (g_str_equal(type, "pty"))
+ return gvir_config_domain_chardev_source_pty_new_from_tree(doc, tree);
+
+ g_debug("Unknown chardev source type: %s", type);
+ return NULL;
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
index e20e597..bdb97dd 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c
@@ -24,6 +24,7 @@
#include "libvirt-gconfig/libvirt-gconfig.h"
#include "libvirt-gconfig/libvirt-gconfig-private.h"
+#include "libvirt-gconfig/libvirt-gconfig-domain-chardev-source-private.h"
#define GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV,
GVirConfigDomainChardevPrivate))
@@ -86,3 +87,26 @@ void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev
*chardev,
prepend_prop(chardev_node, new_attr);
}
}
+
+
+/**
+ * gvir_config_domain_chardev_get_source:
+ * @chardev: a #GVirConfigDomainChardev
+ *
+ * Gets the source for the chardev
+ *
+ * Returns: (transfer full): the chardev source
+ */
+GVirConfigDomainChardevSource *
+gvir_config_domain_chardev_get_source(GVirConfigDomainChardev *chardev)
+{
+ GVirConfigXmlDoc *doc;
+ xmlNodePtr tree;
+
+ doc = gvir_config_object_get_xml_doc(GVIR_CONFIG_OBJECT(chardev));
+ tree = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(chardev));
+
+ return gvir_config_domain_chardev_source_new_from_tree(doc,
+ tree);
+}
+
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
index 23a2f43..7fdccc3 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h
@@ -63,6 +63,9 @@ GType gvir_config_domain_chardev_get_type(void);
void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev *chardev,
GVirConfigDomainChardevSource *source);
+GVirConfigDomainChardevSource *
+gvir_config_domain_chardev_get_source(GVirConfigDomainChardev *chardev);
+
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h
b/libvirt-gconfig/libvirt-gconfig-object-private.h
index 9baac66..2ec358b 100644
--- a/libvirt-gconfig/libvirt-gconfig-object-private.h
+++ b/libvirt-gconfig/libvirt-gconfig-object-private.h
@@ -30,6 +30,8 @@ GVirConfigObject *gvir_config_object_new_from_tree(GType type,
GVirConfigXmlDoc *doc,
const char *schema,
xmlNodePtr tree);
+
+GVirConfigXmlDoc *gvir_config_object_get_xml_doc(GVirConfigObject *config);
xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config);
const char *gvir_config_object_get_node_content(GVirConfigObject *object,
const char *node_name);
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c
b/libvirt-gconfig/libvirt-gconfig-object.c
index 9e3b5f2..8971a5b 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -274,6 +274,14 @@ const gchar *gvir_config_object_get_schema(GVirConfigObject *config)
return config->priv->schema;
}
+
+G_GNUC_INTERNAL GVirConfigXmlDoc *
+gvir_config_object_get_xml_doc(GVirConfigObject *config)
+{
+ return config->priv->doc;
+}
+
+
/* FIXME: will we always have one xmlNode per GConfig object? */
/* FIXME: need to return the right node from subclasses */
/* NB: the xmlNodePtr must not be freed by the caller */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index f8c7cdd..2847570 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -557,6 +557,9 @@ LIBVIRT_GCONFIG_0.1.7 {
gvir_config_storage_pool_target_get_path;
gvir_config_storage_pool_target_get_permissions;
+
+ gvir_config_domain_chardev_source_pty_get_path;
+ gvir_config_domain_chardev_get_source;
} LIBVIRT_GCONFIG_0.1.6;
# .... define new API here using predicted next version number ....
--
1.8.2.1