[rygel] core: Implement ImportResource action of CDS
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Implement ImportResource action of CDS
- Date: Fri, 19 Feb 2010 10:55:49 +0000 (UTC)
commit 325c6c8502d516e97ebfd4741700e31945119573
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Feb 18 15:34:43 2010 +0200
core: Implement ImportResource action of CDS
data/xml/ContentDirectory.xml | 72 +++++++++---------
src/rygel/Makefile.am | 1 +
src/rygel/rygel-content-directory.vala | 9 ++
src/rygel/rygel-import-resource.vala | 133 ++++++++++++++++++++++++++++++++
4 files changed, 179 insertions(+), 36 deletions(-)
---
diff --git a/data/xml/ContentDirectory.xml b/data/xml/ContentDirectory.xml
index a129d78..ff2a722 100644
--- a/data/xml/ContentDirectory.xml
+++ b/data/xml/ContentDirectory.xml
@@ -104,6 +104,20 @@ feature provided by your editor.
<dataType>string</dataType>
</stateVariable>
+ <stateVariable>
+ <Optional/>
+ <name>A_ARG_TYPE_URI</name>
+ <sendEventsAttribute>no</sendEventsAttribute>
+ <dataType>uri</dataType>
+ </stateVariable>
+
+ <stateVariable>
+ <Optional/>
+ <name>A_ARG_TYPE_TransferID</name>
+ <sendEventsAttribute>no</sendEventsAttribute>
+ <dataType>ui4</dataType>
+ </stateVariable>
+
<!-- Optional state variables that are not implemented yet
<stateVariable>
<Optional/>
@@ -121,13 +135,6 @@ feature provided by your editor.
<stateVariable>
<Optional/>
- <name>A_ARG_TYPE_TransferID</name>
- <sendEventsAttribute>no</sendEventsAttribute>
- <dataType>ui4</dataType>
- </stateVariable>
-
- <stateVariable>
- <Optional/>
<name>A_ARG_TYPE_TransferStatus</name>
<sendEventsAttribute>no</sendEventsAttribute>
<dataType>string</dataType>
@@ -159,13 +166,6 @@ feature provided by your editor.
<sendEventsAttribute>no</sendEventsAttribute>
<dataType>string</dataType>
</stateVariable>
-
- <stateVariable>
- <Optional/>
- <name>A_ARG_TYPE_URI</name>
- <sendEventsAttribute>no</sendEventsAttribute>
- <dataType>uri</dataType>
- </stateVariable>
-->
</serviceStateTable>
@@ -355,6 +355,28 @@ feature provided by your editor.
</argumentList>
</action>
+ <action>
+ <Optional/>
+ <name>ImportResource</name>
+ <argumentList>
+ <argument>
+ <name>SourceURI</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable>
+ </argument>
+ <argument>
+ <name>DestinationURI</name>
+ <direction>in</direction>
+ <relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable>
+ </argument>
+ <argument>
+ <name>TransferID</name>
+ <direction>out</direction>
+ <relatedStateVariable>A_ARG_TYPE_TransferID</relatedStateVariable>
+ </argument>
+ </argumentList>
+ </action>
+
<!-- Optional actions that are not implemented yet
<action>
<Optional/>
@@ -426,28 +448,6 @@ feature provided by your editor.
<action>
<Optional/>
- <name>ImportResource</name>
- <argumentList>
- <argument>
- <name>SourceURI</name>
- <direction>in</direction>
- <relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable>
- </argument>
- <argument>
- <name>DestinationURI</name>
- <direction>in</direction>
- <relatedStateVariable>A_ARG_TYPE_URI</relatedStateVariable>
- </argument>
- <argument>
- <name>TransferID</name>
- <direction>out</direction>
- <relatedStateVariable>A_ARG_TYPE_TransferID</relatedStateVariable>
- </argument>
- </argumentList>
- </action>
-
- <action>
- <Optional/>
<name>ExportResource</name>
<argumentList>
<argument>
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 361d1f9..37e9c84 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -77,6 +77,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
rygel-thumbnailer.vala \
rygel-browse.vala \
rygel-search.vala \
+ rygel-import-resource.vala \
rygel-item-creator.vala \
rygel-search-expression.vala \
rygel-relational-expression.vala \
diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala
index 8615d35..8718c8d 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -99,6 +99,7 @@ public class Rygel.ContentDirectory: Service {
this.action_invoked["Browse"] += this.browse_cb;
this.action_invoked["Search"] += this.search_cb;
this.action_invoked["CreateObject"] += this.create_object_cb;
+ this.action_invoked["ImportResource"] += this.import_resource_cb;
/* Connect SystemUpdateID related signals */
this.action_invoked["GetSystemUpdateID"] +=
@@ -155,6 +156,14 @@ public class Rygel.ContentDirectory: Service {
creator.run.begin ();
}
+ /* ImportResource action implementation */
+ private virtual void import_resource_cb (ContentDirectory content_dir,
+ owned ServiceAction action) {
+ var import = new ImportResource (this, action);
+
+ import.run.begin ();
+ }
+
/* GetSystemUpdateID action implementation */
private void get_system_update_id_cb (ContentDirectory content_dir,
owned ServiceAction action) {
diff --git a/src/rygel/rygel-import-resource.vala b/src/rygel/rygel-import-resource.vala
new file mode 100644
index 0000000..445fd22
--- /dev/null
+++ b/src/rygel/rygel-import-resource.vala
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2008-2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * <zeeshan ali nokia com>
+ *
+ * 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;
+
+/**
+ * Responsible for handling ImportResource action.
+ */
+internal class Rygel.ImportResource : GLib.Object, Rygel.StateMachine {
+ private static uint32 last_transfer_id = 0;
+
+ // In arguments
+ public string source_uri;
+ public string destination_uri;
+
+ // Out arguments
+ public uint32 transfer_id;
+
+ public bool complete;
+
+ public Cancellable cancellable { get; set; }
+
+ private HTTPServer http_server;
+ private MediaContainer root_container;
+ private ServiceAction action;
+ private int64 bytes_copied;
+ private int64 bytes_total;
+
+ public ImportResource (ContentDirectory content_dir,
+ owned ServiceAction action) {
+ this.root_container = content_dir.root_container;
+ this.http_server = content_dir.http_server;
+ this.cancellable = content_dir.cancellable;
+ this.action = (owned) action;
+
+ last_transfer_id++;
+ this.transfer_id = last_transfer_id;
+
+ this.bytes_copied = 0;
+ this.bytes_total = 0;
+ }
+
+ public async void run () {
+ // Start by parsing the 'in' arguments
+ this.action.get ("SourceURI",
+ typeof (string),
+ out this.source_uri,
+ "DestinationURI",
+ typeof (string),
+ out this.destination_uri);
+
+ // Set action return arguments
+ this.action.set ("TransferID", typeof (uint32), this.transfer_id);
+
+ string destination_uri;
+ try {
+ destination_uri = yield this.get_original_uri ();
+ } catch (Error error) {
+ warning ("Failed to get original URI for '%s': %s",
+ this.destination_uri,
+ error.message);
+
+ this.action.return_error (719, error.message);
+
+ return;
+ }
+
+ // We can already return the action now
+ this.action.return ();
+
+ try {
+ var destination_file = File.new_for_uri (destination_uri);
+ var source_file = File.new_for_uri (source_uri);
+
+ yield source_file.copy_async (destination_file,
+ FileCopyFlags.OVERWRITE,
+ Priority.LOW,
+ this.cancellable,
+ this.copy_progress_cb);
+ } catch (Error err) {
+ warning ("%s", err.message);
+ }
+
+ this.complete = true;
+
+ debug ("Import of '%s' to '%s' completed",
+ source_uri,
+ destination_uri);
+ this.completed ();
+ }
+
+ private async string get_original_uri () throws Error {
+ var uri = new HTTPItemURI.from_string (this.destination_uri,
+ this.http_server.path_root);
+ var media_object = yield this.root_container.find_object (uri.item_id,
+ null);
+
+ if (media_object == null ||
+ !(media_object is MediaItem) ||
+ media_object.uris.size < 1) {
+ return this.destination_uri;
+ } else {
+ return media_object.uris[0];
+ }
+ }
+
+ private void copy_progress_cb (int64 current_num_bytes,
+ int64 total_num_bytes) {
+ this.bytes_copied = current_num_bytes;
+ this.bytes_total = total_num_bytes;
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]