rygel r560 - in trunk/src: plugins/dvb plugins/test plugins/tracker rygel



Author: zeeshanak
Date: Mon Feb  9 22:29:25 2009
New Revision: 560
URL: http://svn.gnome.org/viewvc/rygel?rev=560&view=rev

Log:
Make MediaContainer.get_children async.

A GIO-based API divided in two methods get_children and
get_children_finish.

Modified:
   trunk/src/plugins/dvb/rygel-dvb-channel-group.vala
   trunk/src/plugins/dvb/rygel-dvb-root-container.vala
   trunk/src/plugins/test/rygel-test-root-container.vala
   trunk/src/plugins/tracker/rygel-tracker-container.vala
   trunk/src/plugins/tracker/rygel-tracker-root-container.vala
   trunk/src/rygel/rygel-browse.vala
   trunk/src/rygel/rygel-media-container.vala

Modified: trunk/src/plugins/dvb/rygel-dvb-channel-group.vala
==============================================================================
--- trunk/src/plugins/dvb/rygel-dvb-channel-group.vala	(original)
+++ trunk/src/plugins/dvb/rygel-dvb-channel-group.vala	Mon Feb  9 22:29:25 2009
@@ -58,13 +58,24 @@
         this.fetch_channels ();
     }
 
-    public override Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws GLib.Error {
+    public override void get_children (uint               offset,
+                                       uint               max_count,
+                                       Cancellable?       cancellable,
+                                       AsyncReadyCallback callback) {
         uint stop = offset + max_count;
         stop = stop.clamp (0, this.child_count);
 
-        return this.channels.slice ((int) offset, (int) stop);
+        var channels = this.channels.slice ((int) offset, (int) stop);
+
+        var res = new Rygel.SimpleAsyncResult (this, callback, channels, null);
+        res.complete_in_idle ();
+    }
+
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                         AsyncResult res)
+                                                         throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (Gee.List<MediaObject>) simple_res.obj;
     }
 
     public override void find_object (string             id,

Modified: trunk/src/plugins/dvb/rygel-dvb-root-container.vala
==============================================================================
--- trunk/src/plugins/dvb/rygel-dvb-root-container.vala	(original)
+++ trunk/src/plugins/dvb/rygel-dvb-root-container.vala	Mon Feb  9 22:29:25 2009
@@ -98,13 +98,24 @@
         this.child_count = this.groups.size;
     }
 
-    public override Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws GLib.Error {
+    public override void get_children (uint               offset,
+                                       uint               max_count,
+                                       Cancellable?       cancellable,
+                                       AsyncReadyCallback callback) {
         uint stop = offset + max_count;
 
         stop = stop.clamp (0, this.child_count);
-        return this.groups.slice ((int) offset, (int) stop);
+        var groups = this.groups.slice ((int) offset, (int) stop);
+
+        var res = new Rygel.SimpleAsyncResult (this, callback, groups, null);
+        res.complete_in_idle ();
+    }
+
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                         AsyncResult res)
+                                                         throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (Gee.List<MediaObject>) simple_res.obj;
     }
 
     public override void find_object (string             id,

Modified: trunk/src/plugins/test/rygel-test-root-container.vala
==============================================================================
--- trunk/src/plugins/test/rygel-test-root-container.vala	(original)
+++ trunk/src/plugins/test/rygel-test-root-container.vala	Mon Feb  9 22:29:25 2009
@@ -48,13 +48,24 @@
         this.child_count = this.items.size;
     }
 
-    public override Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws GLib.Error {
+    public override void get_children (uint               offset,
+                                       uint               max_count,
+                                       Cancellable?       cancellable,
+                                       AsyncReadyCallback callback) {
         uint stop = offset + max_count;
 
         stop = stop.clamp (0, this.child_count);
-        return this.items.slice ((int) offset, (int) stop);
+        var children = this.items.slice ((int) offset, (int) stop);
+
+        var res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+        res.complete_in_idle ();
+    }
+
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                         AsyncResult res)
+                                                         throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (Gee.List<MediaObject>) simple_res.obj;
     }
 
     public override void find_object (string             id,

Modified: trunk/src/plugins/tracker/rygel-tracker-container.vala
==============================================================================
--- trunk/src/plugins/tracker/rygel-tracker-container.vala	(original)
+++ trunk/src/plugins/tracker/rygel-tracker-container.vala	Mon Feb  9 22:29:25 2009
@@ -108,24 +108,50 @@
         return count;
     }
 
