ack
On Wed, Nov 9, 2011 at 9:48 PM, Christophe Fergeau <cfergeau(a)redhat.com> wrote:
This factors the code that is repeated in the _new methods of
all classes deriving from GVirObject
---
libvirt-gconfig/libvirt-gconfig-domain.c | 26 ++++++++++--------------
libvirt-gconfig/libvirt-gconfig-object.c | 31 ++++++++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-object.h | 8 +++++++
libvirt-gconfig/libvirt-gconfig.sym | 1 +
4 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c
b/libvirt-gconfig/libvirt-gconfig-domain.c
index 837287c..3290389 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -147,27 +147,23 @@ static void gvir_config_domain_init(GVirConfigDomain *conn)
GVirConfigDomain *gvir_config_domain_new_from_xml(const gchar *xml,
GError **error)
{
- xmlNodePtr node;
+ GVirConfigObject *object;
- node = gvir_config_xml_parse(xml, "domain", error);
- if ((error != NULL) && (*error != NULL))
- return NULL;
- return GVIR_CONFIG_DOMAIN(g_object_new(GVIR_TYPE_CONFIG_DOMAIN,
- "node", node,
- "schema", DATADIR
"/libvirt/schemas/domain.rng",
- NULL));
+ object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN,
+ "domain",
+ DATADIR
"/libvirt/schemas/domain.rng",
+ xml, error);
+ return GVIR_CONFIG_DOMAIN(object);
}
GVirConfigDomain *gvir_config_domain_new(void)
{
- xmlDocPtr doc;
+ GVirConfigObject *object;
- doc = xmlNewDoc((xmlChar *)"1.0");
- doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"domain", NULL);
- return GVIR_CONFIG_DOMAIN(g_object_new(GVIR_TYPE_CONFIG_DOMAIN,
- "node", doc->children,
- "schema", DATADIR
"/libvirt/schemas/domain.rng",
- NULL));
+ object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN,
+ "domain",
+ DATADIR "/libvirt/schemas/domain.rng");
+ return GVIR_CONFIG_DOMAIN(object);
}
char *gvir_config_domain_get_name(GVirConfigDomain *domain)
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c
b/libvirt-gconfig/libvirt-gconfig-object.c
index e59cbcd..adbd955 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -355,3 +355,34 @@ void gvir_config_object_set_node_content_uint64(GVirConfigObject
*object,
gvir_config_object_set_node_content(object, node_name, str);
g_free(str);
}
+
+GVirConfigObject *gvir_config_object_new_from_xml(GType type,
+ const char *root_name,
+ const char *schema,
+ const gchar *xml,
+ GError **error)
+{
+ xmlNodePtr node;
+
+ node = gvir_config_xml_parse(xml, root_name, error);
+ if ((error != NULL) && (*error != NULL))
+ return NULL;
+ return GVIR_CONFIG_OBJECT(g_object_new(type,
+ "node", node,
+ "schema", schema,
+ NULL));
+}
+
+GVirConfigObject *gvir_config_object_new(GType type,
+ const char *root_name,
+ const char *schema)
+{
+ xmlDocPtr doc;
+
+ doc = xmlNewDoc((xmlChar *)"1.0");
+ doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)root_name, NULL);
+ return GVIR_CONFIG_OBJECT(g_object_new(type,
+ "node", doc->children,
+ "schema", schema,
+ NULL));
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-object.h
b/libvirt-gconfig/libvirt-gconfig-object.h
index c203798..52e4525 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.h
+++ b/libvirt-gconfig/libvirt-gconfig-object.h
@@ -59,6 +59,14 @@ struct _GVirConfigObjectClass
GType gvir_config_object_get_type(void);
+GVirConfigObject *gvir_config_object_new(GType type,
+ const char *root_name,
+ const char *schema);
+GVirConfigObject *gvir_config_object_new_from_xml(GType type,
+ const char *root_name,
+ const char *schema,
+ const gchar *xml,
+ GError **error);
void gvir_config_object_validate(GVirConfigObject *config,
GError **err);
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 951aac6..31a89d2 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -31,6 +31,7 @@ LIBVIRT_GOBJECT_0.0.1 {
gvir_config_object_get_type;
gvir_config_object_error_quark;
gvir_config_object_new;
+ gvir_config_object_new_from_xml;
gvir_config_object_get_schema;
gvir_config_object_get_xml_node;
gvir_config_object_to_xml;
--
1.7.7
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list