[rygel] core,data: Implement ContentDirecotory's DestroyObject
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,data: Implement ContentDirecotory's DestroyObject
- Date: Fri, 29 Oct 2010 12:35:45 +0000 (UTC)
commit 310b1c7fb62e5e95ae994eb6f4a527a0bc10f2b2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Oct 28 14:59:16 2010 +0300
core,data: Implement ContentDirecotory's DestroyObject
data/xml/ContentDirectory.xml.in | 12 +++
src/rygel/Makefile.am | 1 +
src/rygel/rygel-content-directory.vala | 10 +++
src/rygel/rygel-item-destroyer.vala | 115 ++++++++++++++++++++++++++++++++
4 files changed, 138 insertions(+), 0 deletions(-)
---
diff --git a/data/xml/ContentDirectory.xml.in b/data/xml/ContentDirectory.xml.in
index e569c20..ff62780 100644
--- a/data/xml/ContentDirectory.xml.in
+++ b/data/xml/ContentDirectory.xml.in
@@ -345,6 +345,18 @@ feature provided by your editor.
<action>
<Optional/>
+ <name>DestroyObject</name>
+ <argumentList>
+ <argument>
+ <name>ObjectID</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_ObjectID</relatedStateVariable>
+ </argument>
+ </argumentList>
+ </action>
+
+ <action>
+ <Optional/>
<name>ImportResource</name>
<argumentList>
<argument>
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 641ef2d..d66d0ac 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -101,6 +101,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
rygel-xbox-hacks.vala \
rygel-import-resource.vala \
rygel-item-creator.vala \
+ rygel-item-destroyer.vala \
rygel-search-expression.vala \
rygel-relational-expression.vala \
rygel-logical-expression.vala \
diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala
index e812e7c..d5760d6 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -30,6 +30,7 @@ using Gee;
*/
public errordomain Rygel.ContentDirectoryError {
NO_SUCH_OBJECT = 701,
+ RESTRICTED_OBJECT = 711,
BAD_METADATA = 712,
RESTRICTED_PARENT = 713,
CANT_PROCESS = 720,
@@ -89,6 +90,7 @@ internal class Rygel.ContentDirectory: Service {
this.action_invoked["Browse"].connect (this.browse_cb);
this.action_invoked["Search"].connect (this.search_cb);
this.action_invoked["CreateObject"].connect (this.create_object_cb);
+ this.action_invoked["DestroyObject"].connect (this.destroy_object_cb);
this.action_invoked["ImportResource"].connect (this.import_resource_cb);
this.action_invoked["GetTransferProgress"].connect (
this.get_transfer_progress_cb);
@@ -154,6 +156,14 @@ internal class Rygel.ContentDirectory: Service {
creator.run.begin ();
}
+ /* DestroyObject action implementation */
+ private void destroy_object_cb (Service content_dir,
+ owned ServiceAction action) {
+ var destroyer = new ItemDestroyer (this, action);
+
+ destroyer.run.begin ();
+ }
+
/* ImportResource action implementation */
private void import_resource_cb (Service content_dir,
owned ServiceAction action) {
diff --git a/src/rygel/rygel-item-destroyer.vala b/src/rygel/rygel-item-destroyer.vala
new file mode 100644
index 0000000..394007f
--- /dev/null
+++ b/src/rygel/rygel-item-destroyer.vala
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+
+private errordomain Rygel.ItemDestroyerError {
+ PARSE
+}
+
+/**
+ * DestroyObject action implementation.
+ */
+internal class Rygel.ItemDestroyer: GLib.Object, Rygel.StateMachine {
+ private string object_id;
+
+ private ContentDirectory content_dir;
+ private ServiceAction action;
+
+ public Cancellable cancellable { get; set; }
+
+ public ItemDestroyer (ContentDirectory content_dir,
+ owned ServiceAction action) {
+ this.content_dir = content_dir;
+ this.cancellable = content_dir.cancellable;
+ this.action = (owned) action;
+ }
+
+ public async void run () {
+ try {
+ this.action.get ("ObjectID", typeof (string), out this.object_id);
+ if (this.object_id == null) {
+ // Sorry we can't do anything without the ID
+ throw new ContentDirectoryError.NO_SUCH_OBJECT (
+ _("No such object"));
+ }
+
+ yield this.remove_object ();
+
+ this.action.return ();
+
+ debug (_("Successfully destroyed object '%s'"), this.object_id);
+ } catch (Error error) {
+ if (error is ContentDirectoryError) {
+ this.action.return_error (error.code, error.message);
+ } else {
+ this.action.return_error (701, error.message);
+ }
+
+ warning (_("Failed to destroy object '%s': %s"),
+ this.object_id,
+ error.message);
+ }
+
+ this.completed ();
+ }
+
+ public async void remove_object () throws Error {
+ var media_object = yield this.fetch_object ();
+
+ if (media_object is MediaItem &&
+ (media_object as MediaItem).place_holder) {
+ var parent = media_object.parent as WritableContainer;
+
+ yield parent.remove_item (this.object_id, this.cancellable);
+ } else {
+ var writables = yield media_object.get_writables (this.cancellable);
+
+ foreach (var file in writables) {
+ file.delete (this.cancellable);
+ }
+ }
+ }
+
+ private async MediaObject fetch_object () throws Error {
+ var media_object = yield this.content_dir.root_container.find_object (
+ this.object_id,
+ this.cancellable);
+
+ if (media_object == null) {
+ throw new ContentDirectoryError.NO_SUCH_OBJECT (
+ _("No such object"));
+ } else if (media_object is MediaContainer &&
+ !(media_object is WritableContainer)) {
+ throw new ContentDirectoryError.RESTRICTED_OBJECT (
+ _("Removal of object %s not allowed"),
+ media_object.id);
+ } else if (!(media_object.parent is WritableContainer)) {
+ throw new ContentDirectoryError.RESTRICTED_PARENT (
+ _("Object removal from %s not allowed"),
+ media_object.id);
+ }
+
+ return media_object;
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]