[gupnp] [PATCH 3/4] Pass namespaces to GUPnPDIDLLiteObject constructor
- From: Sven Neumann <s neumann raumfeld com>
- To: gupnp o-hand com
- Cc: Sven Neumann <s neumann raumfeld com>
- Subject: [gupnp] [PATCH 3/4] Pass namespaces to GUPnPDIDLLiteObject constructor
- Date: Tue, 25 May 2010 10:30:32 +0200
Allow to pass pointers to the registered XML namespaces to
gupnp_didl_lite_object_new_from_xml() so that they don't have
to be looked up expensively.
Signed-off-by: Sven Neumann <s neumann raumfeld com>
---
libgupnp-av/gupnp-didl-lite-object-private.h | 4 +-
libgupnp-av/gupnp-didl-lite-object.c | 101 +++++++++++++++++++++-----
libgupnp-av/gupnp-didl-lite-parser.c | 3 +-
libgupnp-av/gupnp-didl-lite-writer.c | 8 ++-
4 files changed, 95 insertions(+), 21 deletions(-)
diff --git a/libgupnp-av/gupnp-didl-lite-object-private.h b/libgupnp-av/gupnp-didl-lite-object-private.h
index 4509c7b..52526c0 100644
--- a/libgupnp-av/gupnp-didl-lite-object-private.h
+++ b/libgupnp-av/gupnp-didl-lite-object-private.h
@@ -30,7 +30,9 @@ G_BEGIN_DECLS
GUPnPDIDLLiteObject *
gupnp_didl_lite_object_new_from_xml (xmlNode *xml_node,
- GUPnPXMLDoc *xml_doc) G_GNUC_INTERNAL;
+ GUPnPXMLDoc *xml_doc,
+ xmlNs *upnp_ns,
+ xmlNs *dc_ns) G_GNUC_INTERNAL;
G_END_DECLS
diff --git a/libgupnp-av/gupnp-didl-lite-object.c b/libgupnp-av/gupnp-didl-lite-object.c
index 1a7154f..5a50f47 100644
--- a/libgupnp-av/gupnp-didl-lite-object.c
+++ b/libgupnp-av/gupnp-didl-lite-object.c
@@ -55,6 +55,8 @@ enum {
PROP_0,
PROP_XML_NODE,
PROP_XML_DOC,
+ PROP_UPNP_NAMESPACE,
+ PROP_DC_NAMESPACE,
PROP_ID,
PROP_PARENT_ID,
PROP_RESTRICTED,
@@ -99,6 +101,12 @@ gupnp_didl_lite_object_set_property (GObject *object,
case PROP_XML_DOC:
didl_object->priv->xml_doc = g_value_dup_object (value);
break;
+ case PROP_UPNP_NAMESPACE:
+ didl_object->priv->upnp_ns = g_value_get_pointer (value);
+ break;
+ case PROP_DC_NAMESPACE:
+ didl_object->priv->dc_ns = g_value_get_pointer (value);
+ break;
case PROP_ID:
gupnp_didl_lite_object_set_id (didl_object,
g_value_get_string (value));
@@ -281,31 +289,36 @@ gupnp_didl_lite_object_constructed (GObject *object)
{
GObjectClass *object_class;
GUPnPDIDLLiteObjectPrivate *priv;
- xmlNs **ns_list;
priv = GUPNP_DIDL_LITE_OBJECT (object)->priv;
- ns_list = xmlGetNsList (priv->xml_doc->doc,
- xmlDocGetRootElement (priv->xml_doc->doc));
+ if (! priv->upnp_ns || ! priv->dc_ns) {
+ xmlNs **ns_list;
- if (ns_list) {
- short i;
+ ns_list = xmlGetNsList (priv->xml_doc->doc,
+ xmlDocGetRootElement (priv->xml_doc->doc));
- for (i = 0; ns_list[i] != NULL; i++) {
- const char *prefix;
+ if (ns_list) {
+ short i;
- prefix = (const char *) ns_list[i]->prefix;
+ for (i = 0; ns_list[i] != NULL; i++) {
+ const char *prefix;
- if (prefix == NULL)
- continue;
+ prefix = (const char *) ns_list[i]->prefix;
- if (g_ascii_strcasecmp (prefix, "upnp") == 0)
- priv->upnp_ns = ns_list[i];
- else if (g_ascii_strcasecmp (prefix, "dc") == 0)
- priv->dc_ns = ns_list[i];
- }
+ if (prefix == NULL)
+ continue;
- xmlFree (ns_list);
+ if (! priv->upnp_ns &&
+ g_ascii_strcasecmp (prefix, "upnp") == 0)
+ priv->upnp_ns = ns_list[i];
+ else if (! priv->dc_ns &&
+ g_ascii_strcasecmp (prefix, "dc") == 0)
+ priv->dc_ns = ns_list[i];
+ }
+
+ xmlFree (ns_list);
+ }
}
object_class = G_OBJECT_CLASS (gupnp_didl_lite_object_parent_class);
@@ -387,6 +400,54 @@ gupnp_didl_lite_object_class_init (GUPnPDIDLLiteObjectClass *klass)
G_PARAM_STATIC_BLURB));
/**
+ * GUPnPDIDLLiteObject:upnp-namespace
+ *
+ * Pointer to the UPNP XML namespace registered with the
+ * XML document containing this object.
+ *
+ * Internal property.
+ *
+ * Stability: Private
+ **/
+ g_object_class_install_property
+ (object_class,
+ PROP_UPNP_NAMESPACE,
+ g_param_spec_pointer ("upnp-namespace",
+ "XML namespace",
+ "Pointer to the UPNP XML namespace "
+ "registered with the XML document "
+ "containing this object.",
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ /**
+ * GUPnPDIDLLiteObject:dc-namespace
+ *
+ * Pointer to the DublinCore XML namespace registered with
+ * the XML document containing this object.
+ *
+ * Internal property.
+ *
+ * Stability: Private
+ **/
+ g_object_class_install_property
+ (object_class,
+ PROP_DC_NAMESPACE,
+ g_param_spec_pointer ("dc-namespace",
+ "XML namespace",
+ "Pointer to the Dublin Core XML "
+ "namespace registered with the XML "
+ "document containing this object.",
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+
+ /**
* GUPnPDIDLLiteObject:id
*
* The ID of this object.
@@ -724,7 +785,9 @@ get_contributor_list_by_name (GUPnPDIDLLiteObject *object,
**/
GUPnPDIDLLiteObject *
gupnp_didl_lite_object_new_from_xml (xmlNode *xml_node,
- GUPnPXMLDoc *xml_doc)
+ GUPnPXMLDoc *xml_doc,
+ xmlNs *upnp_ns,
+ xmlNs *dc_ns)
{
g_return_val_if_fail (xml_node != NULL, NULL);
g_return_val_if_fail (xml_node->name != NULL, NULL);
@@ -734,11 +797,15 @@ gupnp_didl_lite_object_new_from_xml (xmlNode *xml_node,
return g_object_new (GUPNP_TYPE_DIDL_LITE_CONTAINER,
"xml-node", xml_node,
"xml-doc", xml_doc,
+ "upnp-namespace", upnp_ns,
+ "dc-namespace", dc_ns,
NULL);
else if (g_ascii_strcasecmp ((char *) xml_node->name, "item") == 0)
return g_object_new (GUPNP_TYPE_DIDL_LITE_ITEM,
"xml-node", xml_node,
"xml-doc", xml_doc,
+ "upnp-namespace", upnp_ns,
+ "dc-namespace", dc_ns,
NULL);
else
return NULL;
diff --git a/libgupnp-av/gupnp-didl-lite-parser.c b/libgupnp-av/gupnp-didl-lite-parser.c
index 9c0cb82..e7e24ac 100644
--- a/libgupnp-av/gupnp-didl-lite-parser.c
+++ b/libgupnp-av/gupnp-didl-lite-parser.c
@@ -208,7 +208,8 @@ gupnp_didl_lite_parser_parse_didl (GUPnPDIDLLiteParser *parser,
for (element = element->children; element; element = element->next) {
GUPnPDIDLLiteObject *object;
- object = gupnp_didl_lite_object_new_from_xml (element, xml_doc);
+ object = gupnp_didl_lite_object_new_from_xml (element, xml_doc,
+ NULL, NULL);
if (object == NULL)
continue;
diff --git a/libgupnp-av/gupnp-didl-lite-writer.c b/libgupnp-av/gupnp-didl-lite-writer.c
index ba6d8da..d01ad2c 100644
--- a/libgupnp-av/gupnp-didl-lite-writer.c
+++ b/libgupnp-av/gupnp-didl-lite-writer.c
@@ -424,7 +424,9 @@ gupnp_didl_lite_writer_add_item (GUPnPDIDLLiteWriter *writer)
NULL);
object = gupnp_didl_lite_object_new_from_xml (item_node,
- writer->priv->xml_doc);
+ writer->priv->xml_doc,
+ writer->priv->upnp_ns,
+ writer->priv->dc_ns);
return GUPNP_DIDL_LITE_ITEM (object);
}
@@ -450,7 +452,9 @@ gupnp_didl_lite_writer_add_container (GUPnPDIDLLiteWriter *writer)
NULL);
object = gupnp_didl_lite_object_new_from_xml (container_node,
- writer->priv->xml_doc);
+ writer->priv->xml_doc,
+ writer->priv->upnp_ns,
+ writer->priv->dc_ns);
return GUPNP_DIDL_LITE_CONTAINER (object);
}
--
1.7.0.4
--
To unsubscribe send a mail to gupnp+unsubscribe\@o-hand.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]