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? + */ +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"); + +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h index 11161c8..49c34dc 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -61,6 +61,8 @@ GType gvir_config_domain_get_type(void); GVirConfigDomain *gvir_config_domain_new(const gchar *xml); +char *gvir_config_domain_get_name(GVirConfigDomain *domain); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index d20e73b..6127e22 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -5,6 +5,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_get_type; gvir_config_domain_new; + gvir_config_domain_get_name; gvir_config_domain_snapshot_get_type; gvir_config_domain_snapshot_new; -- 1.7.6.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list