[rygel] core,plugins: Asynchronous MediaContainer & StateMachine



commit d38794fea7949e4bede6fd169b81034431e6505f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Oct 16 01:01:45 2009 +0300

    core,plugins: Asynchronous MediaContainer & StateMachine
    
    Make MediaContainer and StateMachine interfaces asynchronouse again but
    this time using the new cool vala async syntax. This implies D-Bus
    interfaces used by plugins are now also async.

 src/plugins/external/rygel-external-container.vala |   12 ++--
 .../external/rygel-external-interfaces.vala        |    4 +-
 src/plugins/external/rygel-external-item.vala      |   53 ++++++++++++-------
 .../rygel-media-export-null-container.vala         |    8 ++--
 src/plugins/tracker/rygel-tracker-interfaces.vala  |   50 +++++++++---------
 src/plugins/tracker/rygel-tracker-keywords.vala    |    6 ++-
 .../tracker/rygel-tracker-metadata-values.vala     |   16 ++++--
 .../tracker/rygel-tracker-search-container.vala    |   58 ++++++++++----------
 src/rygel/rygel-browse.vala                        |   22 ++++----
 src/rygel/rygel-content-directory.vala             |   13 +----
 src/rygel/rygel-http-request.vala                  |   15 ++++--
 src/rygel/rygel-http-response.vala                 |    4 +-
 src/rygel/rygel-http-server.vala                   |   10 +---
 src/rygel/rygel-live-response.vala                 |    4 +-
 src/rygel/rygel-media-container.vala               |    8 ++--
 src/rygel/rygel-media-db-container.vala            |    4 +-
 src/rygel/rygel-seekable-response.vala             |    4 +-
 src/rygel/rygel-simple-container.vala              |   36 ++++++++-----
 src/rygel/rygel-state-machine.vala                 |    2 +-
 19 files changed, 174 insertions(+), 155 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-container.vala b/src/plugins/external/rygel-external-container.vala
index 75d7b0c..b680221 100644
--- a/src/plugins/external/rygel-external-container.vala
+++ b/src/plugins/external/rygel-external-container.vala
@@ -72,7 +72,7 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
         }
     }
 
