Use Exceptions rather than returning null.
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Fri, 29 Aug 2008 21:08:13 +0000 (21:08 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Fri, 29 Aug 2008 21:08:13 +0000 (21:08 +0000)
svn path=/trunk/; revision=248

ChangeLog
src/media-providers/tracker/gupnp-media-tracker.vala
src/media-server/gupnp-content-directory.vala
src/media-server/gupnp-media-manager.vala
src/media-server/gupnp-media-provider.vala

index 3718cb4..2f1db31 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2008-08-17  Zeeshan Ali Khattak  <zeenix@gmail.com>
 
+       * src/media-providers/tracker/gupnp-media-tracker.vala:
+       * src/media-server/gupnp-content-directory.vala:
+       * src/media-server/gupnp-media-manager.vala:
+       * src/media-server/gupnp-media-provider.vala:
+
+       Use Exceptions rather than returning null.
+
+2008-08-17  Zeeshan Ali Khattak  <zeenix@gmail.com>
+
        * src/media-server/gupnp-media-server.vala:
 
        Use real name of the user rather than username in FriendlyName.
index 9ca7824..b51bbe7 100644 (file)
@@ -118,15 +118,15 @@ public class GUPnP.MediaTracker : MediaProvider {
         this.context = context;
     }
 
-    public override string? browse (string   container_id,
-                                    string   filter,
-                                    uint     starting_index,
-                                    uint     requested_count,
-                                    string   sort_criteria,
-                                    out uint number_returned,
-                                    out uint total_matches,
-                                    out uint update_id) {
-        string didl;
+    public override string browse (string   container_id,
+                                   string   filter,
+                                   uint     starting_index,
+                                   uint     requested_count,
+                                   string   sort_criteria,
+                                   out uint number_returned,
+                                   out uint total_matches,
+                                   out uint update_id) throws GLib.Error {
+        string didl = null;
 
         /* Start DIDL-Lite fragment */
         this.didl_writer.start_didl_lite (null, null, true);
@@ -162,20 +162,23 @@ public class GUPnP.MediaTracker : MediaProvider {
             didl = this.didl_writer.get_string ();
 
             update_id = uint32.MAX;
-        } else
-            didl = null;
+        }
 
         /* Reset the parser state */
         this.didl_writer.reset ();
 
+        if (didl == null) {
+            throw new MediaProviderError.NO_SUCH_OBJECT ("No such object");
+        }
+
         return didl;
     }
 
     public override string get_metadata (string  object_id,
                                          string  filter,
                                          string  sort_criteria,
-                                         out uint update_id) {
-        string didl;
+                                         out uint update_id) throws GLib.Error {
+        string didl = null;
         bool found;
 
         /* Start DIDL-Lite fragment */
@@ -213,12 +216,15 @@ public class GUPnP.MediaTracker : MediaProvider {
 
             /* Retrieve generated string */
             didl = this.didl_writer.get_string ();
-        } else
-            didl = null;
+        }
 
         /* Reset the parser state */
         this.didl_writer.reset ();
 
+        if (didl == null) {
+            throw new MediaProviderError.NO_SUCH_OBJECT ("No such object");
+        }
+
         update_id = uint32.MAX;
 
         return didl;
index 0f78c1a..fa7427a 100644 (file)
@@ -105,26 +105,26 @@ public class GUPnP.ContentDirectory: Service {
             }
         }
 
-        if (browse_metadata) {
-            didl = this.media_manager.get_metadata (object_id,
-                                                    filter,
-                                                    sort_criteria,
-                                                    out update_id);
-
-            num_returned = 1;
-            total_matches = 1;
-        } else {
-            didl = this.media_manager.browse (object_id,
-                                              filter,
-                                              starting_index,
-                                              requested_count,
-                                              sort_criteria,
-                                              out num_returned,
-                                              out total_matches,
-                                              out update_id);
-        }
-
-        if (didl == null) {
+        try {
+            if (browse_metadata) {
+                didl = this.media_manager.get_metadata (object_id,
+                                                        filter,
+                                                        sort_criteria,
+                                                        out update_id);
+
+                num_returned = 1;
+                total_matches = 1;
+            } else {
+                didl = this.media_manager.browse (object_id,
+                                                  filter,
+                                                  starting_index,
+                                                  requested_count,
+                                                  sort_criteria,
+                                                  out num_returned,
+                                                  out total_matches,
+                                                  out update_id);
+            }
+        } catch (Error error) {
             action.return_error (701, "No such object");
 
             return;
index f091a68..6598ad5 100644 (file)
@@ -64,14 +64,14 @@ public class GUPnP.MediaManager : MediaProvider {
         this.context = context;
     }
 
-    public override string? browse (string   container_id,
-                                    string   filter,
-                                    uint     starting_index,
-                                    uint     requested_count,
-                                    string   sort_criteria,
-                                    out uint number_returned,
-                                    out uint total_matches,
-                                    out uint update_id) {
+    public override string browse (string   container_id,
+                                   string   filter,
+                                   uint     starting_index,
+                                   uint     requested_count,
+                                   string   sort_criteria,
+                                   out uint number_returned,
+                                   out uint total_matches,
+                                   out uint update_id) throws Error {
         string didl;
 
         string root_id = this.get_root_id_from_id (container_id);
@@ -96,7 +96,7 @@ public class GUPnP.MediaManager : MediaProvider {
                     update_id = this.system_update_id;
                 }
             } else {
-                didl = null;
+                throw new MediaProviderError.NO_SUCH_OBJECT ("No such object");
             }
         }
 
@@ -106,7 +106,7 @@ public class GUPnP.MediaManager : MediaProvider {
     public override string get_metadata (string  object_id,
                                          string  filter,
                                          string  sort_criteria,
-                                         out uint update_id) {
+                                         out uint update_id) throws Error {
         string didl;
 
         string root_id = this.get_root_id_from_id (object_id);
@@ -124,7 +124,7 @@ public class GUPnP.MediaManager : MediaProvider {
                     update_id = this.system_update_id;
                 }
             } else {
-                didl = null;
+                throw new MediaProviderError.NO_SUCH_OBJECT ("No such object");
             }
         }
 
index 34252b7..605c5f9 100644 (file)
  * version 2 of the License, or (at your option) any later version.
  */
 
+public errordomain GUPnP.MediaProviderError {
+    NO_SUCH_OBJECT
+}
+
 public abstract class GUPnP.MediaProvider : GLib.Object {
     /* Properties */
     public string# root_id { get; construct; }
@@ -29,19 +33,19 @@ public abstract class GUPnP.MediaProvider : GLib.Object {
     public string# title { get; private construct; }
     public GUPnP.Context context { get; construct; }
 
-    public abstract string? browse (string   container_id,
+    public abstract string browse (string   container_id,
                                     string   filter,
                                     uint     starting_index,
                                     uint     requested_count,
                                     string   sort_criteria,
                                     out uint number_returned,
                                     out uint total_matches,
-                                    out uint update_id);
+                                    out uint update_id) throws Error;
 
     public abstract string get_metadata (string  object_id,
                                          string  filter,
                                          string  sort_criteria,
-                                         out uint update_id);
+                                         out uint update_id) throws Error;
 
     public abstract uint get_root_children_count ();
 }