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



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

Log:
Turn MediaContainer.find_object() async.

A GIO-based API divided in two methods find_object and find_object_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-http-request.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:05 2009
@@ -67,7 +67,28 @@
         return this.channels.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string id) throws GLib.Error {
+    public override void find_object (string             id,
+                                      Cancellable?       cancellable,
+                                      AsyncReadyCallback callback) {
+        MediaObject channel = null;
+        foreach (var tmp in this.channels) {
+            if (tmp.id == id) {
+                channel = tmp;
+                break;
+            }
+        }
+
+        var res = new Rygel.SimpleAsyncResult (this, callback, channel, null);
+        res.complete_in_idle ();
+    }
+
+    public override MediaObject? find_object_finish (AsyncResult res)
+                                                     throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (MediaObject) simple_res.obj;
+    }
+
+    public MediaObject? find_object_sync (string id) {
         MediaObject channel = null;
         foreach (var tmp in this.channels) {
             if (tmp.id == 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:05 2009
@@ -107,7 +107,9 @@
         return this.groups.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string id) throws GLib.Error {
+    public override void find_object (string             id,
+                                      Cancellable?       cancellable,
+                                      AsyncReadyCallback callback) {
         // First try groups
         MediaObject media_object = find_group_by_id (id);
 
@@ -115,7 +117,17 @@
             media_object = find_channel_by_id (id);
         }
 
-        return media_object;
+        var res = new Rygel.SimpleAsyncResult (this,
+                                               callback,
+                                               media_object,
+                                               null);
+        res.complete_in_idle ();
+    }
+
+    public override MediaObject? find_object_finish (AsyncResult res)
+                                                     throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+        return (MediaObject) simple_res.obj;
     }
 
     // Private methods
@@ -137,7 +149,7 @@
         MediaObject channel = null;
 
         foreach (DVBChannelGroup group in this.groups) {
-            channel = group.find_object (id);
+            channel = group.find_object_sync (id);
             if (channel != null) {
                 break;
             }

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:05 2009
@@ -57,8 +57,17 @@
         return this.items.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string id) throws GLib.Error {
+    public override void find_object (string             id,
+                                      Cancellable?       cancellable,
+                                      AsyncReadyCallback callback) {
+        var res = new Rygel.SimpleAsyncResult (this, callback, null, id);
+        res.complete_in_idle ();
+    }
+
+    public override MediaObject? find_object_finish (AsyncResult res)
+                                                     throws Error {
         MediaItem item = null;
+        string id = ((Rygel.SimpleAsyncResult) res).str;
 
         foreach (MediaItem tmp in this.items) {
             if (id == tmp.id) {
@@ -70,5 +79,6 @@
 
         return item;
     }
+
 }
 

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:05 2009
@@ -121,7 +121,7 @@
 
         /* Iterate through all items */
         for (uint i = 0; i < child_paths.length; i++) {
-            MediaObject item = this.find_object (child_paths[i]);
+            MediaObject item = this.find_item (child_paths[i]);
             children.add (item);
         }
 
@@ -136,8 +136,8 @@
         return category;
     }
 
-    public override MediaObject? find_object (string id) throws GLib.Error {
-        MediaObject item;
+    public MediaItem? find_item (string id) throws GLib.Error {
+        MediaItem item;
         string path = id;
 
         if (this.child_class == MediaItem.VIDEO_CLASS) {
@@ -150,5 +150,37 @@
 
         return item;
     }
+
+    public override void find_object (string             id,
+                                      Cancellable?       cancellable,
+                                      AsyncReadyCallback callback) {
+        Rygel.SimpleAsyncResult res = null;
+        MediaItem item = null;
+
+        try {
+            item = this.find_item (id);
+        } catch (GLib.Error error) {
+            res = new Rygel.SimpleAsyncResult.from_error (this,
+                                                          callback,
+                                                          error);
+        }
+
+        if (res == null) {
+            res = new Rygel.SimpleAsyncResult (this, callback, item, null);
+        }
+
+        res.complete_in_idle ();
+    }
+
+    public override MediaObject? find_object_finish (AsyncResult res)
+                                                     throws GLib.Error {
+        var simple_res = (Rygel.SimpleAsyncResult) res;
+
+        if (simple_res.error != null) {
+            throw simple_res.error;
+        } else {
+            return (MediaItem) simple_res.obj;
+        }
+    }
 }
 

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:05 2009
@@ -70,7 +70,9 @@
         return this.containers.slice ((int) offset, (int) stop);
     }
 
-    public override MediaObject? find_object (string id) throws GLib.Error {
+    public override void find_object (string             id,
+                                      Cancellable?       cancellable,
+                                      AsyncReadyCallback callback) {
         /* First try containers */
         MediaObject media_object = find_container_by_id (id);
 
@@ -78,11 +80,24 @@
             /* Now try items */
             var container = get_item_parent (id);
 
-            if (container != null)
-                media_object = container.find_object (id);
+            if (container != null) {
+                container.find_object (id, cancellable, callback);
+                return;
+            }
         }
 
-        return media_object;
+        var res = new Rygel.SimpleAsyncResult (this,
+                                               callback,
+                                               media_object,
+                                               null);
+        res.complete_in_idle ();
+    }
+
+    public override MediaObject? find_object_finish (AsyncResult res)
+                                                     throws GLib.Error {
+        var obj = ((Rygel.SimpleAsyncResult) res).obj;
+
+        return (MediaObject) obj;
     }
 
     /* Private methods */

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:05 2009
@@ -101,9 +101,17 @@
             return;
         }
 
+        this.root_container.find_object (this.object_id,
+                                         null,
+                                         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 =
-                        this.root_container.find_object (this.object_id);
+            this.media_object = container.find_object_finish (res);
         } catch (Error err) {
             this.handle_error (err);
             return;

Modified: trunk/src/rygel/rygel-http-request.vala
==============================================================================
--- trunk/src/rygel/rygel-http-request.vala	(original)
+++ trunk/src/rygel/rygel-http-request.vala	Mon Feb  9 22:29:05 2009
@@ -81,7 +81,9 @@
         }
 
         // Fetch the requested item
-        this.fetch_requested_item ();
+        this.root_container.find_object (this.item_id,
+                                         null,
+                                         this.on_item_found);
     }
 
     private void stream_from_gst_source (Element# src) throws Error {
@@ -279,13 +281,15 @@
             }
     }
 
-    private void fetch_requested_item () {
-        MediaObject media_object;
+    private void on_item_found (GLib.Object source_object,
+                                AsyncResult res) {
+        var container = (MediaContainer) source_object;
 
+        MediaObject media_object;
         try {
-            media_object = this.root_container.find_object (this.item_id);
-        } catch (Error error) {
-            this.handle_error (error);
+            media_object = container.find_object_finish (res);
+        } catch (Error err) {
+            this.handle_error (err);
             return;
         }
 

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:05 2009
@@ -63,13 +63,26 @@
 
    /**
      * Recursively searches for media object with the given id in this
-     * container.
+     * container and calls callback when the result is available.
      *
-     * @param id ID of the media object to search for.
+     * @param id ID of the media object to search for
+     * @param cancellable optional cancellable for this operation
+     * @param callback function to call when result is ready
+     *
+     */
+    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 (string id) throws Error;
+    public abstract MediaObject? find_object_finish (AsyncResult res)
+                                                     throws Error;
 }
 
 /**



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