On Fri, Oct 07, 2011 at 11:41:08AM +0200, Christophe Fergeau wrote: > --- > libvirt-gconfig/libvirt-gconfig-domain.c | 71 ++++++++++++++++++++++++++++ > libvirt-gconfig/libvirt-gconfig-domain.h | 4 ++ > libvirt-gconfig/libvirt-gconfig.sym | 2 + > libvirt-gconfig/tests/test-domain-create.c | 12 +++++ > libvirt-gconfig/tests/test-domain-parse.c | 7 +++ > libvirt-gconfig/tests/test-domain.xml | 1 + > 6 files changed, 97 insertions(+), 0 deletions(-) > > diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c > index 71bfb55..4a32595 100644 > --- a/libvirt-gconfig/libvirt-gconfig-domain.c > +++ b/libvirt-gconfig/libvirt-gconfig-domain.c > @@ -45,6 +45,7 @@ enum { > PROP_0, > PROP_NAME, > PROP_MEMORY, > + PROP_FEATURES > }; > > static void gvir_config_domain_get_property(GObject *object, > @@ -61,6 +62,9 @@ static void gvir_config_domain_get_property(GObject *object, > case PROP_MEMORY: > g_value_set_uint64(value, gvir_config_domain_get_memory(domain)); > break; > + case PROP_FEATURES: > + g_value_take_boxed(value, gvir_config_domain_get_features(domain)); > + break; > > default: > G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); > @@ -81,6 +85,9 @@ static void gvir_config_domain_set_property(GObject *object, > case PROP_MEMORY: > gvir_config_domain_set_memory(domain, g_value_get_uint64(value)); > break; > + case PROP_FEATURES: > + gvir_config_domain_set_features(domain, g_value_get_boxed(value)); > + break; > default: > G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); > } > @@ -113,6 +120,14 @@ static void gvir_config_domain_class_init(GVirConfigDomainClass *klass) > 0, > G_PARAM_READWRITE | > G_PARAM_STATIC_STRINGS)); > + g_object_class_install_property(object_class, > + PROP_FEATURES, > + g_param_spec_boxed("features", > + "Features", > + "Hypervisor Features", > + G_TYPE_STRV, > + G_PARAM_READWRITE | > + G_PARAM_STATIC_STRINGS)); > } > > > @@ -179,3 +194,59 @@ void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory) > "memory", memory); > g_object_notify(G_OBJECT(domain), "memory"); > } > + > +/** > + * gvir_config_domain_get_features: > + * Returns: (transfer full): > + */ > +GStrv gvir_config_domain_get_features(GVirConfigDomain *domain) > +{ > + GPtrArray *features; > + xmlNodePtr parent_node; > + xmlNodePtr node; > + xmlNodePtr it; > + > + parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain)); > + if (parent_node == NULL) > + return NULL; > + > + node = gvir_config_xml_get_element(parent_node, "features", NULL); > + if (node == NULL) > + return NULL; > + > + features = g_ptr_array_new(); > + for (it = node->children; it != NULL; it = it->next) { > + g_ptr_array_add(features, g_strdup((char *)it->name)); > + } > + g_ptr_array_add(features, NULL); > + > + return (GStrv)g_ptr_array_free(features, FALSE); > +} > + > +void gvir_config_domain_set_features(GVirConfigDomain *domain, > + const GStrv features) > +{ > + xmlNodePtr parent_node; > + xmlNodePtr features_node; > + xmlNodePtr old_node; > + GStrv it; > + > + parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain)); > + features_node = xmlNewDocNode(parent_node->doc, NULL, > + (xmlChar *)"features", NULL); > + for (it = features; *it != NULL; it++) { > + xmlNodePtr node; > + > + node = xmlNewDocNode(parent_node->doc, NULL, (xmlChar *)*it, NULL); > + xmlAddChild(features_node, node); > + } > + > + old_node = gvir_config_xml_get_element(parent_node, "features", NULL); > + if (old_node) { > + old_node = xmlReplaceNode(old_node, features_node); > + xmlFreeNode(old_node); > + } else { > + xmlAddChild(parent_node, features_node); > + } > + g_object_notify(G_OBJECT(domain), "features"); > +} > diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h > index 03169b2..d9f0c09 100644 > --- a/libvirt-gconfig/libvirt-gconfig-domain.h > +++ b/libvirt-gconfig/libvirt-gconfig-domain.h > @@ -66,6 +66,10 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain); > void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name); > guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain); > void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory); > +GStrv gvir_config_domain_get_features(GVirConfigDomain *domain); > +void gvir_config_domain_set_features(GVirConfigDomain *domain, > + const GStrv features); > + > > G_END_DECLS > > diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym > index 7acb95d..951aac6 100644 > --- a/libvirt-gconfig/libvirt-gconfig.sym > +++ b/libvirt-gconfig/libvirt-gconfig.sym > @@ -6,6 +6,8 @@ LIBVIRT_GOBJECT_0.0.1 { > gvir_config_domain_get_type; > gvir_config_domain_new; > gvir_config_domain_new_from_xml; > + gvir_config_domain_get_features; > + gvir_config_domain_set_features; > gvir_config_domain_get_memory; > gvir_config_domain_set_memory; > gvir_config_domain_get_name; > diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c > index fe0063c..a719ed2 100644 > --- a/libvirt-gconfig/tests/test-domain-create.c > +++ b/libvirt-gconfig/tests/test-domain-create.c > @@ -28,10 +28,14 @@ > #include <string.h> > #include <libvirt-gconfig/libvirt-gconfig.h> > > +const char *features[] = { "foo", "bar", "baz", NULL }; > + > int main(void) > { > GVirConfigDomain *domain; > char *name; > + GStrv feat; > + unsigned int i; > char *xml; > > g_type_init(); > @@ -47,6 +51,14 @@ int main(void) > gvir_config_domain_set_memory(domain, 1234); > g_assert(gvir_config_domain_get_memory(domain) == 1234); > > + gvir_config_domain_set_features(domain, (const GStrv)features); > + feat = gvir_config_domain_get_features(domain); > + for (i = 0; features[i] != NULL; i++) { > + g_assert(feat[i] != NULL); > + g_assert(strcmp(feat[i], features[i]) == 0); > + } > + g_strfreev(feat); > + > xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); > g_print("%s\n", xml); > g_free(xml); > diff --git a/libvirt-gconfig/tests/test-domain-parse.c b/libvirt-gconfig/tests/test-domain-parse.c > index 7521d20..9528816 100644 > --- a/libvirt-gconfig/tests/test-domain-parse.c > +++ b/libvirt-gconfig/tests/test-domain-parse.c > @@ -33,6 +33,7 @@ int main(int argc, char **argv) > { > GVirConfigDomain *domain; > char *name; > + GStrv features; > char *xml; > GError *error = NULL; > > @@ -69,6 +70,12 @@ int main(int argc, char **argv) > > g_assert(gvir_config_domain_get_memory(domain) == 987654321); > > + features = gvir_config_domain_get_features(domain); > + g_assert(g_strv_length(features) == 2); > + g_assert(strcmp(features[0], "f1") == 0); > + g_assert(strcmp(features[1], "f2") == 0); > + g_strfreev(features); > + > g_free(xml); > > xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(domain)); > diff --git a/libvirt-gconfig/tests/test-domain.xml b/libvirt-gconfig/tests/test-domain.xml > index d887e95..a9610cc 100644 > --- a/libvirt-gconfig/tests/test-domain.xml > +++ b/libvirt-gconfig/tests/test-domain.xml > @@ -2,5 +2,6 @@ > <name>foo</name> > <uuid>4dea22b31d52d8f32516782e98ab3fa0</uuid> > <description>Some human readable description</description> > + <features><f1/><f2/></features> > <memory>987654321</memory> > </domain> ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list