From: Zeeshan Ali (Khattak) Date: Wed, 28 Jan 2009 12:32:43 +0000 (+0000) Subject: Separate out search and serialization of root container in MediaTracker. X-Git-Tag: RYGEL_0_2_2~156 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b302f0c05a65efce573abbeea86242bc291a7c7;p=profile%2Fivi%2Frygel.git Separate out search and serialization of root container in MediaTracker. svn path=/trunk/; revision=487 --- diff --git a/src/plugins/tracker/rygel-media-tracker.vala b/src/plugins/tracker/rygel-media-tracker.vala index 7c4a03e..8ab07ee 100644 --- a/src/plugins/tracker/rygel-media-tracker.vala +++ b/src/plugins/tracker/rygel-media-tracker.vala @@ -118,10 +118,14 @@ public class Rygel.MediaTracker : ContentDirectory { public override void add_root_children_metadata (DIDLLiteWriter didl_writer, BrowseArgs args) throws GLib.Error { - foreach (TrackerContainer container in this.containers) - container.serialize (didl_writer); + var children = get_root_children (args.index, + args.requested_count, + out args.total_matches); + foreach (var child in children) { + child.serialize (didl_writer); + } - args.total_matches = args.number_returned = this.containers.size; + args.number_returned = children.size; args.update_id = uint32.MAX; } @@ -208,5 +212,34 @@ public class Rygel.MediaTracker : ContentDirectory { 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 { + // Make sure we don't go beyond the limits + max_count %= (child_count - offset); + + if (max_count == 0) { + max_count = child_count - offset; + } + + children = new ArrayList (); + for (int i = 0; i < max_count; i++) { + children.add (this.containers.get (i + (int) offset)); + } + } + + return children; + } }