rygel r616 - trunk/src/rygel



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

Log:
Common interface for all state machine classes.

Added:
   trunk/src/rygel/rygel-state-machine.vala
Modified:
   trunk/src/rygel/Makefile.am
   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

Modified: trunk/src/rygel/Makefile.am
==============================================================================
--- trunk/src/rygel/Makefile.am	(original)
+++ trunk/src/rygel/Makefile.am	Thu Feb 19 17:16:59 2009
@@ -42,6 +42,8 @@
 		rygel-plugin-loader.c \
                 rygel-http-server.c \
                 rygel-http-server.h \
+		rygel-state-machine.c \
+		rygel-state-machine.h \
 		rygel-http-request.c \
 		rygel-http-request.h \
                 rygel-http-response.c \
@@ -92,6 +94,8 @@
 		rygel-plugin-loader.vala \
 		rygel-http-server.c \
 		rygel-http-server.h \
+		rygel-state-machine.c \
+		rygel-state-machine.h \
 		rygel-http-request.c \
 		rygel-http-request.h \
 		rygel-http-response.c \
@@ -138,6 +142,7 @@
 		    rygel-connection-manager.vala \
 		    rygel-media-receiver-registrar.vala \
 		    rygel-http-server.vala \
+		    rygel-state-machine.vala \
 		    rygel-http-request.vala \
 		    rygel-http-response.vala \
 		    rygel-live-response.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:16:59 2009
@@ -25,13 +25,14 @@
 using Rygel;
 using GUPnP;
 using Gee;
+using Soup;
 
 /**
  * Browse action implementation. This class is more or less the state-machine
  * associated with the Browse action handling that exists to make asynchronous
  * handling of Browse action possible.
  */
-public class Rygel.Browse: GLib.Object {
+public class Rygel.Browse: GLib.Object, Rygel.StateMachine {
     // In arguments
     public string object_id;
     public string browse_flag;
@@ -54,9 +55,6 @@
     private ServiceAction action;
     private Rygel.DIDLLiteWriter didl_writer;
 
-    // Signals
-    public signal void completed ();
-
     public Browse (ContentDirectory    content_dir,
                    owned ServiceAction action) {
         this.root_container = content_dir.root_container;
@@ -67,7 +65,7 @@
                 new Rygel.DIDLLiteWriter (content_dir.http_server);
     }
 
-    public void start () {
+    public void run () {
         /* Start DIDL-Lite fragment */
         this.didl_writer.start_didl_lite (null, null, true);
 
@@ -75,6 +73,10 @@
         this.parse_args ();
     }
 
+    public void cancel () {
+        // FIXME: implement canceling of browse request here
+    }
+
     private void got_media_object () {
         if (this.media_object == null) {
             this.handle_error (

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:16:59 2009
@@ -121,7 +121,7 @@
         this.browses.add (browse);
         browse.completed += this.on_browse_completed;
 
-        browse.start ();
+        browse.run ();
     }
 
     /* 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:16:59 2009
@@ -37,7 +37,7 @@
 /**
  * Responsible for handling HTTP client requests.
  */
-public class Rygel.HTTPRequest : GLib.Object {
+public class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
     private MediaContainer root_container;
     private Soup.Server server;
     private Soup.Message msg;
@@ -45,8 +45,6 @@
 
     private HTTPResponse response;
 
-    public signal void handled ();
-
     private string item_id;
     private MediaItem item;
     private Seek seek;
@@ -63,7 +61,7 @@
         this.server.pause_message (this.msg);
     }
 
-    public void start_processing () {
+    public void run () {
         if (this.msg.method != "HEAD" && this.msg.method != "GET") {
             /* We only entertain 'HEAD' and 'GET' requests */
             this.handle_error (
@@ -86,15 +84,21 @@
                                          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,
                                          "RygelLiveResponse",
                                          src);
         this.response = response;
-        response.ended += on_response_ended;
+        response.completed += on_response_completed;
 
-        response.start ();
+        response.run ();
     }
 
     private void serve_uri (string uri, size_t size) {
@@ -104,11 +108,12 @@
                                              this.seek,
                                              size);
         this.response = response;
+        response.completed += on_response_completed;
 
-        response.ended += on_response_ended;
+        response.run ();
     }
 
-    private void on_response_ended (HTTPResponse response) {
+    private void on_response_completed (HTTPResponse response) {
         this.end (Soup.KnownStatusCode.NONE);
     }
 
@@ -323,7 +328,7 @@
             this.msg.set_status (status);
         }
 
-        this.handled ();
+        this.completed ();
     }
 }
 

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:16:59 2009
@@ -23,12 +23,10 @@
 
 using Gst;
 
-public class Rygel.HTTPResponse : GLib.Object {
+public abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
     public Soup.Server server { get; private set; }
     protected Soup.Message msg;
 
-    public signal void ended ();
-
     public HTTPResponse (Soup.Server  server,
                          Soup.Message msg,
                          bool         partial) {
@@ -44,6 +42,12 @@
         this.server.request_aborted += on_request_aborted;
     }
 
+    public abstract void run ();
+
+    public void cancel () {
+        this.end (true, Soup.KnownStatusCode.CANCELLED);
+    }
+
     private void on_request_aborted (Soup.Server        server,
                                      Soup.Message       msg,
                                      Soup.ClientContext client) {
@@ -69,7 +73,7 @@
             this.msg.set_status (status);
         }
 
-        this.ended ();
+        this.completed ();
     }
 }
 

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:16:59 2009
@@ -64,7 +64,7 @@
         return create_uri_for_path (query);
     }
 
-    private void on_request_handled (HTTPRequest request) {
+    private void on_request_completed (HTTPRequest request) {
         /* Remove the request from our list. */
         this.requests.remove (request);
     }
@@ -76,10 +76,10 @@
                                  Soup.ClientContext        soup_client) {
         var request = new HTTPRequest (this.root_container, server, msg, query);
 
-        request.handled += this.on_request_handled;
+        request.completed += this.on_request_completed;
         this.requests.add (request);
 
-        request.start_processing ();
+        request.run ();
     }
 }
 

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:16:59 2009
@@ -53,7 +53,7 @@
         this.prepare_pipeline (name, src);
     }
 
-    public void start () {
+    public override void run () {
         // 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:16:59 2009
@@ -53,7 +53,9 @@
 
         this.buffer = new char[this.length];
         this.file = File.new_for_uri (uri);
+    }
 
+    public override void run () {
         this.file.read_async (this.priority, null, this.on_file_read);
     }
 

Added: trunk/src/rygel/rygel-state-machine.vala
==============================================================================
--- (empty file)
+++ trunk/src/rygel/rygel-state-machine.vala	Thu Feb 19 17:16:59 2009
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2008, 2009 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Rygel;
+
+/**
+ * StateMachine interface.
+ */
+public interface Rygel.StateMachine: GLib.Object {
+    // Signals
+    public signal void completed ();
+
+    public abstract void run ();
+    public abstract void cancel ();
+}
+



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