rygel r620 - trunk/src/rygel



Author: zeeshanak
Date: Thu Feb 19 17:17:22 2009
New Revision: 620
URL: http://svn.gnome.org/viewvc/rygel?rev=620&view=rev

Log:
Replace StateMachine.cancel by use of GLib.Cancellable.

Modified:
   trunk/src/rygel/rygel-browse.vala
   trunk/src/rygel/rygel-content-directory.vala
   trunk/src/rygel/rygel-http-request.vala
   trunk/src/rygel/rygel-http-response.vala
   trunk/src/rygel/rygel-http-server.vala
   trunk/src/rygel/rygel-live-response.vala
   trunk/src/rygel/rygel-seekable-response.vala
   trunk/src/rygel/rygel-state-machine.vala

Modified: trunk/src/rygel/rygel-browse.vala
==============================================================================
--- trunk/src/rygel/rygel-browse.vala	(original)
+++ trunk/src/rygel/rygel-browse.vala	Thu Feb 19 17:17:22 2009
@@ -55,6 +55,8 @@
     private ServiceAction action;
     private Rygel.DIDLLiteWriter didl_writer;
 
+    private Cancellable cancellable;
+
     public Browse (ContentDirectory    content_dir,
                    owned ServiceAction action) {
         this.root_container = content_dir.root_container;
@@ -65,7 +67,12 @@
                 new Rygel.DIDLLiteWriter (content_dir.http_server);
     }
 
-    public void run () {
+    public void run (Cancellable? cancellable) {
+        if (cancellable != null) {
+            this.cancellable = cancellable;
+            cancellable.cancelled += this.on_cancelled;
+        }
+
         /* Start DIDL-Lite fragment */
         this.didl_writer.start_didl_lite (null, null, true);
 
@@ -73,7 +80,7 @@
         this.parse_args ();
     }
 
-    public void cancel () {
+    private void on_cancelled (Cancellable cancellable) {
         // FIXME: implement canceling of browse request here
     }
 

Modified: trunk/src/rygel/rygel-content-directory.vala
==============================================================================
--- trunk/src/rygel/rygel-content-directory.vala	(original)
+++ trunk/src/rygel/rygel-content-directory.vala	Thu Feb 19 17:17:22 2009
@@ -57,6 +57,8 @@
     private uint update_notify_id;
 
     private ArrayList<Browse> browses;
+    public Cancellable cancellable;
+
     public uint32 system_update_id;
 
     // Public abstract methods derived classes need to implement
@@ -69,6 +71,7 @@
         this.http_server = new HTTPServer (this, this.get_type ().name ());
 
         this.browses = new ArrayList<Browse> ();
+        this.cancellable = new Cancellable ();
         this.updated_containers =  new ArrayList<MediaContainer> ();
 
         this.root_container.container_updated += on_container_updated;
@@ -110,11 +113,8 @@
     }
 
     ~ContentDirectory () {
-        // Cancel all browse calls
-        foreach (var browse in this.browses) {
-            browse.completed -= this.on_browse_completed;
-            browse.cancel ();
-        }
+        // Cancel all state machines
+        this.cancellable.cancel ();
 
         this.http_server.destroy ();
     }
@@ -127,7 +127,7 @@
         this.browses.add (browse);
         browse.completed += this.on_browse_completed;
 
-        browse.run ();
+        browse.run (this.cancellable);
     }
 
     /* GetSystemUpdateID action implementation */

Modified: trunk/src/rygel/rygel-http-request.vala
==============================================================================
--- trunk/src/rygel/rygel-http-request.vala	(original)
+++ trunk/src/rygel/rygel-http-request.vala	Thu Feb 19 17:17:22 2009
@@ -49,6 +49,8 @@
     private MediaItem item;
     private Seek seek;
 
+    private Cancellable cancellable;
+
     public HTTPRequest (MediaContainer            root_container,
                         Soup.Server               server,
                         Soup.Message              msg,
@@ -61,7 +63,9 @@
         this.server.pause_message (this.msg);
     }
 
