[rygel/wip/create-reference] wip
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/create-reference] wip
- Date: Thu, 28 Feb 2013 12:55:42 +0000 (UTC)
commit e9f541c075f91332c68165b94243ae80a4b5f95f
Author: Jens Georg <jensg openismus com>
Date: Thu Feb 28 13:55:23 2013 +0100
wip
data/xml/ContentDirectory.xml.in | 22 ++++++
src/librygel-server/rygel-object-creator.vala | 3 -
src/librygel-server/rygel-reference-creator.vala | 75 +++++++++++++++++---
.../rygel-media-export-writable-db-container.vala | 4 +
4 files changed, 91 insertions(+), 13 deletions(-)
---
diff --git a/data/xml/ContentDirectory.xml.in b/data/xml/ContentDirectory.xml.in
index 81b82c6..e7db30d 100644
--- a/data/xml/ContentDirectory.xml.in
+++ b/data/xml/ContentDirectory.xml.in
@@ -367,6 +367,28 @@
</action>
<action>
+ <name>CreateReference</name>
+ <argumentList>
+ <argument>
+ <name>ContainerID</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
+ </argument>
+ <argument>
+ <name>ObjectID</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
+ </argument>
+ <argument>
+ <name>NewID</name>
+ <direction>out</direction>
+ <relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
+ </argument>
+ </argumentList>
+ </action>
+
+
+ <action>
<name>ImportResource</name>
<argumentList>
<argument>
diff --git a/src/librygel-server/rygel-object-creator.vala b/src/librygel-server/rygel-object-creator.vala
index 6126604..2eedfe9 100644
--- a/src/librygel-server/rygel-object-creator.vala
+++ b/src/librygel-server/rygel-object-creator.vala
@@ -353,9 +353,6 @@ internal class Rygel.ObjectCreator: GLib.Object, Rygel.StateMachine {
(_("No such object"));
} else if (!(OCMFlags.UPLOAD in media_object.ocm_flags) ||
!(media_object is WritableContainer)) {
- debug ("=> %s %s", (OCMFlags.UPLOAD in
- media_object.ocm_flags).to_string (),
- (media_object is WritableContainer).to_string ());
throw new ContentDirectoryError.RESTRICTED_PARENT
(_("Object creation in %s not allowed"),
media_object.id);
diff --git a/src/librygel-server/rygel-reference-creator.vala
b/src/librygel-server/rygel-reference-creator.vala
index 474334b..4c0e7cb 100644
--- a/src/librygel-server/rygel-reference-creator.vala
+++ b/src/librygel-server/rygel-reference-creator.vala
@@ -23,19 +23,80 @@
using GUPnP;
internal class Rygel.ReferenceCreator : GLib.Object, Rygel.StateMachine {
+ private ContentDirectory content_directory;
private ServiceAction action;
// Props
public Cancellable cancellable { get; set; }
+ public string container_id;
+
+ // Local props
+ public string object_id;
public ReferenceCreator (ContentDirectory content_dir,
owned ServiceAction action) {
+ this.content_directory = content_dir;
this.cancellable = content_dir.cancellable;
this.action = (owned) action;
}
+ public void parse_arguments () throws Error {
+ this.action.get ("ContainerID",
+ typeof (string), out this.container_id,
+ "ObjectID",
+ typeof (string), out this.object_id);
+ if (this.container_id == null) {
+ // FIXME: Add translation
+ throw new ContentDirectoryError.INVALID_ARGS
+ (("'ContainerID' agument missing."));
+ }
+
+ if (this.object_id == null) {
+ // FIXME: Add translation
+ throw new ContentDirectoryError.INVALID_ARGS
+ (("'ObjectID' argument missing."));
+ }
+ }
+
public async void run () {
- var container = yield this.fetch_container ();
+ try {
+ this.parse_arguments ();
+ var container = yield this.fetch_container ();
+ var root_container = this.content_directory.root_container;
+ var object = yield root_container.find_object
+ (this.object_id, this.cancellable);
+ if (object == null) {
+ throw new ContentDirectoryError.NO_SUCH_OBJECT
+ (_("No such object"));
+ }
+
+ object.parent_ref = null;
+ object.parent = container;
+ object.ref_id = object.id;
+ object.id = null;
+
+ if (object is MediaItem) {
+ yield container.add_item (object as MediaItem,
+ this.cancellable);
+ } else {
+ yield container.add_container (object as MediaContainer,
+ this.cancellable);
+ }
+
+ this.action.set ("NewID", typeof (string), object.id);
+ this.action.return ();
+ this.completed ();
+ } catch (Error error) {
+ this.action.return_error (error.code, error.message);
+
+ warning (_("Failed to create object under '%s': %s"),
+ this.container_id,
+ error.message);
+
+ this.completed ();
+
+ return;
+ }
}
/**
@@ -51,21 +112,15 @@ internal class Rygel.ReferenceCreator : GLib.Object, Rygel.StateMachine {
private async WritableContainer fetch_container () throws Error {
MediaObject media_object = null;
- if (this.container_id == MediaContainer.ANY) {
- media_object = yield this.find_any_container ();
- } else {
- media_object = yield this.content_dir.root_container.find_object
- (this.container_id, this.cancellable);
- }
+ var root_container = this.content_directory.root_container;
+ media_object = yield root_container.find_object (this.container_id,
+ this.cancellable);
if (media_object == null || !(media_object is MediaContainer)) {
throw new ContentDirectoryError.NO_SUCH_OBJECT
(_("No such object"));
} else if (!(OCMFlags.UPLOAD in media_object.ocm_flags) ||
!(media_object is WritableContainer)) {
- debug ("=> %s %s", (OCMFlags.UPLOAD in
- media_object.ocm_flags).to_string (),
- (media_object is WritableContainer).to_string ());
throw new ContentDirectoryError.RESTRICTED_PARENT
(_("Object creation in %s not allowed"),
media_object.id);
diff --git a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
index 951df9e..64830be 100644
--- a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
@@ -59,6 +59,10 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
public virtual async void add_item (Rygel.MediaItem item,
Cancellable? cancellable)
throws Error {
+ if (item.id == null && item.ref_id != null) {
+ warning ("=> CreateReference not supported");
+ throw new WriteableContainerError.NOT_IMPLEMENTED ("Not supported");
+ }
item.parent = this;
var file = File.new_for_uri (item.uris[0]);
// TODO: Mark as place-holder. Make this proper some time.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]