[rygel] server,engine: Return null DataSource on error



commit c9cba5b46e90297f460fc4f78ab3256ae7155150
Author: Jens Georg <jensg openismus com>
Date:   Fri Oct 5 12:33:52 2012 +0200

    server,engine: Return null DataSource on error
    
    Make it possible for a media engine to say "I don't support this kind of uris"

 src/librygel-server/rygel-media-engine.vala        |    2 +-
 .../gstreamer/rygel-gst-data-source.vala           |   11 ++++++++++-
 .../gstreamer/rygel-gst-media-engine.vala          |    8 ++++++--
 .../simple/rygel-simple-media-engine.vala          |    6 +++++-
 tests/rygel-item-creator-test.vala                 |    2 +-
 5 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/src/librygel-server/rygel-media-engine.vala b/src/librygel-server/rygel-media-engine.vala
index 7afc116..46a40ae 100644
--- a/src/librygel-server/rygel-media-engine.vala
+++ b/src/librygel-server/rygel-media-engine.vala
@@ -98,5 +98,5 @@ public abstract class Rygel.MediaEngine : GLib.Object {
      * @param uri to create the data source for.
      * @return A data source representing the uri
      */
-    public abstract DataSource create_data_source (string uri);
+    public abstract DataSource? create_data_source (string uri);
 }
diff --git a/src/media-engines/gstreamer/rygel-gst-data-source.vala b/src/media-engines/gstreamer/rygel-gst-data-source.vala
index 5202d7f..0ee3b78 100644
--- a/src/media-engines/gstreamer/rygel-gst-data-source.vala
+++ b/src/media-engines/gstreamer/rygel-gst-data-source.vala
@@ -22,6 +22,10 @@
 
 using Gst;
 
+internal errordomain Rygel.GstDataSourceError {
+    NOT_COMPATIBLE
+}
+
 internal class Rygel.GstDataSource : Rygel.DataSource, GLib.Object {
     internal dynamic Element src;
     private Pipeline pipeline;
@@ -29,8 +33,13 @@ internal class Rygel.GstDataSource : Rygel.DataSource, GLib.Object {
     private GstSink sink;
     private uint bus_watch_id;
 
-    public GstDataSource (string uri) {
+    public GstDataSource (string uri) throws Error {
         this.src = GstUtils.create_source_for_uri (uri);
+        if (this.src == null) {
+            var msg = _("Could not create GstElement for URI %s");
+
+            throw new GstDataSourceError.NOT_COMPATIBLE (msg, uri);
+        }
     }
 
     ~GstDataSource () {
diff --git a/src/media-engines/gstreamer/rygel-gst-media-engine.vala b/src/media-engines/gstreamer/rygel-gst-media-engine.vala
index 9873af1..5c181da 100644
--- a/src/media-engines/gstreamer/rygel-gst-media-engine.vala
+++ b/src/media-engines/gstreamer/rygel-gst-media-engine.vala
@@ -101,8 +101,12 @@ public class Rygel.GstMediaEngine : Rygel.MediaEngine {
         return this.transcoders;
     }
 
-    public override DataSource create_data_source (string uri) {
-        return new GstDataSource (uri);
+    public override DataSource? create_data_source (string uri) {
+        try {
+            return new GstDataSource (uri);
+        } catch (Error error) {
+            return null;
+        }
     }
 
     public DataSource create_data_source_from_element (Element element) {
diff --git a/src/media-engines/simple/rygel-simple-media-engine.vala b/src/media-engines/simple/rygel-simple-media-engine.vala
index c26faed..00cba01 100644
--- a/src/media-engines/simple/rygel-simple-media-engine.vala
+++ b/src/media-engines/simple/rygel-simple-media-engine.vala
@@ -33,7 +33,11 @@ internal class Rygel.SimpleMediaEngine : MediaEngine {
         return null;
     }
 
-    public override DataSource create_data_source (string uri) {
+    public override DataSource? create_data_source (string uri) {
+        if (!uri.has_prefix ("file://")) {
+            return null;
+        }
+
         return new SimpleDataSource (uri);
     }
 }
diff --git a/tests/rygel-item-creator-test.vala b/tests/rygel-item-creator-test.vala
index b11ac01..cf41b92 100644
--- a/tests/rygel-item-creator-test.vala
+++ b/tests/rygel-item-creator-test.vala
@@ -254,7 +254,7 @@ public class Rygel.TestMediaEngine : Rygel.MediaEngine {
         return null;
     }
 
-    public override DataSource create_data_source (string uri) {
+    public override DataSource? create_data_source (string uri) {
         return null;
     }
 }



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