[rygel] core,plugins,build: Synchronous MediaContainer
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core,plugins,build: Synchronous MediaContainer
- Date: Fri, 16 Oct 2009 16:24:27 +0000 (UTC)
commit b4cf9c2c69c9006b37c19dc0c54529876092e4dc
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Oct 15 19:20:41 2009 +0300
core,plugins,build: Synchronous MediaContainer
Turn the MediaContainer interface synchronous only to later convert
it to asynchronous again using the new async vala syntax. Ironic, isn't
it? :)
src/plugins/external/rygel-external-container.vala | 51 ++------
.../rygel-media-export-null-container.vala | 27 ++---
.../tracker/rygel-tracker-search-container.vala | 130 ++++++--------------
src/rygel/Makefile.am | 1 -
src/rygel/rygel-browse.vala | 27 +---
src/rygel/rygel-http-request.vala | 53 ++++-----
src/rygel/rygel-media-container.vala | 39 ++-----
src/rygel/rygel-media-db-container.vala | 47 +++-----
src/rygel/rygel-media-object-search.vala | 84 -------------
src/rygel/rygel-simple-container.vala | 83 +++----------
10 files changed, 130 insertions(+), 412 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 4a869de..75d7b0c 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -72,10 +72,11 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
}
}
- public override void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
+ public override Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
var media_objects = new ArrayList <MediaObject> ();
// First add the child containers
@@ -98,48 +99,18 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
uint stop = offset + max_count;
stop = stop.clamp (0, this.child_count);
- var children = media_objects.slice ((int) offset, (int) stop);
-
- var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
- (this, callback);
- res.data = children;
- res.complete_in_idle ();
- }
-
- public override Gee.List<MediaObject>? get_children_finish (
- AsyncResult res)
- throws GLib.Error {
- var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
- return simple_res.data;
+ return media_objects.slice ((int) offset, (int) stop);
}
- public override void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
-
+ public override MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws GLib.Error {
MediaObject media_object = find_container (id);
if (media_object == null && ExternalItem.id_valid (id)) {
- try {
- media_object = new ExternalItem.for_id (id, this);
- } catch (GLib.Error err) {
- res.error = err;
- }
+ media_object = new ExternalItem.for_id (id, this);
}
- res.data = media_object;
- res.complete_in_idle ();
- }
-
- public override MediaObject? find_object_finish (AsyncResult res)
- throws GLib.Error {
- var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
-
- if (simple_res.error != null) {
- throw simple_res.error;
- } else {
- return simple_res.data;
- }
+ return media_object;
}
public string substitute_keywords (string title) {
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 86d8ae8..00b5c18 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -30,28 +30,17 @@ internal class Rygel.NullContainer : MediaContainer {
base.root ("MediaExport", 0);
}
- public override void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<int> (this, callback);
- res.complete_in_idle ();
- }
-
- public override Gee.List<MediaObject>? get_children_finish (AsyncResult res)
- throws Error {
+ public override Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error {
return new Gee.ArrayList<MediaObject>();
}
- public override void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<int> (this, callback);
- res.complete_in_idle ();
- }
-
- public override MediaObject? find_object_finish (AsyncResult res)
- throws Error {
+ public override MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws Error {
return null;
}
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 5e2159f..bb1590a 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -47,8 +47,6 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
public string[] keywords;
- Gee.List<AsyncResult> results;
-
public TrackerSearchContainer (string id,
MediaContainer parent,
string title,
@@ -68,8 +66,6 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
* this field up2date at all times
*/
this.get_children_count ();
-
- this.results = new Gee.ArrayList<AsyncResult>();
} catch (DBus.Error error) {
critical ("Failed to connect to session bus: %s\n", error.message);
}
@@ -103,101 +99,55 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
}
}
- public override void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<ArrayList<MediaObject>> (this,
- callback);
- res.data = new ArrayList<MediaObject> ();
- this.results.add (res);
-
- try {
- string[] keys = TrackerItem.get_metadata_keys ();
-
- var search_result = this.search.query (0,
- this.service,
- keys,
- "",
- this.keywords,
- this.query_condition,
- false,
- new string[0],
- false,
- (int) offset,
- (int) max_count);
-
- /* Iterate through all items */
- for (uint i = 0; i < search_result.length[0]; i++) {
- string path = search_result[i, 0];
- string service = search_result[i, 1];
- string[] metadata = this.slice_strvv_tail (search_result, i, 2);
-
- var item = this.create_item (service, path, metadata);
- res.data.add (item);
- }
- } catch (GLib.Error error) {
- res.error = error;
+ public override Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ string[] keys = TrackerItem.get_metadata_keys ();
+
+ var search_result = this.search.query (0,
+ this.service,
+ keys,
+ "",
+ this.keywords,
+ this.query_condition,
+ false,
+ new string[0],
+ false,
+ (int) offset,
+ (int) max_count);
+
+ var children = new ArrayList<MediaObject> ();
+ /* Iterate through all items */
+ for (uint i = 0; i < search_result.length[0]; i++) {
+ string path = search_result[i, 0];
+ string service = search_result[i, 1];
+ string[] metadata = this.slice_strvv_tail (search_result, i, 2);
+
+ var item = this.create_item (service, path, metadata);
+ children.add (item);
}
- res.complete_in_idle ();
+ return children;
}
- public override Gee.List<MediaObject>? get_children_finish (
- AsyncResult res)
- throws GLib.Error {
- var search_res = res as SimpleAsyncResult<ArrayList<MediaObject>>;
-
- this.results.remove (search_res);
+ public override MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ string parent_id;
+ string service;
- if (search_res.error != null) {
- throw search_res.error;
- } else {
- return search_res.data;
- }
- }
-
- public override void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<MediaObject> (this, callback);
-
- this.results.add (res);
-
- try {
- string parent_id;
- string service;
-
- var path = this.get_item_info (id, out parent_id, out service);
- if (path == null) {
- res.complete_in_idle ();
-
- return;
- }
-
- string[] keys = TrackerItem.get_metadata_keys ();
-
- var values = this.metadata.get (service, path, keys);
-
- res.data = this.create_item (service, path, values);
- } catch (DBus.Error error) {
- res.error = error;
+ var path = this.get_item_info (id, out parent_id, out service);
+ if (path == null) {
+ return null;
}
- res.complete_in_idle ();
- }
-
- public override MediaObject? find_object_finish (AsyncResult res)
- throws GLib.Error {
- var metadata_res = res as SimpleAsyncResult<MediaObject>;
+ string[] keys = TrackerItem.get_metadata_keys ();
- this.results.remove (metadata_res);
+ var values = this.metadata.get (service, path, keys);
- if (metadata_res.error != null) {
- throw metadata_res.error;
- } else {
- return metadata_res.data;
- }
+ return this.create_item (service, path, values);
}
public bool is_thy_child (string item_id) {
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 2804256..14aa8c1 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -66,7 +66,6 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
rygel-media-object.vala \
rygel-media-container.vala \
rygel-simple-container.vala \
- rygel-media-object-search.vala \
rygel-simple-async-result.vala \
rygel-media-item.vala \
rygel-thumbnail.vala \
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 7d77036..8b52a3f 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -96,17 +96,10 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
return;
}
- this.root_container.find_object (this.object_id,
- this.cancellable,
- this.on_media_object_found);
- }
-
- private void on_media_object_found (Object? source_object,
- AsyncResult res) {
- var container = (MediaContainer) source_object;
-
try {
- this.media_object = container.find_object_finish (res);
+ this.media_object = this.root_container.find_object (
+ this.object_id,
+ this.cancellable);
} catch (Error err) {
this.handle_error (err);
return;
@@ -256,18 +249,10 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
private void fetch_children () {
var container = (MediaContainer) this.media_object;
- container.get_children (this.index,
- this.requested_count,
- this.cancellable,
- this.on_children_fetched);
- }
-
- private void on_children_fetched (Object? source_object,
- AsyncResult res) {
- var container = (MediaContainer) source_object;
-
try {
- var children = container.get_children_finish (res);
+ var children = container.get_children (this.index,
+ this.requested_count,
+ this.cancellable);
this.number_returned = children.size;
this.serialize_children (children);
diff --git a/src/rygel/rygel-http-request.vala b/src/rygel/rygel-http-request.vala
index c0acf65..0f2b7a7 100644
--- a/src/rygel/rygel-http-request.vala
+++ b/src/rygel/rygel-http-request.vala
@@ -97,9 +97,28 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
}
// Fetch the requested item
- this.root_container.find_object (this.item_id,
- null,
- this.on_item_found);
+ MediaObject media_object;
+ try {
+ media_object = this.root_container.find_object (this.item_id, null);
+ } catch (Error err) {
+ this.handle_error (err);
+ return;
+ }
+
+ if (media_object == null || !(media_object is MediaItem)) {
+ this.handle_error (new HTTPRequestError.NOT_FOUND (
+ "requested item '%s' not found",
+ this.item_id));
+ return;
+ }
+
+ this.item = (MediaItem) media_object;
+
+ if (this.thumbnail_index >= 0) {
+ this.thumbnail = this.item.thumbnails.get (this.thumbnail_index);
+ }
+
+ this.handle_item_request ();
}
private void on_response_completed (HTTPResponse response) {
@@ -133,34 +152,6 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
}
}
- private void on_item_found (GLib.Object? source_object,
- AsyncResult res) {
- var container = (MediaContainer) source_object;
-
- MediaObject media_object;
- try {
- media_object = container.find_object_finish (res);
- } catch (Error err) {
- this.handle_error (err);
- return;
- }
-
- if (media_object == null || !(media_object is MediaItem)) {
- this.handle_error (new HTTPRequestError.NOT_FOUND (
- "requested item '%s' not found",
- this.item_id));
- return;
- }
-
- this.item = (MediaItem) media_object;
-
- if (this.thumbnail_index >= 0) {
- this.thumbnail = this.item.thumbnails.get (this.thumbnail_index);
- }
-
- this.handle_item_request ();
- }
-
private void parse_query () throws Error {
if (this.query == null) {
return;
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index 95991cd..eb88b6f 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -59,29 +59,19 @@ public abstract class Rygel.MediaContainer : MediaObject {
}
/**
- * Fetches the list of media objects directly under this container and
- * calls callback once the result is ready.
+ * Fetches the list of media objects directly under this container.
*
* @param offet zero-based index of the first item to return
* @param max_count maximum number of objects to return
* @param cancellable optional cancellable for this operation
- * @param callback function to call when result is ready
- */
- public abstract void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback);
-
- /**
- * Finishes the operation started by #get_children.
- *
- * @param res an AsyncResult
*
* return A list of media objects.
*/
- public abstract Gee.List<MediaObject>? get_children_finish (
- AsyncResult res)
- throws Error;
+ public abstract Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error;
/**
* Recursively searches for media object with the given id in this
@@ -91,20 +81,11 @@ public abstract class Rygel.MediaContainer : MediaObject {
* @param cancellable optional cancellable for this operation
* @param callback function to call when result is ready
*
+ * return the found media object.
*/
- public abstract void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback);
-
- /**
- * Finishes the search operation started by #find_object.
- *
- * @param res an AsyncResult
- *
- * return the found media object.
- */
- public abstract MediaObject? find_object_finish (AsyncResult res)
- throws Error;
+ public abstract MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws Error;
/**
* Method to be be called each time this container is updated (metadata
diff --git a/src/rygel/rygel-media-db-container.vala b/src/rygel/rygel-media-db-container.vala
index 70c170b..80888bc 100644
--- a/src/rygel/rygel-media-db-container.vala
+++ b/src/rygel/rygel-media-db-container.vala
@@ -43,42 +43,25 @@ public class Rygel.MediaDBContainer : MediaContainer {
this.child_count = media_db.get_child_count (this.id);
}
- public override void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<Gee.ArrayList<MediaObject>>
- (this,
- callback);
- res.data = this.media_db.get_children (this.id,
- offset,
- max_count);
- res.complete_in_idle ();
- }
-
- public override Gee.List<MediaObject>? get_children_finish (
- AsyncResult res)
- throws GLib.Error {
- var result = (SimpleAsyncResult<Gee.ArrayList<MediaObject>>)res;
-
- foreach (var obj in result.data) {
- obj.parent = this;
+ public override Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ var children = this.media_db.get_children (this.id,
+ offset,
+ max_count);
+ foreach (var child in children) {
+ child.parent = this;
}
- return result.data;
- }
-
-
- public override void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new SimpleAsyncResult<MediaObject> (this, callback);
- res.data = media_db.get_object (id);
- res.complete_in_idle ();
+ return children;
}
- public override MediaObject? find_object_finish (AsyncResult res) {
- return ((SimpleAsyncResult<MediaObject>)res).data;
+ public override MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws GLib.Error {
+ return media_db.get_object (id);
}
}
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index a699457..7d1d1af 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -32,15 +32,12 @@ using Gee;
public class Rygel.SimpleContainer : Rygel.MediaContainer {
public ArrayList<MediaObject> children;
- private ArrayList<MediaObjectSearch> searches;
-
public SimpleContainer (string id,
MediaContainer? parent,
string title) {
base (id, parent, title, 0);
this.children = new ArrayList<MediaObject> ();
- this.searches = new ArrayList<MediaObjectSearch> ();
}
public SimpleContainer.root (string title) {
@@ -59,33 +56,20 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
this.child_count--;
}
- public override void get_children (uint offset,
- uint max_count,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
+ public override Gee.List<MediaObject>? get_children (
+ uint offset,
+ uint max_count,
+ Cancellable? cancellable)
+ throws Error {
uint stop = offset + max_count;
stop = stop.clamp (0, this.child_count);
- var media_objects = this.children.slice ((int) offset, (int) stop);
-
- var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
- (this, callback);
- res.data = media_objects;
- res.complete_in_idle ();
+ return this.children.slice ((int) offset, (int) stop);
}
- public override Gee.List<MediaObject>? get_children_finish (
- AsyncResult res)
- throws GLib.Error {
- var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
- return simple_res.data;
- }
-
- public override void find_object (string id,
- Cancellable? cancellable,
- AsyncReadyCallback callback) {
- var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
-
+ public override MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws Error {
MediaObject child = null;
foreach (var tmp in this.children) {
@@ -96,51 +80,20 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
}
}
- if (child != null) {
- res.data = child;
- res.complete_in_idle ();
- } else {
- var containers = new ArrayList<MediaContainer> ();
-
+ if (child == null) {
+ // Recurse into the child containers
foreach (var tmp in this.children) {
if (tmp is MediaContainer) {
- containers.add (tmp as MediaContainer);
+ var container = tmp as MediaContainer;
+
+ child = container.find_object (id, cancellable);
+ if (child != null) {
+ break;
+ }
}
}
-
- var search = new MediaObjectSearch
- <Rygel.SimpleAsyncResult<MediaObject>> (
- id,
- containers,
- res,
- cancellable);
- search.completed.connect (this.on_object_search_completed);
-
- this.searches.add (search);
-
- search.run ();
- }
- }
-
- public override MediaObject? find_object_finish (AsyncResult res)
- throws GLib.Error {
- var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
-
- if (simple_res.error != null) {
- throw simple_res.error;
- } else {
- return simple_res.data;
}
- }
-
- private void on_object_search_completed (StateMachine state_machine) {
- var search = state_machine as
- MediaObjectSearch<Rygel.SimpleAsyncResult<MediaObject>>;
-
- search.data.data = search.media_object;
- search.data.error = search.error;
- search.data.complete ();
- this.searches.remove (search);
+ return child;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]