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



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

Log:
Utilize generics in AsyncResult so it can hold any type of data.

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-simple-async-result.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:30 2009
@@ -67,15 +67,17 @@
 
         var channels = this.channels.slice ((int) offset, (int) stop);
 
-        var res = new Rygel.SimpleAsyncResult (this, callback, channels, null);
+        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
+                                                (this, callback);
+        res.data = channels;
         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;
+        var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
+        return simple_res.data;
     }
 
     public override void find_object (string             id,
@@ -89,14 +91,16 @@
             }
         }
 
-        var res = new Rygel.SimpleAsyncResult (this, callback, channel, null);
+        var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
+
+        res.data = channel;
         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;
+        var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
+        return simple_res.data;
     }
 
     public MediaObject? find_object_sync (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:30 2009
@@ -107,15 +107,17 @@
         stop = stop.clamp (0, this.child_count);
         var groups = this.groups.slice ((int) offset, (int) stop);
 
-        var res = new Rygel.SimpleAsyncResult (this, callback, groups, null);
+        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>>
+                                                (this, callback);
+        res.data = groups;
         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;
+        var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
+        return simple_res.data;
     }
 
     public override void find_object (string             id,
@@ -128,17 +130,16 @@
             media_object = find_channel_by_id (id);
         }
 
-        var res = new Rygel.SimpleAsyncResult (this,
-                                               callback,
-                                               media_object,
-                                               null);
+        var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
+
+        res.data = media_object;
         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;
+        var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
+        return simple_res.data;
     }
 
     // Private methods

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:30 2009
@@ -57,28 +57,33 @@
         stop = stop.clamp (0, this.child_count);
         var children = this.items.slice ((int) offset, (int) stop);
 
-        var res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+        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) res;
-        return (Gee.List<MediaObject>) simple_res.obj;
+        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 (this, callback, null, id);
+        var res = new Rygel.SimpleAsyncResult<string> (this, callback);
+
+        res.data = id;
         res.complete_in_idle ();
     }
 
     public override MediaObject? find_object_finish (AsyncResult res)
                                                      throws Error {
         MediaItem item = null;
-        string id = ((Rygel.SimpleAsyncResult) res).str;
+        var id = ((Rygel.SimpleAsyncResult<string>) res).data;
 
         foreach (MediaItem tmp in this.items) {
             if (id == tmp.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:30 2009
@@ -112,8 +112,9 @@
                                        uint               max_count,
                                        Cancellable?       cancellable,
                                        AsyncReadyCallback callback) {
-        Rygel.SimpleAsyncResult res;
-
+        var res = new Rygel.SimpleAsyncResult<Gee.List<MediaObject>> (
+                                                this,
+                                                callback);
 
         try {
             string[] child_paths;
@@ -132,11 +133,9 @@
                 children.add (item);
             }
 
-            res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+            res.data = children;
         } catch (GLib.Error error) {
-            res = new Rygel.SimpleAsyncResult.from_error (this,
-                                                          callback,
-                                                          error);
+            res.error = error;
         }
 
         res.complete_in_idle ();
@@ -145,12 +144,12 @@
     public override Gee.List<MediaObject>? get_children_finish (
                                                          AsyncResult res)
                                                          throws GLib.Error {
-        var simple_res = (Rygel.SimpleAsyncResult) res;
+        var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
 
         if (simple_res.error != null) {
             throw simple_res.error;
         } else {
-            return (Gee.List<MediaObject>) simple_res.obj;
+            return simple_res.data;
         }
     }
 
@@ -180,19 +179,12 @@
     public override void find_object (string             id,
                                       Cancellable?       cancellable,
                                       AsyncReadyCallback callback) {
-        Rygel.SimpleAsyncResult res = null;
-        MediaItem item = null;
+        var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
 
         try {
-            item = this.find_item (id);
+            res.data = 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.error = error;
         }
 
         res.complete_in_idle ();
@@ -200,12 +192,12 @@
 
     public override MediaObject? find_object_finish (AsyncResult res)
                                                      throws GLib.Error {
-        var simple_res = (Rygel.SimpleAsyncResult) res;
+        var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
 
         if (simple_res.error != null) {
             throw simple_res.error;
         } else {
-            return (MediaItem) simple_res.obj;
+            return simple_res.data;
         }
     }
 }

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:30 2009
@@ -70,15 +70,18 @@
         stop = stop.clamp (0, this.child_count);
         var children = this.containers.slice ((int) offset, (int) stop);
 
-        var res = new Rygel.SimpleAsyncResult (this, callback, children, null);
+        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) res;
-        return (Gee.List<MediaObject>) simple_res.obj;
+        var simple_res = (Rygel.SimpleAsyncResult<Gee.List<MediaObject>>) res;
+        return simple_res.data;
     }
 
     public override void find_object (string             id,
@@ -97,18 +100,16 @@
             }
         }
 
-        var res = new Rygel.SimpleAsyncResult (this,
-                                               callback,
-                                               media_object,
-                                               null);
+        var res = new Rygel.SimpleAsyncResult<MediaObject> (this, callback);
+        res.data = media_object;
         res.complete_in_idle ();
     }
 
     public override MediaObject? find_object_finish (AsyncResult res)
                                                      throws GLib.Error {
-        var obj = ((Rygel.SimpleAsyncResult) res).obj;
+        var simple_res = (Rygel.SimpleAsyncResult<MediaObject>) res;
 
-        return (MediaObject) obj;
+        return simple_res.data;
     }
 
     /* Private methods */

Modified: trunk/src/rygel/rygel-simple-async-result.vala
==============================================================================
--- trunk/src/rygel/rygel-simple-async-result.vala	(original)
+++ trunk/src/rygel/rygel-simple-async-result.vala	Mon Feb  9 22:29:30 2009
@@ -22,36 +22,20 @@
 
 /**
  * A simple implementation of GLib.AsyncResult, very similar to
- * GLib.SimpleAsyncResult that provides holders for a string, object and
- * error reference.
+ * GLib.SimpleAsyncResult that provides holders for generic and error
+ * reference/values.
  */
-public class Rygel.SimpleAsyncResult : GLib.Object, GLib.AsyncResult {
+public class Rygel.SimpleAsyncResult<G> : GLib.Object, GLib.AsyncResult {
     private Object source_object;
     private AsyncReadyCallback callback;
 
-    public string str;
-    public Object obj;
-
+    public G data;
     public Error error;
 
     public SimpleAsyncResult (Object             source_object,
-                              AsyncReadyCallback callback,
-                              Object?            obj,
-                              string?            str) {
+                              AsyncReadyCallback callback) {
         this.source_object = source_object;
         this.callback = callback;
-
-        this.obj = obj;
-        this.str = str;
-    }
-
-    public SimpleAsyncResult.from_error (Object             source_object,
-                                         AsyncReadyCallback callback,
-                                         Error              error) {
-        this.source_object = source_object;
-        this.callback = callback;
-
-        this.error = error;
     }
 
     public unowned GLib.Object get_source_object () {



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