[rygel] core: Extract code to find DLNA.ORG_AnyContainer
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Extract code to find DLNA.ORG_AnyContainer
- Date: Tue, 21 Feb 2012 13:49:43 +0000 (UTC)
commit 4c4c0869ed0d92766e4c45aa8947e3a9a372a2a7
Author: Jens Georg <mail jensge org>
Date: Mon Feb 20 12:12:22 2012 +0200
core: Extract code to find DLNA.ORG_AnyContainer
src/rygel/rygel-item-creator.vala | 89 +++++++++++++++++++++---------------
1 files changed, 52 insertions(+), 37 deletions(-)
---
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index d3fe848..b21310e 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -188,47 +188,62 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
}
}
+ /**
+ * Find a container that can create items matching the UPnP class of the
+ * requested item.
+ *
+ * If the item's UPnP class cannot be found, generalize the UPnP class until
+ * we reach object.item according to DLNA guideline 7.3.120.4.
+ *
+ * @returns a container able to create the item or null if no such container
+ * can be found.
+ */
+ private async MediaObject? find_any_container () throws Error {
+ var root_container = this.content_dir.root_container
+ as SearchableContainer;
+
+ if (root_container == null) {
+ return null;
+ }
+
+ var upnp_class = this.didl_item.upnp_class;
+
+ var expression = new RelationalExpression ();
+ expression.op = SearchCriteriaOp.DERIVED_FROM;
+ expression.operand1 = "upnp:createClass";
+
+ while (upnp_class != "object.item") {
+ expression.operand2 = upnp_class;
+
+ uint total_matches;
+ var result = yield root_container.search (expression,
+ 0,
+ 1,
+ out total_matches,
+ this.cancellable);
+ if (result.size > 0) {
+ this.didl_item.upnp_class = upnp_class;
+
+ return result[0];
+ } else {
+ this.generalize_upnp_class (ref upnp_class);
+ }
+ }
+
+ if (upnp_class == "object.item") {
+ throw new ContentDirectoryError.BAD_METADATA
+ ("'%s' UPnP class unsupported",
+ this.didl_item.upnp_class);
+ }
+
+ return null;
+ }
+
private async WritableContainer fetch_container () throws Error {
MediaObject media_object = null;
if (this.container_id == "DLNA.ORG_AnyContainer") {
- var upnp_class = didl_item.upnp_class;
-
- var expression = new RelationalExpression ();
- expression.op = SearchCriteriaOp.DERIVED_FROM;
- expression.operand1 = "upnp:createClass";
-
- while (upnp_class != "object.item") {
- expression.operand2 = upnp_class;
-
- var container = this.content_dir.root_container
- as SearchableContainer;
-
- if (container != null) {
- uint total_matches;
- var result = yield container.search (expression,
- 0,
- 1,
- out total_matches,
- this.cancellable);
- if (result.size > 0) {
- media_object = result[0];
- didl_item.upnp_class = upnp_class;
-
- break;
- } else {
- this.generalize_upnp_class (ref upnp_class);
- }
- } else {
- break;
- }
- }
-
- if (upnp_class == "object.item") {
- throw new ContentDirectoryError.BAD_METADATA
- ("'%s' UPnP class unsupported",
- didl_item.upnp_class);
- }
+ media_object = yield this.find_any_container ();
} else {
media_object = yield this.content_dir.root_container.find_object
(this.container_id, this.cancellable);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]