[rygel] core,plugins: Custom ArrayList for MediaObjects
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,plugins: Custom ArrayList for MediaObjects
- Date: Mon, 2 Aug 2010 16:14:52 +0000 (UTC)
commit a865b8410498f2bef79281d8a2364fe48fc6a953
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Jul 29 12:30:42 2010 +0300
core,plugins: Custom ArrayList for MediaObjects
This class not only unifies handling of lists of media objects but also
handles the UPnP-specific sorting of them.
src/plugins/external/rygel-external-container.vala | 26 +++----
.../external/rygel-external-dummy-container.vala | 11 ++--
.../rygel-media-export-db-container.vala | 24 +++----
.../rygel-media-export-media-cache.vala | 28 ++++----
.../rygel-media-export-null-container.vala | 11 ++--
.../rygel-media-export-query-container.vala | 30 ++++-----
.../rygel-media-export-root-container.vala | 15 ++--
.../tracker/rygel-tracker-search-container.vala | 24 +++----
src/rygel/Makefile.am | 1 +
src/rygel/rygel-browse.vala | 11 ++--
src/rygel/rygel-media-container.vala | 39 +++++------
src/rygel/rygel-media-objects.vala | 71 ++++++++++++++++++++
src/rygel/rygel-media-query-action.vala | 42 +-----------
src/rygel/rygel-search.vala | 2 +-
src/rygel/rygel-simple-container.vala | 15 ++--
15 files changed, 185 insertions(+), 165 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 5675c85..014cbc2 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -71,11 +71,10 @@ public class Rygel.External.Container : Rygel.MediaContainer {
this.update_container.begin (true);
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
string[] filter = {};
foreach (var object_prop in MediaObjectProxy.PROPERTIES) {
@@ -94,13 +93,12 @@ public class Rygel.External.Container : Rygel.MediaContainer {
return yield this.create_media_objects (children_props, this);
}
- public override async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws GLib.Error {
if (!this.searchable) {
// Backend doesn't implement search :(
return yield base.search (expression,
@@ -183,11 +181,11 @@ public class Rygel.External.Container : Rygel.MediaContainer {
return media_object;
}
- private async Gee.List<MediaObject> create_media_objects (
+ private async MediaObjects create_media_objects (
HashTable<string,Value?>[] all_props,
MediaContainer? parent
= null) throws GLib.Error {
- var media_objects = new ArrayList <MediaObject> ();
+ var media_objects = new MediaObjects ();
foreach (var props in all_props) {
var id = props.lookup ("Path").get_string ();
diff --git a/src/plugins/external/rygel-external-dummy-container.vala b/src/plugins/external/rygel-external-dummy-container.vala
index a15de9d..df64f2f 100644
--- a/src/plugins/external/rygel-external-dummy-container.vala
+++ b/src/plugins/external/rygel-external-dummy-container.vala
@@ -38,11 +38,10 @@ internal class Rygel.External.DummyContainer : MediaContainer {
base (id, parent, title, child_count);
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
- return new ArrayList<MediaObject> ();
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error {
+ return new MediaObjects ();
}
}
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index f32783e..0b06dfc 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -50,11 +50,10 @@ public class Rygel.MediaExport.DBContainer : MediaContainer {
}
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
var children = this.media_db.get_children (this.id,
offset,
max_count);
@@ -65,14 +64,13 @@ public class Rygel.MediaExport.DBContainer : MediaContainer {
return children;
}
- public override async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws GLib.Error {
- Gee.List<MediaObject> children = null;
+ public override async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ MediaObjects children = null;
var max_objects = max_count;
if (max_objects == 0) {
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index f665aa1..89944fc 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -325,11 +325,10 @@ public class Rygel.MediaExport.MediaCache : Object {
return exists;
}
- public Gee.ArrayList<MediaObject> get_children (string container_id,
- long offset,
- long max_count)
- throws Error {
- ArrayList<MediaObject> children = new ArrayList<MediaObject> ();
+ public MediaObjects get_children (string container_id,
+ long offset,
+ long max_count) throws Error {
+ MediaObjects children = new MediaObjects ();
var parent = get_object (container_id) as MediaContainer;
GLib.Value[] values = { container_id,
@@ -358,7 +357,7 @@ public class Rygel.MediaExport.MediaCache : Object {
}
}
- public Gee.List<MediaObject> get_objects_by_search_expression (
+ public MediaObjects get_objects_by_search_expression (
SearchExpression? expression,
string container_id,
uint offset,
@@ -369,7 +368,7 @@ public class Rygel.MediaExport.MediaCache : Object {
var filter = this.search_expression_to_sql (expression, args);
if (filter == null) {
- return new Gee.ArrayList<MediaObject> ();
+ return new MediaObjects ();
}
debug ("Original search: %s", expression.to_string ());
@@ -449,14 +448,13 @@ public class Rygel.MediaExport.MediaCache : Object {
}
- public Gee.ArrayList<MediaObject> get_objects_by_filter (
- string filter,
- GLib.ValueArray args,
- string container_id,
- long offset,
- long max_count)
- throws Error {
- ArrayList<MediaObject> children = new ArrayList<MediaObject> ();
+ public MediaObjects get_objects_by_filter (string filter,
+ GLib.ValueArray args,
+ string container_id,
+ long offset,
+ long max_count)
+ throws Error {
+ var children = new MediaObjects ();
GLib.Value v = offset;
args.append (v);
v = max_count;
diff --git a/src/plugins/media-export/rygel-media-export-null-container.vala b/src/plugins/media-export/rygel-media-export-null-container.vala
index ac48544..1be8b7c 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -30,11 +30,10 @@ internal class Rygel.NullContainer : MediaContainer {
base.root ("MediaExport", 0);
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
- return new Gee.ArrayList<MediaObject> ();
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error {
+ return new MediaObjects ();
}
}
diff --git a/src/plugins/media-export/rygel-media-export-query-container.vala b/src/plugins/media-export/rygel-media-export-query-container.vala
index 589f01e..3166173 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -146,14 +146,13 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
}
}
- public override async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws GLib.Error {
- Gee.List<MediaObject> children = null;
+ public override async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ MediaObjects children = null;
var combined_expression = new LogicalExpression ();
combined_expression.operand1 = this.expression;
@@ -174,7 +173,7 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
out total_matches);
} catch (MediaDBError error) {
if (error is MediaDBError.UNSUPPORTED_SEARCH) {
- children = new ArrayList<MediaObject> ();
+ children = new MediaObjects ();
total_matches = 0;
} else {
throw error;
@@ -184,12 +183,11 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
return children;
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
- Gee.List<MediaObject> children;
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ MediaObjects children;
if (pattern == "") {
// this "duplicates" the search expression but using the same
@@ -206,7 +204,7 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
max_objects = -1;
}
- children = new ArrayList<MediaObject> ();
+ children = new MediaObjects ();
var data = this.media_db.get_object_attribute_by_search_expression (
this.attribute,
this.expression,
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 4755d81..582ae80 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -189,14 +189,13 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
return object;
}
- public override async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws GLib.Error {
- Gee.List<MediaObject> list;
+ public override async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ MediaObjects list;
MediaContainer query_container = null;
string upnp_class = null;
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index fff93fa..feb1114 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -99,11 +99,10 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
}
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws GLib.Error {
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
var expression = new RelationalExpression ();
expression.op = SearchCriteriaOp.EQ;
expression.operand1 = "@parentID";
@@ -118,14 +117,13 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
cancellable);
}
- public override async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws GLib.Error {
- var results = new ArrayList<MediaObject> ();
+ public override async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ var results = new MediaObjects ();
var query = this.create_query (expression,
(int) offset,
(int) max_count);
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 0acf3c8..3bba0dc 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -77,6 +77,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
rygel-media-renderer-plugin.vala \
rygel-plugin-loader.vala \
rygel-media-object.vala \
+ rygel-media-objects.vala \
rygel-media-container.vala \
rygel-simple-container.vala \
rygel-media-item.vala \
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 46dfef7..fe4a8a2 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -64,7 +64,7 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
}
}
- protected override async Gee.List<MediaObject> fetch_results (
+ protected override async MediaObjects fetch_results (
MediaObject media_object) throws Error {
if (this.fetch_metadata) {
// BrowseMetadata
@@ -75,18 +75,17 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
}
}
- private Gee.List<MediaObject> handle_metadata_request (
- MediaObject media_object)
- throws Error {
+ private MediaObjects handle_metadata_request (MediaObject media_object)
+ throws Error {
this.total_matches = 1;
- var results = new ArrayList<MediaObject> ();
+ var results = new MediaObjects ();
results.add (media_object);
return results;
}
- private async Gee.List<MediaObject> handle_children_request (
+ private async MediaObjects handle_children_request (
MediaObject media_object)
throws Error {
if (!(media_object is MediaContainer)) {
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index f47d50b..7df24e9 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -72,11 +72,10 @@ public abstract class Rygel.MediaContainer : MediaObject {
*
* return A list of media objects.
*/
- public async abstract Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error;
+ public async abstract MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error;
/**
* Recursively searches for all media objects the satisfy the given search
@@ -93,14 +92,13 @@ public abstract class Rygel.MediaContainer : MediaObject {
*
* return A list of media objects.
*/
- public virtual async Gee.List<MediaObject>? search (
- SearchExpression expression,
- uint offset,
- uint max_count,
- out uint total_matches,
- Cancellable? cancellable)
- throws Error {
- var result = new ArrayList<MediaObject> ();
+ public virtual async MediaObjects? search (SearchExpression expression,
+ uint offset,
+ uint max_count,
+ out uint total_matches,
+ Cancellable? cancellable)
+ throws Error {
+ var result = new MediaObjects ();
var children = yield this.get_children (0,
this.child_count,
@@ -154,7 +152,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
// actually satisfy the give search expression
total_matches = 0;
- return result.slice ((int) start, (int) stop);
+ return result.slice ((int) start, (int) stop) as MediaObjects;
} else {
total_matches = result.size;
@@ -260,13 +258,12 @@ public abstract class Rygel.MediaContainer : MediaObject {
}
}
- private async Gee.List<MediaObject> search_in_children (
- SearchExpression expression,
- Gee.List<MediaObject> children,
- uint limit,
- Cancellable? cancellable)
- throws Error {
- var result = new ArrayList<MediaObject> ();
+ private async MediaObjects search_in_children (SearchExpression expression,
+ MediaObjects children,
+ uint limit,
+ Cancellable? cancellable)
+ throws Error {
+ var result = new MediaObjects ();
foreach (var child in children) {
if (child is MediaContainer) {
diff --git a/src/rygel/rygel-media-objects.vala b/src/rygel/rygel-media-objects.vala
new file mode 100644
index 0000000..204011f
--- /dev/null
+++ b/src/rygel/rygel-media-objects.vala
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali <zeenix gmail com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Gee;
+
+/**
+ * An array list that keeps media objects.
+ */
+public class Rygel.MediaObjects : ArrayList<MediaObject> {
+ public override Gee.List<MediaObject>? slice (int start, int stop) {
+ var slice = base.slice (start, stop);
+ var ret = new MediaObjects ();
+
+ ret.add_all (slice);
+
+ return ret;
+ }
+
+ internal void sort_by_criteria (string sort_criteria) {
+ var sort_props = sort_criteria.split (",");
+ if (sort_props.length == 0) {
+ return;
+ }
+
+ this.sort_with_data ((a, b) => {
+ var object_a = a as MediaObject;
+ var object_b = b as MediaObject;
+
+ return this.compare_media_objects (object_a, object_b, sort_props);
+ });
+ }
+
+ private int compare_media_objects (MediaObject a,
+ MediaObject b,
+ string[] sort_props) {
+ int i;
+ int ret = 0;
+
+ for (i = 0; ret == 0 && i < sort_props.length; i++) {
+ var property = sort_props [i].substring (1);
+
+ ret = a.compare_by_property (b, property);
+
+ if (sort_props [i][0] == '-') {
+ // Need it in descending order so reverse the comparison
+ ret = 0 - ret;
+ }
+ }
+
+ return ret;
+ }
+}
diff --git a/src/rygel/rygel-media-query-action.vala b/src/rygel/rygel-media-query-action.vala
index 5518a79..875239c 100644
--- a/src/rygel/rygel-media-query-action.vala
+++ b/src/rygel/rygel-media-query-action.vala
@@ -49,8 +49,6 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
protected XBoxHacks xbox_hacks;
protected string object_id_arg;
- private string[] sort_props;
-
protected MediaQueryAction (ContentDirectory content_dir,
owned ServiceAction action) {
this.root_container = content_dir.root_container;
@@ -79,7 +77,9 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
this.update_id = uint32.MAX;
}
- this.sort_media_objects (results);
+ if (this.sort_criteria != null) {
+ results.sort_by_criteria (this.sort_criteria);
+ }
foreach (var result in results) {
if (result is MediaItem && this.xbox_hacks != null) {
@@ -124,7 +124,7 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
}
}
- protected abstract async Gee.List<MediaObject> fetch_results (
+ protected abstract async MediaObjects fetch_results (
MediaObject media_object) throws Error;
private async MediaObject fetch_media_object () throws Error {
@@ -183,38 +183,4 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
this.completed ();
}
-
- private void sort_media_objects (Gee.List<MediaObject> media_objects) {
- if (this.sort_criteria == null) {
- return;
- }
-
- this.sort_props = this.sort_criteria.split (",");
- if (this.sort_props.length == 0) {
- return;
- }
-
- media_objects.sort_with_data (this.compare_media_objects);
- }
-
- private int compare_media_objects (void *a, void *b) {
- var object_a = a as MediaObject;
- var object_b = b as MediaObject;
-
- int i;
- int ret = 0;
-
- for (i = 0; ret == 0 && i < this.sort_props.length; i++) {
- var property = this.sort_props [i].substring (1);
-
- ret = object_a.compare_by_property (object_b, property);
-
- if (this.sort_props [i][0] == '-') {
- // Need it in descending order so reverse the comparison
- ret = 0 - ret;
- }
- }
-
- return ret;
- }
}
diff --git a/src/rygel/rygel-search.vala b/src/rygel/rygel-search.vala
index 8ec2fe8..9798a10 100644
--- a/src/rygel/rygel-search.vala
+++ b/src/rygel/rygel-search.vala
@@ -54,7 +54,7 @@ internal class Rygel.Search: Rygel.MediaQueryAction {
debug (_("Executing search request: %s"), this.search_criteria);
}
- protected override async Gee.List<MediaObject> fetch_results (
+ protected override async MediaObjects fetch_results (
MediaObject media_object) throws Error {
var container = media_object as MediaContainer;
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index d6806da..0a7875c 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -30,14 +30,14 @@ using Gee;
* children ArrayList field.
*/
public class Rygel.SimpleContainer : Rygel.MediaContainer {
- public ArrayList<MediaObject> children;
+ public MediaObjects children;
public SimpleContainer (string id,
MediaContainer? parent,
string title) {
base (id, parent, title, 0);
- this.children = new ArrayList<MediaObject> ();
+ this.children = new MediaObjects ();
}
public SimpleContainer.root (string title) {
@@ -62,14 +62,13 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
this.child_count = 0;
}
- public override async Gee.List<MediaObject>? get_children (
- uint offset,
- uint max_count,
- Cancellable? cancellable)
- throws Error {
+ public override async MediaObjects? get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error {
uint stop = offset + max_count;
stop = stop.clamp (0, this.child_count);
- return this.children.slice ((int) offset, (int) stop);
+ return this.children.slice ((int) offset, (int) stop) as MediaObjects;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]