[rygel] server: Add automatic change tracking



commit 2afb6fdf4261777ab3fbdcadb8215c1866a9922f
Author: Jens Georg <jensg openismus com>
Date:   Mon Oct 29 15:03:01 2012 +0100

    server: Add automatic change tracking

 src/librygel-server/filelist.am                    |    1 +
 src/librygel-server/rygel-content-directory.vala   |   13 +++-
 src/librygel-server/rygel-media-container.vala     |    2 +
 src/librygel-server/rygel-media-object.vala        |    1 +
 src/librygel-server/rygel-trackable-container.vala |   70 ++++++++++++++++++++
 5 files changed, 83 insertions(+), 4 deletions(-)
---
diff --git a/src/librygel-server/filelist.am b/src/librygel-server/filelist.am
index 39b85cd..a59bd45 100644
--- a/src/librygel-server/filelist.am
+++ b/src/librygel-server/filelist.am
@@ -18,6 +18,7 @@ LIBRYGEL_SERVER_VAPI_SOURCE_FILES = \
 	rygel-media-server-plugin.vala \
 	rygel-search-expression.vala \
 	rygel-searchable-container.vala \
+	rygel-trackable-container.vala \
 	rygel-transcode-manager.vala \
 	rygel-transcoder.vala \
 	rygel-visual-item.vala \
diff --git a/src/librygel-server/rygel-content-directory.vala b/src/librygel-server/rygel-content-directory.vala
index bfa3f7c..df4db64 100644
--- a/src/librygel-server/rygel-content-directory.vala
+++ b/src/librygel-server/rygel-content-directory.vala
@@ -398,9 +398,16 @@ internal class Rygel.ContentDirectory: Service {
                                        MediaObject object,
                                        ObjectEventType event_type,
                                        bool sub_tree_update) {
-        this.add_last_change_entry (object, event_type, sub_tree_update);
         this.system_update_id++;
-        updated_container.update_id = this.system_update_id++;
+        this.add_last_change_entry (object, event_type, sub_tree_update);
+
+        if (event_type == ObjectEventType.ADDED ||
+            event_type == ObjectEventType.DELETED) {
+            updated_container.update_id = this.system_update_id;
+            object.object_update_id = this.system_update_id;
+        } else {
+            object.object_update_id = this.system_update_id;
+        }
 
         if (this.clear_updated_containers) {
             this.updated_containers.clear ();
@@ -417,7 +424,6 @@ internal class Rygel.ContentDirectory: Service {
     private void on_sub_tree_updates_finished (MediaContainer root_container,
                                                MediaObject sub_tree_root)
     {
-        this.system_update_id++;
 
         var entry = new LastChangeStDone (sub_tree_root.id,
                                           this.system_update_id);
@@ -522,7 +528,6 @@ internal class Rygel.ContentDirectory: Service {
     {
         LastChangeEntry entry;
 
-        this.system_update_id++;
         switch (event_type) {
         case ObjectEventType.ADDED:
             entry = new LastChangeObjAdd (object.id,
diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala
index 8aeee09..5d8ee2b 100644
--- a/src/librygel-server/rygel-media-container.vala
+++ b/src/librygel-server/rygel-media-container.vala
@@ -200,6 +200,8 @@ public abstract class Rygel.MediaContainer : MediaObject {
         didl_container.upnp_class = this.upnp_class;
         didl_container.searchable = this is SearchableContainer;
         didl_container.storage_used = this.storage_used;
+        didl_container.container_update_id = this.update_id;
+        didl_container.update_id = this.object_update_id;
 
         if (this.parent == null && (this is SearchableContainer)) {
             (this as SearchableContainer).serialize_search_parameters
diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala
index d8d9ca9..2421c56 100644
--- a/src/librygel-server/rygel-media-object.vala
+++ b/src/librygel-server/rygel-media-object.vala
@@ -42,6 +42,7 @@ public abstract class Rygel.MediaObject : GLib.Object {
     public string ref_id;
     public string upnp_class;
     public uint64 modified;
+    public uint object_update_id;
     public Gee.ArrayList<string> uris;
 
     // You can keep both a unowned and owned ref to parent of this MediaObject.
diff --git a/src/librygel-server/rygel-trackable-container.vala b/src/librygel-server/rygel-trackable-container.vala
new file mode 100644
index 0000000..952d7a4
--- /dev/null
+++ b/src/librygel-server/rygel-trackable-container.vala
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Jens Georg <jensg openismus come
+ *
+ * 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.
+ */
+
+public interface Rygel.TrackableContainer : Rygel.MediaContainer {
+    public async void clear () {
+        try {
+            var children = yield this.get_children (0, 0, "", null);
+            if (children == null) {
+                return;
+            }
+
+            foreach (var child in children) {
+                yield this.remove_child_tracked (child);
+            }
+        } catch (Error error) {
+        }
+    }
+
+    public abstract async void add_child (MediaObject object);
+
+    public async void add_child_tracked (MediaObject object) {
+        yield this.add_child (object);
+
+        this.updated (object, ObjectEventType.ADDED);
+        this.updated ();
+        if (object is TrackableContainer) {
+            var trackable = object as TrackableContainer;
+
+            // Release the events that might have accumulated
+            trackable.thaw_events ();
+        }
+    }
+
+    public abstract async void remove_child (MediaObject object);
+
+    public async void remove_child_tracked (MediaObject object) {
+        // We need to descend into this to get the proper events
+        if (object is TrackableContainer) {
+            var trackable = object as TrackableContainer;
+            yield trackable.clear ();
+        }
+
+        yield this.remove_child (object);
+
+        this.updated (object, ObjectEventType.DELETED);
+        this.total_deleted_child_count++;
+        this.updated ();
+    }
+
+    private void thaw_events () {
+        // Forward events.
+    }
+}



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