[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [libvirt-glib 08/23] Implement gvir_config_domain_set_name



On Fri, Oct 07, 2011 at 11:40:53AM +0200, Christophe Fergeau wrote:
> ---
>  libvirt-gconfig/libvirt-gconfig-domain.c |   27 +++++++++++++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig-domain.h |    1 +
>  libvirt-gconfig/libvirt-gconfig.sym      |    1 +
>  3 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
> index 7ae10b8..06fc3fa 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain.c
> @@ -130,3 +130,30 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain)
>      return gvir_config_xml_get_child_element_content_glib(node, "name");
>  
>  }
> +
> +void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name)
> +{
> +    xmlNodePtr parent_node;
> +    xmlNodePtr old_node;
> +    xmlNodePtr new_node;
> +    xmlChar *encoded_name;
> +
> +    parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain),
> +                                                  NULL);
> +    encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc,
> +                                              (xmlChar *)name);
> +    new_node = xmlNewDocNode(parent_node->doc, NULL,
> +                             (xmlChar *)"name", encoded_name);
> +    xmlFree(encoded_name);
> +
> +    old_node = gvir_config_xml_get_element(parent_node, "name", NULL);
> +
> +    if (old_node) {
> +        old_node = xmlReplaceNode(old_node, new_node);
> +        xmlFreeNode(old_node);
> +    } else {
> +        xmlAddChild(parent_node, new_node);
> +    }
> +
> +    g_object_notify(G_OBJECT(domain), "name");
> +}

Perhaps we want another helper method for setting XML elements too.

In python-virtinst, they had a helper which allowed a very simple
xpath like use.eg

   gvir_config_xml_set_element(parent_node, "/name", node);

Or

   gvir_config_xml_set_element(parent_node, "/foo/bar/name", node);

automagically creating foo & bar in the process.

Perhaps even have wrappers to avoid needing to pass in a node
for the value

  gvir_config_xml_set_data_element(parent_node, "/name", "foobar");

And setting NULL terminated list of attributes

  gvir_config_xml_set_element_attrs(parent_node, "/blah",
                                    "someattr", "somevalue",
                                    "otherattr", "othervalue",
                                    NULL);

etc,m 

> diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
> index baa94c6..f6ceef1 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain.h
> +++ b/libvirt-gconfig/libvirt-gconfig-domain.h
> @@ -63,6 +63,7 @@ GVirConfigDomain *gvir_config_domain_new_from_xml(const gchar *xml);
>  GVirConfigDomain *gvir_config_domain_new(void);
>  
>  char *gvir_config_domain_get_name(GVirConfigDomain *domain);
> +void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index 8702a76..2571c05 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -7,6 +7,7 @@ LIBVIRT_GOBJECT_0.0.1 {
>  	gvir_config_domain_new;
>  	gvir_config_domain_new_from_xml;
>  	gvir_config_domain_get_name;
> +	gvir_config_domain_set_name;
>  
>  	gvir_config_domain_snapshot_get_type;
>  	gvir_config_domain_snapshot_new;

ACK to this patch anyway, since convenience helpers can be added later
as desired

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 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]