[rygel] core: cancellable is now a prop of StateMachine
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: cancellable is now a prop of StateMachine
- Date: Sun, 20 Sep 2009 23:26:37 +0000 (UTC)
commit 9a2d057bef9bcc227e590d610f72a1e2de43d42a
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Sep 17 15:49:38 2009 +0300
core: cancellable is now a prop of StateMachine
Earlier a cancellable was passed to StateMachine.run() although this
cancellable was supposed to be instance property. So now have it as the
property of StateMachine interface.
src/rygel/rygel-browse.vala | 7 +++----
src/rygel/rygel-content-directory.vala | 4 ++--
src/rygel/rygel-http-identity-handler.vala | 13 +++++++++----
src/rygel/rygel-http-request-handler.vala | 2 ++
src/rygel/rygel-http-request.vala | 17 +++++++++--------
src/rygel/rygel-http-response.vala | 13 +++++++------
src/rygel/rygel-http-server.vala | 10 +++++-----
src/rygel/rygel-http-transcode-handler.vala | 7 +++++--
src/rygel/rygel-live-response.vala | 9 +++++----
src/rygel/rygel-seekable-response.vala | 15 ++++++++-------
src/rygel/rygel-simple-container.vala | 17 ++++++++++-------
src/rygel/rygel-state-machine.vala | 5 ++++-
12 files changed, 69 insertions(+), 50 deletions(-)
---
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 55952d1..7d77036 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -54,21 +54,20 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
private ServiceAction action;
private Rygel.DIDLLiteWriter didl_writer;
- private Cancellable cancellable;
+ public Cancellable cancellable { get; set; }
public Browse (ContentDirectory content_dir,
owned ServiceAction action) {
this.root_container = content_dir.root_container;
this.system_update_id = content_dir.system_update_id;
+ this.cancellable = content_dir.cancellable;
this.action = (owned) action;
this.didl_writer =
new Rygel.DIDLLiteWriter (content_dir.http_server);
}
- public void run (Cancellable? cancellable) {
- this.cancellable = cancellable;
-
+ public void run () {
/* Start by parsing the 'in' arguments */
this.parse_args ();
}
diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala
index 2faa80f..89bbc7d 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -120,7 +120,7 @@ public class Rygel.ContentDirectory: Service {
this.action_invoked["GetFeatureList"] += this.get_feature_list_cb;
this.query_variable["FeatureList"] += this.query_feature_list;
- this.http_server.run (this.cancellable);
+ this.http_server.run ();
}
~ContentDirectory () {
@@ -136,7 +136,7 @@ public class Rygel.ContentDirectory: Service {
this.browses.add (browse);
browse.completed += this.on_browse_completed;
- browse.run (this.cancellable);
+ browse.run ();
}
/* GetSystemUpdateID action implementation */
diff --git a/src/rygel/rygel-http-identity-handler.vala b/src/rygel/rygel-http-identity-handler.vala
index ec46794..bf3bcbe 100644
--- a/src/rygel/rygel-http-identity-handler.vala
+++ b/src/rygel/rygel-http-identity-handler.vala
@@ -26,7 +26,9 @@ using GUPnP;
// An HTTP request handler that passes the item content through as is.
internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
- public HTTPIdentityHandler () {}
+ public HTTPIdentityHandler (Cancellable? cancellable) {
+ this.cancellable = cancellable;
+ }
public override void add_response_headers (HTTPRequest request)
throws HTTPRequestError {
@@ -68,7 +70,8 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
request.msg,
request.thumbnail.uri,
request.byte_range,
- request.thumbnail.size);
+ request.thumbnail.size,
+ this.cancellable);
}
var item = request.item;
@@ -83,7 +86,8 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
request.msg,
"RygelLiveResponse",
src,
- request.time_range);
+ request.time_range,
+ this.cancellable);
} else {
if (item.uris.size == 0) {
throw new HTTPRequestError.NOT_FOUND (
@@ -95,7 +99,8 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
request.msg,
item.uris.get (0),
request.byte_range,
- item.size);
+ item.size,
+ this.cancellable);
}
}
diff --git a/src/rygel/rygel-http-request-handler.vala b/src/rygel/rygel-http-request-handler.vala
index 8cb6b84..a99335a 100644
--- a/src/rygel/rygel-http-request-handler.vala
+++ b/src/rygel/rygel-http-request-handler.vala
@@ -27,6 +27,8 @@ using GUPnP;
* HTTP request handler interface.
*/
internal abstract class Rygel.HTTPRequestHandler: GLib.Object {
+ public Cancellable cancellable { get; set; }
+
// Add response headers.
public virtual void add_response_headers (HTTPRequest request)
throws HTTPRequestError {
diff --git a/src/rygel/rygel-http-request.vala b/src/rygel/rygel-http-request.vala
index 09325ba..54bea27 100644
--- a/src/rygel/rygel-http-request.vala
+++ b/src/rygel/rygel-http-request.vala
@@ -41,6 +41,8 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
public Soup.Message msg;
private HashTable<string,string>? query;
+ public Cancellable cancellable { get; set; }
+
private HTTPResponse response;
private string item_id;
@@ -52,13 +54,12 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
private HTTPRequestHandler request_handler;
- private Cancellable cancellable;
-
public HTTPRequest (HTTPServer http_server,
Soup.Server server,
Soup.Message msg,
HashTable<string,string>? query) {
this.http_server = http_server;
+ this.cancellable = http_server.cancellable;
this.root_container = http_server.root_container;
this.server = server;
this.msg = msg;
@@ -66,9 +67,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
this.thumbnail_index = -1;
}
- public void run (Cancellable? cancellable) {
- this.cancellable = cancellable;
-
+ public void run () {
this.server.pause_message (this.msg);
var header = this.msg.request_headers.get (
@@ -87,7 +86,9 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
var target = this.query.lookup ("transcode");
if (target != null) {
var transcoder = this.http_server.get_transcoder (target);
- this.request_handler = new HTTPTranscodeHandler (transcoder);
+ this.request_handler = new HTTPTranscodeHandler (
+ transcoder,
+ this.cancellable);
}
var index = this.query.lookup ("thumbnail");
@@ -102,7 +103,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
}
if (this.request_handler == null) {
- this.request_handler = new HTTPIdentityHandler ();
+ this.request_handler = new HTTPIdentityHandler (this.cancellable);
}
// Fetch the requested item
@@ -132,7 +133,7 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
this.response = this.request_handler.render_body (this);
this.response.completed += on_response_completed;
- this.response.run (this.cancellable);
+ this.response.run ();
} catch (Error error) {
this.handle_error (error);
}
diff --git a/src/rygel/rygel-http-response.vala b/src/rygel/rygel-http-response.vala
index c7c2583..e95c18b 100644
--- a/src/rygel/rygel-http-response.vala
+++ b/src/rygel/rygel-http-response.vala
@@ -27,13 +27,15 @@ internal abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
public Soup.Server server { get; private set; }
protected Soup.Message msg;
- protected Cancellable cancellable;
+ public Cancellable cancellable { get; set; }
public HTTPResponse (Soup.Server server,
Soup.Message msg,
- bool partial) {
+ bool partial,
+ Cancellable? cancellable) {
this.server = server;
this.msg = msg;
+ this.cancellable = cancellable;
if (partial) {
this.msg.set_status (Soup.KnownStatusCode.PARTIAL_CONTENT);
@@ -46,10 +48,9 @@ internal abstract class Rygel.HTTPResponse : GLib.Object, Rygel.StateMachine {
this.server.request_aborted += on_request_aborted;
}
- public virtual void run (Cancellable? cancellable) {
- if (cancellable != null) {
- this.cancellable = cancellable;
- cancellable.cancelled += this.on_cancelled;
+ public virtual void run () {
+ if (this.cancellable != null) {
+ this.cancellable.cancelled += this.on_cancelled;
}
}
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index 0a2bc07..54c8ea6 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -34,7 +34,7 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
public GUPnP.Context context;
private ArrayList<HTTPRequest> requests;
- private Cancellable cancellable;
+ public Cancellable cancellable { get; set; }
public HTTPServer (ContentDirectory content_dir,
string name) throws GLib.Error {
@@ -42,16 +42,16 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
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;
}
- public void run (Cancellable? cancellable) {
+ public void run () {
context.server.add_handler (this.path_root, server_handler);
- if (cancellable != null) {
- this.cancellable = cancellable;
+ if (this.cancellable != null) {
this.cancellable.cancelled += this.on_cancelled;
}
}
@@ -179,7 +179,7 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
request.completed += this.on_request_completed;
this.requests.add (request);
- request.run (this.cancellable);
+ request.run ();
}
}
diff --git a/src/rygel/rygel-http-transcode-handler.vala b/src/rygel/rygel-http-transcode-handler.vala
index a942623..92c4891 100644
--- a/src/rygel/rygel-http-transcode-handler.vala
+++ b/src/rygel/rygel-http-transcode-handler.vala
@@ -30,8 +30,10 @@ using GUPnP;
internal class Rygel.HTTPTranscodeHandler : HTTPRequestHandler {
private Transcoder transcoder;
- public HTTPTranscodeHandler (Transcoder transcoder) {
+ public HTTPTranscodeHandler (Transcoder transcoder,
+ Cancellable? cancellable) {
this.transcoder = transcoder;
+ this.cancellable = cancellable;
}
public override void add_response_headers (HTTPRequest request)
@@ -60,7 +62,8 @@ internal class Rygel.HTTPTranscodeHandler : HTTPRequestHandler {
request.msg,
"RygelLiveResponse",
src,
- request.time_range);
+ request.time_range,
+ this.cancellable);
}
protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item,
diff --git a/src/rygel/rygel-live-response.vala b/src/rygel/rygel-live-response.vala
index 0310323..3d17554 100644
--- a/src/rygel/rygel-live-response.vala
+++ b/src/rygel/rygel-live-response.vala
@@ -44,8 +44,9 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
Soup.Message msg,
string name,
Element src,
- HTTPSeek? time_range) throws Error {
- base (server, msg, false);
+ HTTPSeek? time_range,
+ Cancellable? cancellable) throws Error {
+ base (server, msg, false, cancellable);
this.msg.response_headers.set_encoding (Soup.Encoding.EOF);
@@ -55,8 +56,8 @@ internal class Rygel.LiveResponse : Rygel.HTTPResponse {
this.time_range = time_range;
}
- public override void run (Cancellable? cancellable) {
- base.run (cancellable);
+ public override void run () {
+ base.run ();
// Only bother attempting to seek if the offset is greater than zero.
if (this.time_range != null && this.time_range.start > 0) {
diff --git a/src/rygel/rygel-seekable-response.vala b/src/rygel/rygel-seekable-response.vala
index f16cd6d..fed7bb1 100644
--- a/src/rygel/rygel-seekable-response.vala
+++ b/src/rygel/rygel-seekable-response.vala
@@ -40,8 +40,9 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
Soup.Message msg,
string uri,
HTTPSeek? seek,
- size_t file_length) {
- base (server, msg, seek != null);
+ size_t file_length,
+ Cancellable? cancellable) {
+ base (server, msg, seek != null, cancellable);
this.seek = seek;
this.total_length = file_length;
@@ -59,7 +60,7 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
this.file = File.new_for_uri (uri);
}
- public override void run (Cancellable? cancellable) {
+ public override void run () {
this.cancellable = cancellable;
this.file.read_async (this.priority, cancellable, this.on_file_read);
@@ -95,10 +96,10 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
}
this.input_stream.read_async (this.buffer,
- SeekableResponse.BUFFER_LENGTH,
- this.priority,
- this.cancellable,
- on_contents_read);
+ SeekableResponse.BUFFER_LENGTH,
+ this.priority,
+ this.cancellable,
+ on_contents_read);
}
private void on_contents_read (GLib.Object? source_object,
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index 5a5d20f..9a3b879 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -96,12 +96,12 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
}
}
- var search = new ObjectSearch (id, containers, res);
+ var search = new ObjectSearch (id, containers, res, cancellable);
search.completed.connect (this.on_object_search_completed);
this.searches.add (search);
- search.run (cancellable);
+ search.run ();
}
}
@@ -130,20 +130,24 @@ private class Rygel.ObjectSearch : GLib.Object, Rygel.StateMachine {
public ArrayList<MediaContainer> containers;
public Rygel.SimpleAsyncResult<MediaObject> res;
+ public Cancellable cancellable { get; set; }
+
public ObjectSearch (string id,
ArrayList<MediaContainer> containers,
- SimpleAsyncResult<MediaObject> res) {
+ SimpleAsyncResult<MediaObject> res,
+ Cancellable? cancellable) {
this.id = id;
this.containers = containers;
this.res = res;
+ this.cancellable = cancellable;
}
- public void run (Cancellable? cancellable) {
+ public void run () {
var container = this.containers.get (0);
if (container != null) {
container.find_object (this.id,
- cancellable,
+ this.cancellable,
this.on_object_found);
} else {
this.completed ();
@@ -160,8 +164,7 @@ private class Rygel.ObjectSearch : GLib.Object, Rygel.StateMachine {
// continue the search
this.containers.remove_at (0);
- // FIXME: We are loosing the 'cancellable' from the first call
- this.run (null);
+ this.run ();
} else {
this.completed ();
}
diff --git a/src/rygel/rygel-state-machine.vala b/src/rygel/rygel-state-machine.vala
index 36d7140..5ab6c7a 100644
--- a/src/rygel/rygel-state-machine.vala
+++ b/src/rygel/rygel-state-machine.vala
@@ -28,6 +28,9 @@ public interface Rygel.StateMachine: GLib.Object {
// Signals
public signal void completed ();
- public abstract void run (Cancellable? cancellable);
+ // Props
+ public abstract Cancellable cancellable { get; set; }
+
+ public abstract void run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]