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

Re: [libvirt] [libvirt-glib 04/23] Add GVirConfigObject::node property



On Fri, Oct 07, 2011 at 11:40:49AM +0200, Christophe Fergeau wrote:
> This property stores the XML node corresponding to the current
> configuration object in the XML tree. When creating configuration
> objects from a XML string, the XML file will be lazily loaded, and
> this property will be set.
> ---
>  libvirt-gconfig/libvirt-gconfig-object.c |   35 +++++++++++++++++++++++++++--
>  1 files changed, 32 insertions(+), 3 deletions(-)
> 
> diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
> index 52e9be0..762baf9 100644
> --- a/libvirt-gconfig/libvirt-gconfig-object.c
> +++ b/libvirt-gconfig/libvirt-gconfig-object.c
> @@ -43,7 +43,11 @@ struct _GVirConfigObjectPrivate
>      gchar *doc;
>      gchar *schema;
>  
> +    /* FIXME: docHandle is node->doc, can probably be removed to avoid the
> +     * 2 getting out of sync
> +     */
>      xmlDocPtr docHandle;
> +    xmlNodePtr node;
>  };
>  
>  G_DEFINE_ABSTRACT_TYPE(GVirConfigObject, gvir_config_object, G_TYPE_OBJECT);
> @@ -52,6 +56,7 @@ enum {
>      PROP_0,
>      PROP_DOC,
>      PROP_SCHEMA,
> +    PROP_NODE
>  };
>  
>  
> @@ -83,6 +88,10 @@ static void gvir_config_object_get_property(GObject *object,
>          g_value_set_string(value, priv->schema);
>          break;
>  
> +    case PROP_NODE:
> +        g_value_set_pointer(value, gvir_config_object_get_xml_node(conn, NULL));
> +        break;
> +
>      default:
>          G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
>      }
> @@ -108,6 +117,16 @@ static void gvir_config_object_set_property(GObject *object,
>          priv->schema = g_value_dup_string(value);
>          break;
>  
> +    case PROP_NODE:
> +        priv->node = g_value_get_pointer(value);
> +        if ((priv->docHandle != NULL) && (priv->docHandle != priv->node->doc))
> +            xmlFreeDoc(priv->docHandle);
> +        if (priv->node)
> +            priv->docHandle = priv->node->doc;
> +        else
> +            priv->docHandle = NULL;
> +        break;
> +
>      default:
>          G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
>      }
> @@ -164,6 +183,15 @@ static void gvir_config_object_class_init(GVirConfigObjectClass *klass)
>                                                          G_PARAM_STATIC_NICK |
>                                                          G_PARAM_STATIC_BLURB));
>  
> +    g_object_class_install_property(object_class,
> +                                    PROP_NODE,
> +                                    g_param_spec_pointer("node",
> +                                                        "XML Node",
> +                                                        "The XML node this config object corresponds to",
> +                                                        G_PARAM_READWRITE |
> +                                                        G_PARAM_CONSTRUCT_ONLY |
> +                                                        G_PARAM_STATIC_STRINGS));
> +
>      g_type_class_add_private(klass, sizeof(GVirConfigObjectPrivate));
>  }
>  
> @@ -202,6 +230,7 @@ gvir_config_object_parse(GVirConfigObject *config,
>                                    "%s",
>                                    "Unable to parse configuration");
>      }
> +    priv->node = priv->docHandle->children;
>  }
>  
>  
> @@ -277,6 +306,8 @@ const gchar *gvir_config_object_get_schema(GVirConfigObject *config)
>  }
>  
>  /* NB: the xmlDocPtr must not be freed by the caller */
> +/* gupnp has wrapped xmlDoc in a gobject */
> +/* not really useful, can be obtained from xmlNode::doc */

I guess the reason for doing that would be to avoid any libxml2 data
types in the public API. Might be worth considering in the future.

>  xmlDocPtr gvir_config_object_get_xml_doc(GVirConfigObject *config, GError **error)
>  {
>      gvir_config_object_parse(config, error);
> @@ -290,7 +321,5 @@ xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config,
>                                             GError **error)
>  {
>      gvir_config_object_parse(config, error);
> -    if (error)
> -        return NULL;
> -    return config->priv->docHandle->children;
> +    return config->priv->node;
>  }


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


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