[rygel/wip/update-object: 14/15] wip: Add RygelUpdatableObject for storing metadata in persistent storage.



commit 905a93cbae800c3ac84af5102f478dbf8b865992
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Tue Oct 23 12:48:14 2012 +0200

    wip: Add RygelUpdatableObject for storing metadata in persistent storage.

 src/librygel-server/filelist.am                 |    3 +-
 src/librygel-server/rygel-item-updater.vala     |    9 +++--
 src/librygel-server/rygel-media-container.vala  |    4 ++
 src/librygel-server/rygel-media-item.vala       |   29 ++++++++++++-------
 src/librygel-server/rygel-media-object.vala     |    5 ++-
 src/librygel-server/rygel-updatable-object.vala |   35 +++++++++++++++++++++++
 6 files changed, 68 insertions(+), 17 deletions(-)
---
diff --git a/src/librygel-server/filelist.am b/src/librygel-server/filelist.am
index 62046d6..dbd3e10 100644
--- a/src/librygel-server/filelist.am
+++ b/src/librygel-server/filelist.am
@@ -25,7 +25,8 @@ LIBRYGEL_SERVER_VAPI_SOURCE_FILES = \
 	rygel-media-server.vala \
 	rygel-media-engine.vala \
 	rygel-http-seek.vala \
-	rygel-data-source.vala
+	rygel-data-source.vala \
+	rygel-updatable-object.vala
 
 LIBRYGEL_SERVER_NONVAPI_SOURCE_FILES = \
 	rygel-browse.vala \
diff --git a/src/librygel-server/rygel-item-updater.vala b/src/librygel-server/rygel-item-updater.vala
index f635162..be81257 100644
--- a/src/librygel-server/rygel-item-updater.vala
+++ b/src/librygel-server/rygel-item-updater.vala
@@ -113,11 +113,12 @@ internal class Rygel.ItemUpdater: GLib.Object, Rygel.StateMachine {
         var media_object = yield this.fetch_object ();
         var current_list = csv_split (this.current_tag_value);
         var new_list = csv_split (this.new_tag_value);
+        var result = yield media_object.apply_fragments
+                                        (current_list,
+                                         new_list,
+                                         this.content_dir.http_server);
 
-
-        switch (media_object.apply_fragments (current_list,
-                                              new_list,
-                                              this.content_dir.http_server)) {
+        switch (result) {
         case DIDLLiteFragmentResult.OK:
             break;
 
diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala
index 47ff14e..4ee9233 100644
--- a/src/librygel-server/rygel-media-container.vala
+++ b/src/librygel-server/rygel-media-container.vala
@@ -93,6 +93,10 @@ public abstract class Rygel.MediaContainer : MediaObject {
                 flags |= OCMFlags.DESTROYABLE;
             }
 
+            if (this is UpdatableObject) {
+                flags |= OCMFlags.CHANGE_METADATA;
+            }
+
             return flags;
         }
     }
diff --git a/src/librygel-server/rygel-media-item.vala b/src/librygel-server/rygel-media-item.vala
index 29d9d08..2d98c75 100644
--- a/src/librygel-server/rygel-media-item.vala
+++ b/src/librygel-server/rygel-media-item.vala
@@ -63,22 +63,29 @@ public abstract class Rygel.MediaItem : MediaObject {
 
     internal override OCMFlags ocm_flags {
         get {
+            var flags = OCMFlags.NONE;
+
             if (this.place_holder) {
                 // Place-holder items are always destroyable.
-                return OCMFlags.DESTROYABLE;
-            }
+                flags |= OCMFlags.DESTROYABLE;
+            } else {
+                var config = MetaConfig.get_default ();
+                var allow_deletion = true;
 
-            var config = MetaConfig.get_default ();
-            var allow_deletion = true;
-            try {
-                allow_deletion = config.get_allow_deletion ();
-            } catch (Error error) {}
+                try {
+                    allow_deletion = config.get_allow_deletion ();
+                } catch (Error error) {}
 
-            if (allow_deletion) {
-                return OCMFlags.DESTROYABLE;
-            } else {
-                return OCMFlags.NONE;
+                if (allow_deletion) {
+                    flags |= OCMFlags.DESTROYABLE;
+                }
+            }
+
+            if (this is UpdatableObject) {
+                flags |= OCMFlags.CHANGE_METADATA;
             }
+
+            return flags;
         }
     }
 
diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala
index 1e577b5..1f3e75a 100644
--- a/src/librygel-server/rygel-media-object.vala
+++ b/src/librygel-server/rygel-media-object.vala
@@ -161,7 +161,7 @@ public abstract class Rygel.MediaObject : GLib.Object {
         this.title = didl_object.title;
     }
 
-    internal DIDLLiteFragmentResult apply_fragments
+    internal async DIDLLiteFragmentResult apply_fragments
                                         (LinkedList<string> current_fragments,
                                          LinkedList<string> new_fragments,
                                          HTTPServer         http_server) {
@@ -177,6 +177,9 @@ public abstract class Rygel.MediaObject : GLib.Object {
 
             if (result == DIDLLiteFragmentResult.OK) {
                 this.apply_didl_lite (didl_object);
+                if (this is UpdatableObject) {
+                    yield (this as UpdatableObject).commit ();
+                }
             }
 
         } catch (Error e) {}
diff --git a/src/librygel-server/rygel-updatable-object.vala b/src/librygel-server/rygel-updatable-object.vala
new file mode 100644
index 0000000..a4ad9b4
--- /dev/null
+++ b/src/librygel-server/rygel-updatable-object.vala
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Krzesimir Nowak <krnowak openismus 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.
+ */
+
+/**
+ * This interface should be implemented by 'updatable' objects - ones
+ * that allow modifying their own metadata in some persistent storage.
+ */
+public interface Rygel.UpdatableObject : MediaObject {
+    /**
+     * Commit changes in MediaObject to persistent storage.
+     *
+     * This is called after properties are changed. This happens when
+     * e.g. UpdateObject was called on this object.
+     */
+    public abstract async void commit () throws Error;
+}



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