-    public override Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws GLib.Error {
-        ArrayList<MediaObject> children = new ArrayList<MediaObject> ();
+    public override void get_children (uint               offset,
+                                       uint               max_count,
+                                       Cancellable?       cancellable,
+                                       AsyncReadyCallback callback) {
+        Rygel.SimpleAsyncResult res;
+
 
-        string[] child_paths =
-                TrackerContainer.files.GetByServiceType (0,
-                                                         this.category,
-                                                         (int) offset,
-                                                         (int) max_count);
+        try {
+            string[] child_paths;
 
-        /* Iterate through all items */
-        for (uint i = 0; i < child_paths.length; i++) {
-            MediaObject item = this.find_item (child_paths[i]);
-            children.add (item);
+            child_paths = TrackerContainer.files.GetByServiceType (
+                                                        0,
+                                                        this.category,
+                                                        (int) offset,
+                                                        (int) max_count);
+
+            ArrayList<MediaObject> children = new ArrayList<MediaObject> ();
+
+            /* Iterate through all items */
+            for (uint i = 0; i < child_paths.length; i++) {
+                MediaObject item = this.find_item (child_paths[i]);
+                children.add (item);
+            }
+
+            res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+        } catch (GLib.Error error) {
+            res = new Rygel.SimpleAsyncResult.from_error (this,
+                                                          callback,
+                                                          error);
         }
 
-        return children;
+        res.complete_in_idle ();
+    }
+
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                         AsyncResult res)
+                                                         throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+
+        if (simple_res.error != null) {
+            throw simple_res.error;
+        } else {
+            return (Gee.List<MediaObject>) simple_res.obj;
+        }
     }
 
     public static string get_file_category (string uri) throws GLib.Error {

Modified: trunk/src/plugins/tracker/rygel-tracker-root-container.vala
==============================================================================
--- trunk/src/plugins/tracker/rygel-tracker-root-container.vala	(original)
+++ trunk/src/plugins/tracker/rygel-tracker-root-container.vala	Mon Feb  9 22:29:25 2009
@@ -61,13 +61,24 @@
         this.child_count = this.containers.size;
     }
 
-    public override Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws GLib.Error {
+    public override void get_children (uint               offset,
+                                       uint               max_count,
+                                       Cancellable?       cancellable,
+                                       AsyncReadyCallback callback) {
         uint stop = offset + max_count;
 
         stop = stop.clamp (0, this.child_count);
-        return this.containers.slice ((int) offset, (int) stop);
+        var children = this.containers.slice ((int) offset, (int) stop);
+
+        var res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+        res.complete_in_idle ();
+    }
+
+    public override Gee.List<MediaObject>? get_children_finish (
+                                                    AsyncResult res)
+                                                    throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (Gee.List<MediaObject>) simple_res.obj;
     }
 
     public override void find_object (string             id,

Modified: trunk/src/rygel/rygel-browse.vala
==============================================================================
--- trunk/src/rygel/rygel-browse.vala	(original)
+++ trunk/src/rygel/rygel-browse.vala	Mon Feb  9 22:29:25 2009
@@ -260,16 +260,23 @@
     private void fetch_children () {
         var container = (MediaContainer) this.media_object;
 
+         container.get_children (this.index,
+                                 this.requested_count,
+                                 null,
+                                 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 (this.index,
-                                                   this.requested_count);
+            var children = container.get_children_finish (res);
             this.number_returned = children.size;
 
             serialize_children (children);
-        } catch {
-            this.handle_error (
-                new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"));
-            return;
+        } catch (Error err) {
+            this.handle_error (err);
         }
     }
 }

Modified: trunk/src/rygel/rygel-media-container.vala
==============================================================================
--- trunk/src/rygel/rygel-media-container.vala	(original)
+++ trunk/src/rygel/rygel-media-container.vala	Mon Feb  9 22:29:25 2009
@@ -49,17 +49,30 @@
         this.update_id = 0;
     }
 
-   /**
-    * 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
-    *
-    * return A list of media objects.
-    */
-    public abstract Gee.List<MediaObject>? get_children (uint offset,
-                                                         uint max_count)
-                                                         throws Error;
+    /**
+     * Fetches the list of media objects directly under this container and
+     * calls callback once the result is ready.
+     *
+     * @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;
 
    /**
     * Recursively searches for media object with the given id in this



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