More utilization of state-machine in Browse.
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Mon, 9 Feb 2009 22:29:20 +0000 (22:29 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Mon, 9 Feb 2009 22:29:20 +0000 (22:29 +0000)
These changes are particularly for ease of move to async
MediaContainer.get_children method when it's there.

svn path=/trunk/; revision=559

src/rygel/rygel-browse.vala

index 0f66d58..eed106d 100644 (file)
@@ -153,19 +153,14 @@ public class Browse: GLib.Object {
 
         var container = (MediaContainer) this.media_object;
         this.total_matches = container.child_count;
+        this.update_id = container.update_id;
+
         if (this.requested_count == 0) {
             // No max count requested, try to fetch all children
             this.requested_count = this.total_matches;
         }
 
-        if (!this.serialize_children ()) {
-            return;
-        }
-
-        this.update_id = container.update_id;
-
-        // Conclude the successful Browse action
-        this.conclude ();
+        this.fetch_children ();
     }
 
     private void parse_args () {
@@ -241,10 +236,11 @@ public class Browse: GLib.Object {
         this.completed ();
     }
 
-    private bool serialize_children () {
-        var children = this.get_children ();
+    private void serialize_children (Gee.List<MediaObject>? children) {
         if (children == null) {
-            return false;
+            this.handle_error (
+                new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"));
+            return;
         }
 
         /* serialize all children */
@@ -253,27 +249,27 @@ public class Browse: GLib.Object {
                 this.didl_writer.serialize (children[i]);
             } catch (Error err) {
                 this.handle_error (err);
-                return false;
+                return;
             }
         }
 
-        this.number_returned = children.size;
-
-        return true;
+        // Conclude the successful Browse action
+        this.conclude ();
     }
 
-    private Gee.List<MediaObject>? get_children () {
+    private void fetch_children () {
         var container = (MediaContainer) this.media_object;
 
         try {
             var children = container.get_children (this.index,
                                                    this.requested_count);
+            this.number_returned = children.size;
 
-            return children;
+            serialize_children (children);
         } catch {
             this.handle_error (
                 new ContentDirectoryError.NO_SUCH_OBJECT ("No such object"));
-            return null;
+            return;
         }
     }
 }