[gupnp-av/wip/didl-lite-fragments: 18/20] Add gupnp_didl_lite_object_apply_fragments.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-av/wip/didl-lite-fragments: 18/20] Add gupnp_didl_lite_object_apply_fragments.
- Date: Thu, 25 Oct 2012 09:49:57 +0000 (UTC)
commit 01cef0d4a13d499b298381b6c48276ac1e4d8ce9
Author: Krzesimir Nowak <krnowak openismus com>
Date: Thu Oct 25 11:41:34 2012 +0200
Add gupnp_didl_lite_object_apply_fragments.
libgupnp-av/gupnp-didl-lite-object.c | 99 ++++++++++++++++++++++++++++++++++
libgupnp-av/gupnp-didl-lite-object.h | 9 +++
2 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/libgupnp-av/gupnp-didl-lite-object.c b/libgupnp-av/gupnp-didl-lite-object.c
index f19fe00..59f2251 100644
--- a/libgupnp-av/gupnp-didl-lite-object.c
+++ b/libgupnp-av/gupnp-didl-lite-object.c
@@ -40,6 +40,7 @@
#include "gupnp-didl-lite-item.h"
#include "gupnp-didl-lite-contributor-private.h"
#include "xml-util.h"
+#include "fragment-util.h"
#include "xsd-data.h"
G_DEFINE_ABSTRACT_TYPE (GUPnPDIDLLiteObject,
@@ -2289,3 +2290,101 @@ gupnp_didl_lite_object_unset_artists (GUPnPDIDLLiteObject *object)
g_object_notify (G_OBJECT (object), "artist");
}
+
+/**
+ * gupnp_didl_lite_object_apply_fragments:
+ * @object: The #GUPnPDIDLLiteObject
+ * @current_fragments: (array length=current_size) (transfer none): XML
+ * fragments of @object.
+ * @current_size: Size of @current_fragments or -1.
+ * @new_fragments: (array length=new_size) (transfer none): Substitutes
+ * for @current_fragments.
+ * @new_size: Size of @new_fragments or -1.
+ *
+ * Updates object by applying @new_fragments in places of
+ * @current_fragments. For @current_size and @new_size -1 can be
+ * passed when respectively @current_fragments and @new_fragments are
+ * NULL terminated.
+ *
+ * Returns: Result of operation.
+ */
+GUPnPDIDLLiteFragmentResult
+gupnp_didl_lite_object_apply_fragments (GUPnPDIDLLiteObject *object,
+ gchar **current_fragments,
+ gint current_size,
+ gchar **new_fragments,
+ gint new_size)
+{
+ DocNode modified;
+ DocNode original;
+ GUPnPDIDLLiteFragmentResult result;
+ gint iter;
+
+ g_return_val_if_fail (GUPNP_IS_DIDL_LITE_OBJECT (object),
+ GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR);
+ g_return_val_if_fail (current_fragments != NULL,
+ GUPNP_DIDL_LITE_FRAGMENT_RESULT_CURRENT_INVALID);
+ g_return_val_if_fail (new_fragments != NULL,
+ GUPNP_DIDL_LITE_FRAGMENT_RESULT_NEW_INVALID);
+
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_OK;
+ modified.doc = NULL;
+
+ if (current_size < 0)
+ current_size = g_strv_length (current_fragments);
+ if (new_size < 0)
+ new_size = g_strv_length (new_fragments);
+
+ if (current_size != new_size) {
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_MISMATCH;
+
+ goto out;
+ }
+
+ if (!current_size) {
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_CURRENT_INVALID;
+
+ goto out;
+ }
+
+ original.doc = object->priv->xml_doc->doc;
+ original.node = object->priv->xml_node;
+ modified.doc = xmlCopyDoc (original.doc, 1);
+
+ if (modified.doc == NULL) {
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
+
+ goto out;
+ }
+
+ modified.node = xml_util_find_node (modified.doc->children,
+ original.node);
+
+ if (modified.node == NULL) {
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
+
+ goto out;
+ }
+
+ for (iter = 0; iter < new_size; ++iter) {
+ const gchar *current_fragment = current_fragments[iter];
+ const gchar *new_fragment = new_fragments[iter];
+
+ result = fragment_util_check_fragments (&original,
+ &modified,
+ current_fragment,
+ new_fragment,
+ didl_lite_xsd);
+
+ if (result != GUPNP_DIDL_LITE_FRAGMENT_RESULT_OK)
+ goto out;
+ }
+
+ if (!fragment_util_apply_modification (&object->priv->xml_node,
+ &modified))
+ result = GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
+ out:
+ if (modified.doc != NULL)
+ xmlFreeDoc (modified.doc);
+ return result;
+}
diff --git a/libgupnp-av/gupnp-didl-lite-object.h b/libgupnp-av/gupnp-didl-lite-object.h
index ab782c5..6ca982d 100644
--- a/libgupnp-av/gupnp-didl-lite-object.h
+++ b/libgupnp-av/gupnp-didl-lite-object.h
@@ -34,6 +34,7 @@
#include "gupnp-didl-lite-resource.h"
#include "gupnp-didl-lite-descriptor.h"
#include "gupnp-didl-lite-contributor.h"
+#include "gupnp-av-enums.h"
G_BEGIN_DECLS
@@ -292,6 +293,14 @@ gupnp_didl_lite_object_get_artists_xml_string
void
gupnp_didl_lite_object_unset_artists (GUPnPDIDLLiteObject *object);
+GUPnPDIDLLiteFragmentResult
+gupnp_didl_lite_object_apply_fragments
+ (GUPnPDIDLLiteObject *object,
+ gchar **current_fragments,
+ gint current_size,
+ gchar **new_fragments,
+ gint new_size);
+
G_END_DECLS
#endif /* __GUPNP_DIDL_LITE_OBJECT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]