[rygel/wip/track-changes: 123/128] core, plugins: Add server capabilities



commit eb483d1014c4a94ec3b82dcd6824b6007171926e
Author: Jens Georg <jensg openismus com>
Date:   Thu Oct 11 12:25:30 2012 +0200

    core,plugins: Add server capabilities
    
    Fixes:
        https://bugzilla.gnome.org/show_bug.cgi?id=676024

 src/librygel-core/rygel-description-file.vala      |   53 ++++++++++++++++++++
 src/librygel-core/rygel-plugin.vala                |   28 ++++++++++
 src/librygel-core/rygel-root-device-factory.vala   |   26 +---------
 .../media-export/rygel-media-export-plugin.vala    |    1 +
 src/plugins/tracker/rygel-tracker-plugin.vala      |    2 +
 5 files changed, 85 insertions(+), 25 deletions(-)
---
diff --git a/src/librygel-core/rygel-description-file.vala b/src/librygel-core/rygel-description-file.vala
index 025f133..c6b1465 100644
--- a/src/librygel-core/rygel-description-file.vala
+++ b/src/librygel-core/rygel-description-file.vala
@@ -120,6 +120,59 @@ public class Rygel.DescriptionFile : Object {
     }
 
     /**
+     * Set the DLNA caps of this root device and while taking the
+     * capabilities of the plugin into account.
+     *
+     * @param capabilities RygelPluginCapabilities flags
+     */
+    public void set_dlna_caps (PluginCapabilities capabilities) {
+        var flags = new string[0];
+        var content = "";
+
+        if ((PluginCapabilities.UPLOAD & capabilities) != 0) {
+            // This means "Supports upload to AnyContainer_DLNA.ORG", but we
+            // also use it as "supports upload". AnyContainer upload is
+            // handled by Rygel transparently.
+            var allow_upload = true;
+            var allow_delete = false;
+
+            try {
+                var config = MetaConfig.get_default ();
+                allow_upload = config.get_allow_upload ();
+                allow_delete = config.get_allow_deletion ();
+            } catch (GLib.Error error) { }
+
+            if (allow_upload) {
+                if (PluginCapabilities.IMAGE_UPLOAD in capabilities) {
+                    flags += "image-upload";
+                }
+
+                if (PluginCapabilities.VIDEO_UPLOAD in capabilities) {
+                    flags += "av-upload";
+                }
+
+                if (PluginCapabilities.AUDIO_UPLOAD in capabilities) {
+                    flags += "audio-upload";
+                }
+            }
+
+            if (allow_delete) {
+                flags += "create-item-with-OCM-destroy-item";
+            }
+
+        }
+
+        // Set the flags we found; otherwise remove whatever is in the
+        // template.
+        if (flags.length > 0) {
+            content = string.joinv (",", flags);
+        }
+
+        this.set_device_element ("X_DLNACAP", content);
+    }
+
+
+    /**
      * Change the type of a service.
      *
      * Usually used to modify the service version, e.g. old_type =
diff --git a/src/librygel-core/rygel-plugin.vala b/src/librygel-core/rygel-plugin.vala
index f170a79..7e7dd64 100644
--- a/src/librygel-core/rygel-plugin.vala
+++ b/src/librygel-core/rygel-plugin.vala
@@ -25,6 +25,32 @@ using Gee;
 using GUPnP;
 
 /**
+ * RygelPluginCapabilities is a set of flags that represent various
+ * capabilities of plugins.
+ */
+[Flags]
+public enum Rygel.PluginCapabilities {
+    /* Server caps */
+
+    /// Server plugin supports upload of images
+    IMAGE_UPLOAD,
+
+    /// Server plugin supports upload of video files
+    VIDEO_UPLOAD,
+
+    /// Server plugin supports upload of audio files
+    AUDIO_UPLOAD,
+
+    /// Server supports upload of all kind of items
+    UPLOAD = IMAGE_UPLOAD | VIDEO_UPLOAD | AUDIO_UPLOAD,
+
+    /// Server supports tracking changes
+    TRACK_CHANGES
+
+    /* Renderer caps */
+}
+
+/**
  * Represents a Rygel plugin. Plugins are supposed to provide an object of this
  * class or a subclass.
  */
@@ -55,6 +81,8 @@ public class Rygel.Plugin : GUPnP.ResourceFactory {
     private static const int ICON_SMALL_WIDTH = 48;
     private static const int ICON_SMALL_HEIGHT = 48;
 
+    public PluginCapabilities capabilities { get; protected set; }
+
     public string name;
     public string title;
     public string description;
diff --git a/src/librygel-core/rygel-root-device-factory.vala b/src/librygel-core/rygel-root-device-factory.vala
index a9a304f..f05679d 100644
--- a/src/librygel-core/rygel-root-device-factory.vala
+++ b/src/librygel-core/rygel-root-device-factory.vala
@@ -82,6 +82,7 @@ public class Rygel.RootDeviceFactory {
         this.prepare_desc_for_plugin (doc, plugin);
 
         var file = new DescriptionFile.from_xml_document (doc);
+        file.set_dlna_caps (plugin.capabilities);
         file.save (desc_path);
 
         return doc;
@@ -104,7 +105,6 @@ public class Rygel.RootDeviceFactory {
         this.set_friendly_name_and_udn (device_element,
                                         plugin.name,
                                         plugin.title);
-        this.set_dlnacap (device_element);
 
         if (plugin.description != null) {
             this.set_description (device_element, plugin.description);
@@ -164,30 +164,6 @@ public class Rygel.RootDeviceFactory {
         }
     }
 
-    private void set_dlnacap (Xml.Node *device_element) {
-        var element = XMLUtils.get_element (device_element,
-                                            "X_DLNACAP",
-                                            null);
-
-        var content = "";
-        var allow_upload = true;
-        var allow_delete = false;
-
-        try {
-            allow_upload = config.get_allow_upload ();
-            allow_delete = config.get_allow_deletion ();
-        } catch (Error error) { }
-
-        if (allow_upload) {
-            content += "av-upload,image-upload,audio-upload";
-        }
-
-        if (allow_delete) {
-            content += ",create-item-with-OCM-destroy-item";
-        }
-        element->set_content (content);
-    }
-
     private void set_description (Xml.Node *device_element,
                                   string    description) {
         Xml.Node *element = XMLUtils.get_element (device_element,
diff --git a/src/plugins/media-export/rygel-media-export-plugin.vala b/src/plugins/media-export/rygel-media-export-plugin.vala
index fe5d359..a87fe50 100644
--- a/src/plugins/media-export/rygel-media-export-plugin.vala
+++ b/src/plugins/media-export/rygel-media-export-plugin.vala
@@ -106,5 +106,6 @@ public class Rygel.MediaExport.Plugin : Rygel.MediaServerPlugin {
 
     public Plugin () throws Error {
         base (RootContainer.get_instance (), NAME);
+        this.capabilities |= PluginCapabilities.UPLOAD;
     }
 }
diff --git a/src/plugins/tracker/rygel-tracker-plugin.vala b/src/plugins/tracker/rygel-tracker-plugin.vala
index 765a5d2..db880b0 100644
--- a/src/plugins/tracker/rygel-tracker-plugin.vala
+++ b/src/plugins/tracker/rygel-tracker-plugin.vala
@@ -35,6 +35,8 @@ public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin {
         }
 
         base (root, Plugin.NAME);
+
+        this.capabilities |= PluginCapabilities.UPLOAD;
     }
 }
 



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