-    public void run () {
+    public void run (Cancellable? cancellable) {
+        this.cancellable = cancellable;
+
         if (this.msg.method != "HEAD" && this.msg.method != "GET") {
             /* We only entertain 'HEAD' and 'GET' requests */
             this.handle_error (
@@ -84,12 +88,6 @@
                                          this.on_item_found);
     }
 
-    public void cancel () {
-        if (this.response != null ) {
-            this.response.cancel ();
-        }
-    }
-
     private void stream_from_gst_source (Element# src) throws Error {
         var response = new LiveResponse (this.server,
                                          this.msg,
@@ -98,7 +96,7 @@
         this.response = response;
         response.completed += on_response_completed;
 
-        response.run ();
+        response.run (this.cancellable);
     }
 
     private void serve_uri (string uri, size_t size) {
@@ -110,7 +108,7 @@
         this.response = response;
         response.completed += on_response_completed;
 
-        response.run ();
+        response.run (this.cancellable);
     }
 
     private void on_response_completed (HTTPResponse response) {

Modified: trunk/src/rygel/rygel-http-response.vala
==============================================================================
--- trunk/src/rygel/rygel-http-response.vala	(original)
+++ trunk/src/rygel/rygel-http-response.vala	Thu Feb 19 17:17:22 2009
@@ -27,6 +27,8 @@
     public Soup.Server server { get; private set; }
     protected Soup.Message msg;
 
+    protected Cancellable cancellable;
+
     public HTTPResponse (Soup.Server  server,
                          Soup.Message msg,
                          bool         partial) {
@@ -42,9 +44,14 @@
         this.server.request_aborted += on_request_aborted;
     }
 
-    public abstract void run ();
+    public virtual void run (Cancellable? cancellable) {
+        if (cancellable != null) {
+            this.cancellable = cancellable;
+            cancellable.cancelled += this.on_cancelled;
+        }
+    }
 
-    public void cancel () {
+    private void on_cancelled (Cancellable cancellable) {
         this.end (true, Soup.KnownStatusCode.CANCELLED);
     }
 

Modified: trunk/src/rygel/rygel-http-server.vala
==============================================================================
--- trunk/src/rygel/rygel-http-server.vala	(original)
+++ trunk/src/rygel/rygel-http-server.vala	Thu Feb 19 17:17:22 2009
@@ -35,10 +35,13 @@
     private GUPnP.Context context;
     private ArrayList<HTTPRequest> requests;
 
+    private Cancellable cancellable;
+
     public HTTPServer (ContentDirectory content_dir,
                        string           name) {
         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;
@@ -47,11 +50,8 @@
     }
 
     public void destroy () {
-        // Cancel all http requests
-        foreach (var request in this.requests) {
-            request.completed -= this.on_request_completed;
-            request.cancel ();
-        }
+        // Cancel all state machines
+        this.cancellable.cancel ();
 
         context.server.remove_handler (this.path_root);
     }
@@ -85,7 +85,7 @@
         request.completed += this.on_request_completed;
         this.requests.add (request);
 
-        request.run ();
+        request.run (this.cancellable);
     }
 }
 

Modified: trunk/src/rygel/rygel-live-response.vala
==============================================================================
--- trunk/src/rygel/rygel-live-response.vala	(original)
+++ trunk/src/rygel/rygel-live-response.vala	Thu Feb 19 17:17:22 2009
@@ -53,7 +53,9 @@
         this.prepare_pipeline (name, src);
     }
 
-    public override void run () {
+    public override void run (Cancellable? cancellable) {
+        base.run (cancellable);
+
         // Go to PAUSED first
         this.pipeline.set_state (State.PLAYING);
     }

Modified: trunk/src/rygel/rygel-seekable-response.vala
==============================================================================
--- trunk/src/rygel/rygel-seekable-response.vala	(original)
+++ trunk/src/rygel/rygel-seekable-response.vala	Thu Feb 19 17:17:22 2009
@@ -55,8 +55,10 @@
         this.file = File.new_for_uri (uri);
     }
 
-    public override void run () {
-        this.file.read_async (this.priority, null, this.on_file_read);
+    public override void run (Cancellable? cancellable) {
+        this.cancellable = cancellable;
+
+        this.file.read_async (this.priority, cancellable, this.on_file_read);
     }
 
     private void on_file_read (GLib.Object      source_object,
@@ -75,7 +77,7 @@
 
         if (seek != null) {
             try {
-                input_stream.seek (seek.start, SeekType.SET, null);
+                input_stream.seek (seek.start, SeekType.SET, this.cancellable);
             } catch (Error err) {
                 warning ("Failed to seek to %s-%s on URI %s: %s\n",
                          seek.start.to_string (),
@@ -91,7 +93,7 @@
         input_stream.read_async (this.buffer,
                                  this.length,
                                  this.priority,
-                                 null,
+                                 this.cancellable,
                                  on_contents_read);
     }
 
@@ -112,7 +114,7 @@
         this.push_data (this.buffer, this.length);
 
         input_stream.close_async (this.priority,
-                                  null,
+                                  this.cancellable,
                                   on_input_stream_closed);
     }
 

Modified: trunk/src/rygel/rygel-state-machine.vala
==============================================================================
--- trunk/src/rygel/rygel-state-machine.vala	(original)
+++ trunk/src/rygel/rygel-state-machine.vala	Thu Feb 19 17:17:22 2009
@@ -30,7 +30,6 @@
     // Signals
     public signal void completed ();
 
-    public abstract void run ();
-    public abstract void cancel ();
+    public abstract void run (Cancellable? cancellable);
 }
 



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