On Fri, Oct 07, 2011 at 11:40:50AM +0200, Christophe Fergeau wrote: > For now, it's read-only, but is exposed as a gobject property too. > --- > libvirt-gconfig/libvirt-gconfig-domain.c | 50 ++++++++++++++++++++++++++++++ > libvirt-gconfig/libvirt-gconfig-domain.h | 2 + > libvirt-gconfig/libvirt-gconfig.sym | 1 + > 3 files changed, 53 insertions(+), 0 deletions(-) > > diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c > index 4a8911d..125c1ac 100644 > --- a/libvirt-gconfig/libvirt-gconfig-domain.c > +++ b/libvirt-gconfig/libvirt-gconfig-domain.c > @@ -41,11 +41,45 @@ struct _GVirConfigDomainPrivate > > G_DEFINE_TYPE(GVirConfigDomain, gvir_config_domain, GVIR_TYPE_CONFIG_OBJECT); > > +enum { > + PROP_0, > + PROP_NAME, > +}; > + > +static void gvir_config_domain_get_property(GObject *object, > + guint prop_id, > + GValue *value, > + GParamSpec *pspec) > +{ > + GVirConfigDomain *domain = GVIR_CONFIG_DOMAIN(object); > + > + switch (prop_id) { > + case PROP_NAME: > + g_value_take_string(value, gvir_config_domain_get_name(domain)); > + break; > + > + default: > + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); > + } > +} > + > > static void gvir_config_domain_class_init(GVirConfigDomainClass *klass) > { > + GObjectClass *object_class = G_OBJECT_CLASS(klass); > > g_type_class_add_private(klass, sizeof(GVirConfigDomainPrivate)); > + > + object_class->get_property = gvir_config_domain_get_property; > + > + g_object_class_install_property(object_class, > + PROP_NAME, > + g_param_spec_string("name", > + "Name", > + "Domain Name", > + NULL, > + G_PARAM_READABLE | > + G_PARAM_STATIC_STRINGS)); > } > > > @@ -68,3 +102,19 @@ GVirConfigDomain *gvir_config_domain_new(const gchar *xml) > "schema", DATADIR "/libvirt/schemas/domain.rng", > NULL)); > } > + > +/* FIXME: do we add a GError ** to all getters in case there's an XML > + * parsing error? Doesn't work with gobject properties > + * => have a function to test if an error has occurred a la cairo? > + */ I think it is reasonable to declare that the getters are not allowed to be accessed after a parsing failure. The app will be able to get back the parsing errors, at time of parse if they want them > +char *gvir_config_domain_get_name(GVirConfigDomain *domain) > +{ > + xmlNodePtr node; > + > + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain), NULL); > + if (node == NULL) > + return NULL; > + > + return gvir_config_xml_get_child_element_content_glib(node, "name"); > + > +} 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