server: Move knowledge of supported profiles
authorJens Georg <jensg@openismus.com>
Fri, 9 Aug 2013 11:17:24 +0000 (13:17 +0200)
committerJens Georg <jensg@openismus.com>
Mon, 19 Aug 2013 09:11:23 +0000 (11:11 +0200)
Query the supported profiles (all, upload) from the MediaServerPlugin,
provide a default implementation that does return everything from the
profiles supported by the MediaEngine.

Note: This is done via properties in this slightly complicated manner to not
break ABI this late in the cycle. Ideally it should be abstract/virtual
properties or abstract/virtual functions.

src/librygel-server/rygel-content-directory.vala
src/librygel-server/rygel-media-server-plugin.vala
src/librygel-server/rygel-object-creator.vala
src/librygel-server/rygel-source-connection-manager.vala

index 48ec050..1812a96 100644 (file)
@@ -774,8 +774,8 @@ internal class Rygel.ContentDirectory: Service {
             return;
         }
 
-        unowned GLib.List<DLNAProfile> profiles = MediaEngine.get_default ().
-                                        get_dlna_profiles ();
+        var plugin = this.root_device.resource_factory as MediaServerPlugin;
+        unowned GLib.List<DLNAProfile> profiles = plugin.upload_profiles;
         var requested_profiles = upload_profiles.split (",");
         var builder = new StringBuilder ();
         foreach (var profile in profiles) {
index 1ee13d2..6e58f43 100644 (file)
@@ -40,6 +40,60 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin {
 
     public MediaContainer root_container { get; construct; }
 
+    private GLib.List<DLNAProfile> _upload_profiles;
+
+    /**
+     * The list of DLNA profiles the MediaServer in this plugin will accept
+     * files as upload.
+     *
+     * Can be a subset of :supported_profiles. If set to %NULL, it will be
+     * reset to :supported_profiles.
+     */
+    public unowned GLib.List<DLNAProfile> upload_profiles {
+        get {
+            if (_upload_profiles == null) {
+                return _supported_profiles;
+            }
+
+            return _upload_profiles;
+        }
+
+        construct set {
+            _upload_profiles = null;
+            foreach (var profile in value) {
+                _upload_profiles.append (profile);
+            }
+        }
+    }
+
+    private GLib.List<DLNAProfile> _supported_profiles;
+
+    /**
+     * The list of DLNA profiles the MediaServer in this plugin will be able
+     * to serve.
+     *
+     * If it does not accept all formats it can serve for uploading,
+     * :upload_profiles needs to be set to the supported subset.
+     *
+     * By default it will be the supported profiles of the #RygelMediaEngine.
+     */
+    public unowned GLib.List<DLNAProfile> supported_profiles {
+        get {
+            if (_supported_profiles == null) {
+                return MediaEngine.get_default ().get_dlna_profiles ();
+            }
+
+            return _supported_profiles;
+        }
+
+        construct set {
+            _supported_profiles = null;
+            foreach (var profile in value) {
+                _supported_profiles.append (profile);
+            }
+        }
+    }
+
     /**
      * Create an instance of the plugin.
      * The plugin's service will have the same title as its root container.
index 58b193c..6e1fe25 100644 (file)
@@ -786,7 +786,8 @@ internal class Rygel.ObjectCreator: GLib.Object, Rygel.StateMachine {
     private bool is_profile_valid (string profile) {
         unowned GLib.List<DLNAProfile> profiles, result;
 
-        profiles = MediaEngine.get_default ().get_dlna_profiles ();
+        var plugin = this.content_dir.root_device.resource_factory as MediaServerPlugin;
+        profiles = plugin.upload_profiles;
         var p = new DLNAProfile (profile, "");
 
         result = profiles.find_custom (p, DLNAProfile.compare_by_name);
index 77031bd..4c23884 100644 (file)
@@ -51,8 +51,8 @@ internal class Rygel.SourceConnectionManager : Rygel.ConnectionManager {
         var server = this.get_http_server ();
         var protocol_infos = server.get_protocol_info ();
 
-        unowned GLib.List<DLNAProfile> profiles = MediaEngine.get_default ().
-                                                              get_dlna_profiles ();
+        var plugin = this.root_device.resource_factory as MediaServerPlugin;
+        unowned GLib.List<DLNAProfile> profiles = plugin.supported_profiles;
 
         var protocol = server.get_protocol ();