-    public override Gee.List<MediaObject>? get_children (
+    public override async Gee.List<MediaObject>? get_children (
                                         uint         offset,
                                         uint         max_count,
                                         Cancellable? cancellable)
@@ -86,7 +86,7 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
         var obj_paths = this.actual_container.items;
         foreach (var obj_path in obj_paths) {
             try {
-                var item = new ExternalItem.for_path (obj_path, this);
+                var item = yield ExternalItem.create_for_path (obj_path, this);
 
                 media_objects.add (item);
             } catch (GLib.Error err) {
@@ -102,12 +102,12 @@ public class Rygel.ExternalContainer : Rygel.MediaContainer {
         return media_objects.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws GLib.Error {
+    public override async MediaObject? find_object (string       id,
+                                                    Cancellable? cancellable)
+                                                    throws GLib.Error {
         MediaObject media_object = find_container (id);
         if (media_object == null && ExternalItem.id_valid (id)) {
-            media_object = new ExternalItem.for_id (id, this);
+            media_object = yield ExternalItem.create_for_id (id, this);
         }
 
         return media_object;
diff --git a/src/plugins/external/rygel-external-interfaces.vala b/src/plugins/external/rygel-external-interfaces.vala
index ec70992..1e5b4f7 100644
--- a/src/plugins/external/rygel-external-interfaces.vala
+++ b/src/plugins/external/rygel-external-interfaces.vala
@@ -90,6 +90,6 @@ public interface FreeDesktop.DBusObject: DBus.Object {
 
 [DBus (name = "org.freedesktop.DBus.Properties")]
 public interface FreeDesktop.Properties: DBus.Object {
-    public abstract HashTable<string,Value?> get_all (string iface)
-                                                      throws DBus.Error;
+    public abstract async HashTable<string,Value?> get_all (string iface)
+                                                            throws DBus.Error;
 }
diff --git a/src/plugins/external/rygel-external-item.vala b/src/plugins/external/rygel-external-item.vala
index a0cf8e5..e306404 100644
--- a/src/plugins/external/rygel-external-item.vala
+++ b/src/plugins/external/rygel-external-item.vala
@@ -33,41 +33,56 @@ public class Rygel.ExternalItem : Rygel.MediaItem {
     private static string OBJECT_IFACE = "org.gnome.UPnP.MediaObject1";
     private static string ITEM_IFACE = "org.gnome.UPnP.MediaItem1";
 
-    public ExternalItem.for_path (string            object_path,
-                                  ExternalContainer parent) throws GLib.Error {
-        this ("item:" + object_path, object_path, parent);
+    public static async ExternalItem create_for_path (
+                                        string            object_path,
+                                        ExternalContainer parent)
+                                        throws GLib.Error {
+        return yield create ("item:" + object_path, object_path, parent);
     }
 
-    public ExternalItem.for_id (string            id,
-                                ExternalContainer parent) throws GLib.Error {
+    public static async ExternalItem create_for_id (string            id,
+                                                    ExternalContainer parent)
+                                                    throws GLib.Error {
         var object_path = id.str ("/");
         assert (object_path != null);
 
-        this (id, object_path, parent);
+        return yield create (id, object_path, parent);
     }
 
-    private ExternalItem (string            id,
-                          string            object_path,
-                          ExternalContainer parent)
-                          throws GLib.Error {
-        base (id,
-              parent,
-              "Unknown",        /* Title Unknown at this point */
-              "Unknown");       /* UPnP Class Unknown at this point */
-
+    private static async ExternalItem create (string            id,
+                                              string            object_path,
+                                              ExternalContainer parent)
+                                              throws GLib.Error {
         DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
 
         var props = connection.get_object (parent.service_name,
                                            object_path)
-                                          as Properties;
+                                           as Properties;
 
-        var object_props = props.get_all (OBJECT_IFACE);
+        var object_props = yield props.get_all (OBJECT_IFACE);
+        var item_props = yield props.get_all (ITEM_IFACE);
+
+        return new ExternalItem (id,
+                                 object_path,
+                                 parent,
+                                 object_props,
+                                 item_props);
+    }
+
+    private ExternalItem (string                   id,
+                          string                   object_path,
+                          ExternalContainer        parent,
+                          HashTable<string,Value?> object_props,
+                          HashTable<string,Value?> item_props)
+                          throws GLib.Error {
+        base (id,
+              parent,
+              "Unknown",        /* Title Unknown at this point */
+              "Unknown");       /* UPnP Class Unknown at this point */
 
         var value = object_props.lookup ("DisplayName");
         this.title = parent.substitute_keywords (value.get_string ());
 
-        var item_props = props.get_all (ITEM_IFACE);
-
         value = item_props.lookup ("Type");
         string type = value.get_string ();
         if (type == "audio") {
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 00b5c18..cf835aa 100644
--- a/src/plugins/media-export/rygel-media-export-null-container.vala
+++ b/src/plugins/media-export/rygel-media-export-null-container.vala
@@ -30,7 +30,7 @@ internal class Rygel.NullContainer : MediaContainer {
         base.root ("MediaExport", 0);
     }
 
-    public override Gee.List<MediaObject>? get_children (
+    public override async Gee.List<MediaObject>? get_children (
                                         uint         offset,
                                         uint         max_count,
                                         Cancellable? cancellable)
@@ -38,9 +38,9 @@ internal class Rygel.NullContainer : MediaContainer {
         return new Gee.ArrayList<MediaObject>();
     }
 
-    public override MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws Error {
+    public override async MediaObject? find_object (string       id,
+                                                    Cancellable? cancellable)
+                                                    throws Error {
         return null;
     }
 
diff --git a/src/plugins/tracker/rygel-tracker-interfaces.vala b/src/plugins/tracker/rygel-tracker-interfaces.vala
index a4b9def..98194f1 100644
--- a/src/plugins/tracker/rygel-tracker-interfaces.vala
+++ b/src/plugins/tracker/rygel-tracker-interfaces.vala
@@ -25,42 +25,42 @@ using DBus;
 
 [DBus (name = "org.freedesktop.Tracker")]
 public interface Rygel.TrackerIface : DBus.Object {
-    public abstract int get_version () throws DBus.Error;
+    public abstract async int get_version () throws DBus.Error;
 }
 
 [DBus (name = "org.freedesktop.Tracker.Keywords")]
 public interface Rygel.TrackerKeywordsIface : DBus.Object {
-    public abstract string[,] get_list (string service) throws DBus.Error;
+    public abstract async string[,] get_list (string service) throws DBus.Error;
 }
 
 [DBus (name = "org.freedesktop.Tracker.Metadata")]
 public interface Rygel.TrackerMetadataIface: DBus.Object {
-    public abstract string[,] get_unique_values (string   service,
-                                                 string[] meta_types,
-                                                 string   query,
-                                                 bool     descending,
-                                                 int      offset,
-                                                 int      max_hits)
-                                                 throws DBus.Error;
+    public abstract async string[,] get_unique_values (string   service,
+                                                       string[] meta_types,
+                                                       string   query,
+                                                       bool     descending,
+                                                       int      offset,
+                                                       int      max_hits)
+                                                       throws DBus.Error;
 
-    public abstract string[] @get (string   service_type,
-                                   string   uri,
-                                   string[] keys)
-                                   throws DBus.Error;
+    public abstract async string[] @get (string   service_type,
+                                         string   uri,
+                                         string[] keys)
+                                         throws DBus.Error;
 }
 
 [DBus (name = "org.freedesktop.Tracker.Search")]
 public interface Rygel.TrackerSearchIface: DBus.Object {
-    public abstract string[,] query (int live_query_id,
-                                     string   service,
-                                     string[] fields,
-                                     string   search_text,
-                                     string[] keywords,
-                                     string   query_condition,
-                                     bool     sort_by_service,
-                                     string[] sort_fields,
-                                     bool     sort_descending,
-                                     int      offset,
-                                     int      max_hits)
-                                     throws DBus.Error;
+    public abstract async string[,] query (int live_query_id,
+                                           string   service,
+                                           string[] fields,
+                                           string   search_text,
+                                           string[] keywords,
+                                           string   query_condition,
+                                           bool     sort_by_service,
+                                           string[] sort_fields,
+                                           bool     sort_descending,
+                                           int      offset,
+                                           int      max_hits)
+                                           throws DBus.Error;
 }
diff --git a/src/plugins/tracker/rygel-tracker-keywords.vala b/src/plugins/tracker/rygel-tracker-keywords.vala
index 2197b71..6bbf2a9 100644
--- a/src/plugins/tracker/rygel-tracker-keywords.vala
+++ b/src/plugins/tracker/rygel-tracker-keywords.vala
@@ -51,13 +51,17 @@ public class Rygel.TrackerKeywords : Rygel.SimpleContainer {
             return;
         }
 
+        this.fetch_keywords.begin ();
+    }
+
+    private async void fetch_keywords () {
         string[,] keywords_list;
 
         try {
             /* FIXME: We need to hook to some tracker signals to keep
              *        this field up2date at all times
              */
-            keywords_list = this.keywords.get_list (SERVICE);
+            keywords_list = yield this.keywords.get_list (SERVICE);
         } catch (DBus.Error error) {
             critical ("error getting all keywords: %s", error.message);
 
diff --git a/src/plugins/tracker/rygel-tracker-metadata-values.vala b/src/plugins/tracker/rygel-tracker-metadata-values.vala
index d39f27d..d492daa 100644
--- a/src/plugins/tracker/rygel-tracker-metadata-values.vala
+++ b/src/plugins/tracker/rygel-tracker-metadata-values.vala
@@ -63,6 +63,10 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
             return;
         }
 
+        this.fetch_metadata_values.begin ();
+    }
+
+    private async void fetch_metadata_values () {
         string[,] values;
 
         try {
@@ -71,12 +75,12 @@ public class Rygel.TrackerMetadataValues : Rygel.SimpleContainer {
             /* FIXME: We need to hook to some tracker signals to keep
              *        this field up2date at all times
              */
-            values = this.metadata.get_unique_values (SERVICE,
-                                                    keys,
-                                                    "",
-                                                    false,
-                                                    0,
-                                                    -1);
+            values = yield this.metadata.get_unique_values (SERVICE,
+                                                            keys,
+                                                            "",
+                                                            false,
+                                                            0,
+                                                            -1);
         } catch (DBus.Error error) {
             critical ("error getting all values for '%s': %s",
                       this.key,
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index b243c04..c11e4cd 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -62,28 +62,28 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
             /* FIXME: We need to hook to some tracker signals to keep
              *        this field up2date at all times
              */
-            this.get_children_count ();
+            this.get_children_count.begin ();
         } catch (DBus.Error error) {
             critical ("Failed to connect to session bus: %s\n", error.message);
         }
     }
 
-    private void get_children_count () {
+    private async void get_children_count () {
         try {
             // We are performing actual search (though an optimized one) to get
             // the hitcount rather than GetHitCount because GetHitCount only
             // allows us to get hit count for Text searches.
-            var search_result = this.search.query (0,
-                                                   this.service,
-                                                   new string[0],
-                                                   "",
-                                                   this.keywords,
-                                                   this.query_condition,
-                                                   false,
-                                                   new string[0],
-                                                   false,
-                                                   0,
-                                                   -1);
+            var search_result = yield this.search.query (0,
+                                                         this.service,
+                                                         new string[0],
+                                                         "",
+                                                         this.keywords,
+                                                         this.query_condition,
+                                                         false,
+                                                         new string[0],
+                                                         false,
+                                                         0,
+                                                         -1);
 
             this.child_count = search_result.length[0];
             this.updated ();
@@ -96,24 +96,24 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
         }
     }
 
-    public override Gee.List<MediaObject>? get_children (
+    public override async 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 search_result = yield 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 */
@@ -129,9 +129,9 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
         return children;
     }
 
-    public override MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws GLib.Error {
+    public override async MediaObject? find_object (string       id,
+                                                    Cancellable? cancellable)
+                                                    throws GLib.Error {
         string parent_id;
         string service;
 
@@ -142,7 +142,7 @@ public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
 
         string[] keys = TrackerItem.get_metadata_keys ();
 
-        var values = this.metadata.get (service, path, keys);
+        var values = yield this.metadata.get (service, path, keys);
 
         return this.create_item (service, path, values);
     }
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 8b52a3f..5f4a23d 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -67,9 +67,9 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
                 new Rygel.DIDLLiteWriter (content_dir.http_server);
     }
 
-    public void run () {
+    public async void run () {
         /* Start by parsing the 'in' arguments */
-        this.parse_args ();
+        yield this.parse_args ();
     }
 
     private void got_media_object () {
@@ -88,7 +88,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         }
     }
 
-    private void fetch_media_object () {
+    private async void fetch_media_object () {
         if (this.object_id == this.root_container.id) {
             this.media_object = this.root_container;
 
@@ -97,7 +97,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         }
 
         try {
-            this.media_object = this.root_container.find_object (
+            this.media_object = yield this.root_container.find_object (
                                         this.object_id,
                                         this.cancellable);
         } catch (Error err) {
@@ -145,10 +145,10 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
             this.requested_count = this.total_matches;
         }
 
-        this.fetch_children ();
+        this.fetch_children.begin ();
     }
 
-    private void parse_args () {
+    private async void parse_args () {
         this.action.get ("ObjectID", typeof (string), out this.object_id,
                     "BrowseFlag", typeof (string), out this.browse_flag,
                     "Filter", typeof (string), out this.filter,
@@ -185,7 +185,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
             return;
         }
 
-        this.fetch_media_object ();
+        yield this.fetch_media_object ();
     }
 
     private void conclude () {
@@ -246,13 +246,13 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         this.conclude ();
     }
 
-    private void fetch_children () {
+    private async void fetch_children () {
         var container = (MediaContainer) this.media_object;
 
         try {
-            var children = container.get_children (this.index,
-                                                   this.requested_count,
-                                                   this.cancellable);
+            var children = yield 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-content-directory.vala b/src/rygel/rygel-content-directory.vala
index 89bbc7d..65d50b3 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -56,7 +56,6 @@ public class Rygel.ContentDirectory: Service {
     private bool clear_updated_containers;
     private uint update_notify_id;
 
-    private ArrayList<Browse> browses;
     internal Cancellable cancellable;
 
     public uint32 system_update_id;
@@ -80,7 +79,6 @@ public class Rygel.ContentDirectory: Service {
             return;
         }
 
-        this.browses = new ArrayList<Browse> ();
         this.updated_containers =  new ArrayList<MediaContainer> ();
 
         this.root_container.container_updated += on_container_updated;
@@ -120,7 +118,7 @@ public class Rygel.ContentDirectory: Service {
         this.action_invoked["GetFeatureList"] += this.get_feature_list_cb;
         this.query_variable["FeatureList"] += this.query_feature_list;
 
-        this.http_server.run ();
+        this.http_server.run.begin ();
     }
 
     ~ContentDirectory () {
@@ -133,10 +131,7 @@ public class Rygel.ContentDirectory: Service {
                                     owned ServiceAction action) {
         Browse browse = new Browse (this, action);
 
-        this.browses.add (browse);
-        browse.completed += this.on_browse_completed;
-
-        browse.run ();
+        browse.run.begin ();
     }
 
     /* GetSystemUpdateID action implementation */
@@ -222,10 +217,6 @@ public class Rygel.ContentDirectory: Service {
         value.set_string (this.feature_list);
     }
 
-    private void on_browse_completed (Browse browse) {
-        this.browses.remove (browse);
-    }
-
     private string create_container_update_ids () {
         var update_ids = "";
 
diff --git a/src/rygel/rygel-http-request.vala b/src/rygel/rygel-http-request.vala
index 0f2b7a7..8fb2552 100644
--- a/src/rygel/rygel-http-request.vala
+++ b/src/rygel/rygel-http-request.vala
@@ -67,7 +67,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
         this.thumbnail_index = -1;
     }
 
-    public void run () {
+    public async void run () {
         this.server.pause_message (this.msg);
 
         var header = this.msg.request_headers.get (
@@ -96,10 +96,15 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
             this.request_handler = new HTTPIdentityHandler (this.cancellable);
         }
 
+        yield this.find_item ();
+    }
+
+    public async void find_item () {
         // Fetch the requested item
         MediaObject media_object;
         try {
-            media_object = this.root_container.find_object (this.item_id, null);
+            media_object = yield this.root_container.find_object (this.item_id,
+                                                                  null);
         } catch (Error err) {
             this.handle_error (err);
             return;
@@ -118,14 +123,14 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
             this.thumbnail = this.item.thumbnails.get (this.thumbnail_index);
         }
 
-        this.handle_item_request ();
+        yield this.handle_item_request ();
     }
 
     private void on_response_completed (HTTPResponse response) {
         this.end (Soup.KnownStatusCode.NONE);
     }
 
-    private void handle_item_request () {
+    private async void handle_item_request () {
         try {
             this.byte_range = HTTPSeek.from_byte_range(this.msg);
             this.time_range = HTTPSeek.from_time_range(this.msg);
@@ -146,7 +151,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
 
             this.response = this.request_handler.render_body (this);
             this.response.completed += on_response_completed;
-            this.response.run ();
+            yield this.response.run ();
         } catch (Error error) {
             this.handle_error (error);
         }
diff --git a/src/rygel/rygel-http-response.vala b/src/rygel/rygel-http-response.vala
index e95c18b..5160222 100644
--- a/src/rygel/rygel-http-response.vala
+++ b/src/rygel/rygel-http-response.vala
@@ -46,14 +46,14 @@ internal abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
         this.msg.response_body.set_accumulate (false);
 
         this.server.request_aborted += on_request_aborted;
-    }
 
-    public virtual void run () {
         if (this.cancellable != null) {
             this.cancellable.cancelled += this.on_cancelled;
         }
     }
 
+    public abstract async void run ();
+
     private void on_cancelled (Cancellable cancellable) {
         this.end (true, Soup.KnownStatusCode.CANCELLED);
     }
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index 5e03ff7..d67a9e3 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -32,7 +32,6 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
     // Reference to root container of associated ContentDirectory
     public MediaContainer root_container;
     public GUPnP.Context context;
-    private ArrayList<HTTPRequest> requests;
 
     public Cancellable cancellable { get; set; }
 
@@ -43,12 +42,11 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
         this.root_container = content_dir.root_container;
         this.context = content_dir.context;
         this.cancellable = content_dir.cancellable;
-        this.requests = new ArrayList<HTTPRequest> ();
 
         this.path_root = SERVER_PATH_PREFIX + "/" + name;
     }
 
-    public void run () {
+    public async void run () {
         context.server.add_handler (this.path_root, server_handler);
 
         if (this.cancellable != null) {
@@ -164,9 +162,6 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
         debug ("HTTP %s request for URI '%s' handled.",
                request.msg.method,
                request.msg.get_uri ().to_string (false));
-
-        /* Remove the request from our list. */
-        this.requests.remove (request);
     }
 
     private void server_handler (Soup.Server               server,
@@ -184,9 +179,8 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
         var request = new HTTPRequest (this, server, msg, query);
 
         request.completed += this.on_request_completed;
-        this.requests.add (request);
 
-        request.run ();
+        request.run.begin ();
     }
 }
 
diff --git a/src/rygel/rygel-live-response.vala b/src/rygel/rygel-live-response.vala
index b673f2f..102a6a0 100644
--- a/src/rygel/rygel-live-response.vala
+++ b/src/rygel/rygel-live-response.vala
@@ -56,9 +56,7 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
         this.time_range = time_range;
     }
 
-    public override void run () {
-        base.run ();
-
+    public override async void run () {
         // Only bother attempting to seek if the offset is greater than zero.
         if (this.time_range != null && this.time_range.start > 0) {
             this.pipeline.set_state (State.PAUSED);
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index eb88b6f..342350b 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -67,7 +67,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
      *
      * return A list of media objects.
      */
-    public abstract Gee.List<MediaObject>? get_children (
+    public async abstract Gee.List<MediaObject>? get_children (
                                         uint               offset,
                                         uint               max_count,
                                         Cancellable?       cancellable)
@@ -83,9 +83,9 @@ public abstract class Rygel.MediaContainer : MediaObject {
     *
     * return the found media object.
     */
-    public abstract MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws Error;
+    public async 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 80888bc..349e45a 100644
--- a/src/rygel/rygel-media-db-container.vala
+++ b/src/rygel/rygel-media-db-container.vala
@@ -43,7 +43,7 @@ public class Rygel.MediaDBContainer : MediaContainer {
         this.child_count = media_db.get_child_count (this.id);
     }
 
-    public override Gee.List<MediaObject>? get_children (
+    public override async Gee.List<MediaObject>? get_children (
                                         uint               offset,
                                         uint               max_count,
                                         Cancellable?       cancellable)
@@ -58,7 +58,7 @@ public class Rygel.MediaDBContainer : MediaContainer {
         return children;
     }
 
-    public override MediaObject? find_object (string       id,
+    public override async MediaObject? find_object (string       id,
                                               Cancellable? cancellable)
                                               throws GLib.Error {
         return media_db.get_object (id);
diff --git a/src/rygel/rygel-seekable-response.vala b/src/rygel/rygel-seekable-response.vala
index fed7bb1..27cec07 100644
--- a/src/rygel/rygel-seekable-response.vala
+++ b/src/rygel/rygel-seekable-response.vala
@@ -60,9 +60,7 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
         this.file = File.new_for_uri (uri);
     }
 
-    public override void run () {
-        this.cancellable = cancellable;
-
+    public override async void run () {
         this.file.read_async (this.priority, cancellable, this.on_file_read);
     }
 
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index 7d1d1af..46fb191 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -56,7 +56,7 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
         this.child_count--;
     }
 
-    public override Gee.List<MediaObject>? get_children (
+    public override async Gee.List<MediaObject>? get_children (
                                         uint         offset,
                                         uint         max_count,
                                         Cancellable? cancellable)
@@ -67,9 +67,9 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
         return this.children.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string       id,
-                                              Cancellable? cancellable)
-                                              throws Error {
+    public override async MediaObject? find_object (string       id,
+                                                    Cancellable? cancellable)
+                                                    throws Error {
         MediaObject child = null;
 
         foreach (var tmp in this.children) {
@@ -81,15 +81,25 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
         }
 
         if (child == null) {
-            // Recurse into the child containers
-            foreach (var tmp in this.children) {
-                if (tmp is MediaContainer) {
-                    var container = tmp as MediaContainer;
-
-                    child = container.find_object (id, cancellable);
-                    if (child != null) {
-                        break;
-                    }
+            child = yield this.find_object_in_children (id, cancellable);
+        }
+
+        return child;
+    }
+
+    public async MediaObject? find_object_in_children (string       id,
+                                                       Cancellable? cancellable)
+                                                       throws Error {
+        MediaObject child = null;
+
+        // Recurse into the child containers
+        foreach (var tmp in this.children) {
+            if (tmp is MediaContainer) {
+                var container = tmp as MediaContainer;
+
+                child = yield container.find_object (id, cancellable);
+                if (child != null) {
+                    break;
                 }
             }
         }
diff --git a/src/rygel/rygel-state-machine.vala b/src/rygel/rygel-state-machine.vala
index 5ab6c7a..f3ef622 100644
--- a/src/rygel/rygel-state-machine.vala
+++ b/src/rygel/rygel-state-machine.vala
@@ -31,6 +31,6 @@ public interface Rygel.StateMachine: GLib.Object {
     // Props
     public abstract Cancellable cancellable { get; set; }
 
-    public abstract void run ();
+    public async abstract void run ();
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]