From d1b77c8b1421cfdce5e9f6bc71e857254f626590 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Wed, 28 Jan 2009 12:33:04 +0000 Subject: [PATCH] Free ContentDirectory implementations from DIDL-Lite handling. svn path=/trunk/; revision=492 --- src/plugins/dvb/rygel-dvb-content-dir.vala | 117 ++++++++--------------- src/plugins/test/rygel-test-content-dir.vala | 36 ++------ src/plugins/tracker/rygel-media-tracker.vala | 133 +++++++++------------------ src/rygel/rygel-content-directory.vala | 69 ++++++++++++-- 4 files changed, 151 insertions(+), 204 deletions(-) diff --git a/src/plugins/dvb/rygel-dvb-content-dir.vala b/src/plugins/dvb/rygel-dvb-content-dir.vala index 52867a1..0535be0 100644 --- a/src/plugins/dvb/rygel-dvb-content-dir.vala +++ b/src/plugins/dvb/rygel-dvb-content-dir.vala @@ -31,8 +31,6 @@ using Gee; * Implementation of DVB ContentDirectory service. */ public class Rygel.DVBContentDir : ContentDirectory { - public static const int MAX_REQUESTED_COUNT = 128; - // class-wide constants private const string DVB_SERVICE = "org.gnome.DVB"; private const string MANAGER_PATH = "/org/gnome/DVB/Manager"; @@ -101,79 +99,8 @@ public class Rygel.DVBContentDir : ContentDirectory { } } - public override void add_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws GLib.Error { - if (args.requested_count == 0) - args.requested_count = MAX_REQUESTED_COUNT; - - ArrayList children; - - children = this.get_children (args.object_id, - args.index, - args.requested_count, - out args.total_matches); - args.number_returned = children.size; - - /* Iterate through all items */ - for (int i = 0; i < children.size; i++) { - children[i].serialize (didl_writer); - } - - args.update_id = uint32.MAX; - } - - public override void add_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) throws GLib.Error { - MediaObject media_object = find_object_by_id (args.object_id); - media_object.serialize (didl_writer); - - args.update_id = uint32.MAX; - } - - public override void add_root_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws GLib.Error { - var children = get_root_children (args.index, - args.requested_count, - out args.total_matches); - foreach (var child in children) { - child.serialize (didl_writer); - } - - args.number_returned = children.size; - args.update_id = uint32.MAX; - } - - // Private methods - private DVBChannelGroup? find_group_by_id (string id) { - DVBChannelGroup group = null; - - foreach (DVBChannelGroup tmp in this.groups) { - if (id == tmp.id) { - group = tmp; - - break; - } - } - - return group; - } - - private DVBChannel find_channel_by_id (string id) throws GLib.Error { - DVBChannel channel = null; - - foreach (DVBChannelGroup group in this.groups) { - channel = group.find_channel (id); - if (channel != null) { - break; - } - } - - return channel; - } - - private MediaObject find_object_by_id (string object_id) throws GLib.Error { + public override MediaObject find_object_by_id (string object_id) + throws GLib.Error { // First try groups MediaObject media_object = find_group_by_id (object_id); @@ -188,7 +115,8 @@ public class Rygel.DVBContentDir : ContentDirectory { return media_object; } - private ArrayList get_children (string container_id, + public override ArrayList get_children ( + string container_id, uint offset, uint max_count, out uint child_count) @@ -210,10 +138,11 @@ public class Rygel.DVBContentDir : ContentDirectory { } } - private ArrayList get_root_children (uint offset, - uint max_count, - out uint child_count) - throws GLib.Error { + public override ArrayList get_root_children ( + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { child_count = this.groups.size; ArrayList children; @@ -231,6 +160,34 @@ public class Rygel.DVBContentDir : ContentDirectory { return children; } + // Private methods + private DVBChannelGroup? find_group_by_id (string id) { + DVBChannelGroup group = null; + + foreach (DVBChannelGroup tmp in this.groups) { + if (id == tmp.id) { + group = tmp; + + break; + } + } + + return group; + } + + private DVBChannel find_channel_by_id (string id) throws GLib.Error { + DVBChannel channel = null; + + foreach (DVBChannelGroup group in this.groups) { + channel = group.find_channel (id); + if (channel != null) { + break; + } + } + + return channel; + } + private ArrayList slice_object_list ( ArrayList list, uint offset, diff --git a/src/plugins/test/rygel-test-content-dir.vala b/src/plugins/test/rygel-test-content-dir.vala index 0a4c207..0907ada 100644 --- a/src/plugins/test/rygel-test-content-dir.vala +++ b/src/plugins/test/rygel-test-content-dir.vala @@ -55,32 +55,11 @@ public class Rygel.TestContentDir : ContentDirectory { this.root_container.child_count = this.items.size; } - public override void add_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) throws GLib.Error { - MediaObject media_object = find_object_by_id (args.object_id); - media_object.serialize (didl_writer); - - args.update_id = uint32.MAX; - } - - public override void add_root_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws GLib.Error { - var children = get_root_children (args.index, - args.requested_count, - out args.total_matches); - foreach (var child in children) { - child.serialize (didl_writer); - } - - args.number_returned = children.size; - args.update_id = uint32.MAX; - } - - private ArrayList get_root_children (uint offset, - uint max_count, - out uint child_count) - throws GLib.Error { + public override ArrayList get_root_children ( + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { child_count = this.items.size; ArrayList children; @@ -98,8 +77,8 @@ public class Rygel.TestContentDir : ContentDirectory { return children; } - /* Private methods */ - private MediaObject find_object_by_id (string object_id) throws GLib.Error { + public override MediaObject find_object_by_id (string object_id) + throws GLib.Error { MediaItem item = null; foreach (MediaItem tmp in this.items) { @@ -117,6 +96,7 @@ public class Rygel.TestContentDir : ContentDirectory { return item; } + /* Private methods */ private void on_item_requested (HTTPServer http_server, string item_id, out MediaItem item) { diff --git a/src/plugins/tracker/rygel-media-tracker.vala b/src/plugins/tracker/rygel-media-tracker.vala index 23b758c..920972e 100644 --- a/src/plugins/tracker/rygel-media-tracker.vala +++ b/src/plugins/tracker/rygel-media-tracker.vala @@ -30,8 +30,6 @@ using Gee; * Implementation of Tracker-based ContentDirectory service. */ public class Rygel.MediaTracker : ContentDirectory { - public static const int MAX_REQUESTED_COUNT = 128; - /* FIXME: Make this a static if you know how to initize it */ private ArrayList containers; @@ -73,48 +71,62 @@ public class Rygel.MediaTracker : ContentDirectory { this.search_parser = new SearchCriteriaParser (); } - public override void add_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws GLib.Error { - if (args.requested_count == 0) - args.requested_count = MAX_REQUESTED_COUNT; + public override ArrayList get_children ( + string container_id, + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { + var container = this.find_container_by_id (container_id); + if (container == null) { + throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); + } - ArrayList children; + return container.get_children_from_db (offset, + max_count, + out child_count); + } + + public override MediaObject find_object_by_id (string object_id) + throws GLib.Error { + /* First try containers */ + MediaObject media_object = find_container_by_id (object_id); - children = this.get_children (args.object_id, - args.index, - args.requested_count, - out args.total_matches); - args.number_returned = children.size; + if (media_object == null) { + /* Now try items */ + var container = get_item_parent (object_id); + + if (container != null) + media_object = container.get_item_from_db (object_id); + } - /* Iterate through all items */ - for (int i = 0; i < children.size; i++) { - children[i].serialize (didl_writer); + if (media_object == null) { + throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); } - args.update_id = uint32.MAX; + return media_object; } - public override void add_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) throws GLib.Error { - MediaObject media_object = find_object_by_id (args.object_id); - media_object.serialize (didl_writer); + public override ArrayList get_root_children ( + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { + child_count = this.containers.size; - args.update_id = uint32.MAX; - } + ArrayList children; - public override void add_root_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws GLib.Error { - var children = get_root_children (args.index, - args.requested_count, - out args.total_matches); - foreach (var child in children) { - child.serialize (didl_writer); + if (max_count == 0 && offset == 0) { + children = this.containers; + } else if (offset >= child_count) { + throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); + } else { + children = slice_object_list (this.containers, + offset, + max_count); } - args.number_returned = children.size; - args.update_id = uint32.MAX; + return children; } /* Private methods */ @@ -167,61 +179,6 @@ public class Rygel.MediaTracker : ContentDirectory { item = container.get_item_from_db (item_id); } - private ArrayList get_children (string container_id, - uint offset, - uint max_count, - out uint child_count) - throws GLib.Error { - var container = this.find_container_by_id (container_id); - if (container == null) { - throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); - } - - return container.get_children_from_db (offset, - max_count, - out child_count); - } - - private MediaObject find_object_by_id (string object_id) throws GLib.Error { - /* First try containers */ - MediaObject media_object = find_container_by_id (object_id); - - if (media_object == null) { - /* Now try items */ - var container = get_item_parent (object_id); - - if (container != null) - media_object = container.get_item_from_db (object_id); - } - - if (media_object == null) { - throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); - } - - return media_object; - } - - private ArrayList get_root_children (uint offset, - uint max_count, - out uint child_count) - throws GLib.Error { - child_count = this.containers.size; - - ArrayList children; - - if (max_count == 0 && offset == 0) { - children = this.containers; - } else if (offset >= child_count) { - throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"); - } else { - children = slice_object_list (this.containers, - offset, - max_count); - } - - return children; - } - private ArrayList slice_object_list ( ArrayList list, uint offset, diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala index 8aa2e8e..aec4e89 100644 --- a/src/rygel/rygel-content-directory.vala +++ b/src/rygel/rygel-content-directory.vala @@ -23,6 +23,7 @@ */ using GUPnP; +using Gee; /** * Errors used by ContentDirectory and deriving classes. @@ -58,6 +59,8 @@ public class Rygel.ContentDirectory: Service { "urn:schemas-upnp-org:service:ContentDirectory:2"; public const string DESCRIPTION_PATH = "xml/ContentDirectory.xml"; + public const int MAX_REQUESTED_COUNT = 128; + protected uint32 system_update_id; protected string feature_list; protected string search_caps; @@ -70,20 +73,24 @@ public class Rygel.ContentDirectory: Service { DIDLLiteWriter didl_writer; // Public abstract methods derived classes need to implement - public virtual void add_children_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) - throws Error { + public virtual ArrayList get_children (string container_id, + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n"); } - public virtual void add_metadata (DIDLLiteWriter didl_writer, - BrowseArgs args) throws Error { + public virtual MediaObject find_object_by_id (string object_id) + throws GLib.Error { throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n"); } - public virtual void add_root_children_metadata - (DIDLLiteWriter didl_writer, - BrowseArgs args) throws Error { + public virtual ArrayList get_root_children ( + uint offset, + uint max_count, + out uint child_count) + throws GLib.Error { throw new ServerError.NOT_IMPLEMENTED ("Not Implemented\n"); } @@ -316,5 +323,51 @@ public class Rygel.ContentDirectory: Service { action.return (); } + + protected virtual void add_children_metadata (DIDLLiteWriter didl_writer, + BrowseArgs args) + throws GLib.Error { + if (args.requested_count == 0) + args.requested_count = MAX_REQUESTED_COUNT; + + ArrayList children; + + children = this.get_children (args.object_id, + args.index, + args.requested_count, + out args.total_matches); + args.number_returned = children.size; + + /* Iterate through all items */ + for (int i = 0; i < children.size; i++) { + children[i].serialize (didl_writer); + } + + args.update_id = uint32.MAX; + } + + protected virtual void add_metadata (DIDLLiteWriter didl_writer, + BrowseArgs args) + throws GLib.Error { + MediaObject media_object = find_object_by_id (args.object_id); + media_object.serialize (didl_writer); + + args.update_id = uint32.MAX; + } + + protected virtual void add_root_children_metadata ( + DIDLLiteWriter didl_writer, + BrowseArgs args) + throws GLib.Error { + var children = get_root_children (args.index, + args.requested_count, + out args.total_matches); + foreach (var child in children) { + child.serialize (didl_writer); + } + + args.number_returned = children.size; + args.update_id = uint32.MAX; + } } -- 2.7.4