[rygel/wip/track-changes: 12/13] core, plugins: Add server capabilities
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/track-changes: 12/13] core, plugins: Add server capabilities
- Date: Fri, 19 Oct 2012 17:26:51 +0000 (UTC)
commit 7c43f7b0866636d8b4f0afcfd0e40ebf721f5356
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 | 59 +++++++++++++++++++-
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, 88 insertions(+), 28 deletions(-)
---
diff --git a/src/librygel-core/rygel-description-file.vala b/src/librygel-core/rygel-description-file.vala
index 025f133..2d59d83 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 =
@@ -184,8 +237,8 @@ public class Rygel.DescriptionFile : Object {
"root",
"device",
element);
- assert (xml_element != null);
-
- xml_element->set_content (new_value);
+ if (element != null) {
+ xml_element->set_content (new_value);
+ }
}
}
diff --git a/src/librygel-core/rygel-plugin.vala b/src/librygel-core/rygel-plugin.vala
index d8259cc..95925f3 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 */
+}
+
+/**
* This represents a Rygel plugin.
*
* Plugin libraries should provide an object of this
@@ -61,6 +87,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 bd8ac37..5206240 100644
--- a/src/librygel-core/rygel-root-device-factory.vala
+++ b/src/librygel-core/rygel-root-device-factory.vala
@@ -85,6 +85,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;
@@ -107,7 +108,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);
@@ -167,30 +167,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]