[rygel] core: Clean-up MediaQueryAction and its subclasses



commit 2296f96c59acc081b169dc740b0886f8e80af005
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Jul 23 19:53:32 2010 +0300

    core: Clean-up MediaQueryAction and its subclasses
    
    Cleaner way to handle error messages and ObjectID argument name in
    MediaQueryAction and its implementations.

 src/rygel/rygel-browse.vala             |   19 +++++++++++++++----
 src/rygel/rygel-media-query-action.vala |   20 +++-----------------
 src/rygel/rygel-search.vala             |   15 +++++++++++----
 3 files changed, 29 insertions(+), 25 deletions(-)
---
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index b89b428..46dfef7 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -37,10 +37,13 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
 
     public Browse (ContentDirectory    content_dir,
                    owned ServiceAction action) {
-        base (content_dir,
-              action,
-              "ObjectID",
-              _("Failed to browse '%s': %s\n"));
+        base (content_dir, action);
+
+        if (this.xbox_hacks != null) {
+            this.object_id_arg = "ContainerID";
+        } else {
+            this.object_id_arg = "ObjectID";
+        }
     }
 
     protected override void parse_args () throws Error {
@@ -113,5 +116,13 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
 
         return children;
     }
+
+    protected override void handle_error (Error error) {
+        warning (_("Failed to browse '%s': %s\n"),
+                 this.object_id,
+                 error.message);
+
+        base.handle_error (error);
+    }
 }
 
diff --git a/src/rygel/rygel-media-query-action.vala b/src/rygel/rygel-media-query-action.vala
index a5e51af..600544e 100644
--- a/src/rygel/rygel-media-query-action.vala
+++ b/src/rygel/rygel-media-query-action.vala
@@ -47,20 +47,15 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
     protected ServiceAction action;
     protected Rygel.DIDLLiteWriter didl_writer;
     protected XBoxHacks xbox_hacks;
+    protected string object_id_arg;
 
-    private string object_id_arg;
-    private string error_message;
 
     protected MediaQueryAction (ContentDirectory    content_dir,
-                                owned ServiceAction action,
-                                string              object_id_arg,
-                                string              error_message) {
+                                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.object_id_arg = object_id_arg;
-        this.error_message = error_message;
 
         this.didl_writer = new Rygel.DIDLLiteWriter (content_dir.http_server);
 
@@ -116,13 +111,6 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
                              out this.sort_criteria);
 
         if (this.object_id == null) {
-            /* Stupid Xbox */
-            this.action.get ("ContainerID",
-                                 typeof (string),
-                                 out this.object_id);
-        }
-
-        if (this.object_id == null) {
             // Sorry we can't do anything without ObjectID
             throw new ContentDirectoryError.NO_SUCH_OBJECT (
                                         _("No such object"));
@@ -183,9 +171,7 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
         this.completed ();
     }
 
-    private void handle_error (Error error) {
-        warning (this.error_message, this.object_id, error.message);
-
+    protected virtual void handle_error (Error error) {
         if (error is ContentDirectoryError) {
             this.action.return_error (error.code, error.message);
         } else {
diff --git a/src/rygel/rygel-search.vala b/src/rygel/rygel-search.vala
index e05b780..8ec2fe8 100644
--- a/src/rygel/rygel-search.vala
+++ b/src/rygel/rygel-search.vala
@@ -34,10 +34,9 @@ internal class Rygel.Search:  Rygel.MediaQueryAction {
 
     public Search (ContentDirectory    content_dir,
                    owned ServiceAction action) {
-        base (content_dir,
-              action,
-              "ContainerID",
-              _("Failed to search in '%s': %s"));
+        base (content_dir, action);
+
+        this.object_id_arg = "ContainerID";
     }
 
     protected override void parse_args () throws Error {
@@ -79,5 +78,13 @@ internal class Rygel.Search:  Rygel.MediaQueryAction {
 
         return results;
     }
+
+    protected override void handle_error (Error error) {
+        warning (_("Failed to search in '%s': %s"),
+                 this.object_id,
+                 error.message);
+
+        base.handle_error (error);
+    }
 }
 



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