[rygel] server: Changed Container's updated() signal.



commit 49c2914398a86aa03d3b2e26dd50e6d6dc09c609
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Tue Sep 11 16:34:57 2012 +0200

    server: Changed Container's updated() signal.
    
    Used to implement a more fine-grained change tracking.

 src/librygel-server/rygel-content-directory.vala   |    6 ++-
 src/librygel-server/rygel-media-container.vala     |   54 +++++++++++++++++---
 src/librygel-server/rygel-media-server-plugin.vala |    5 ++-
 src/librygel-server/rygel-simple-container.vala    |    6 ++-
 .../rygel-media-export-db-container.vala           |    7 +--
 .../rygel-media-export-harvesting-task.vala        |    5 +-
 6 files changed, 66 insertions(+), 17 deletions(-)
---
diff --git a/src/librygel-server/rygel-content-directory.vala b/src/librygel-server/rygel-content-directory.vala
index e68b710..8f12562 100644
--- a/src/librygel-server/rygel-content-directory.vala
+++ b/src/librygel-server/rygel-content-directory.vala
@@ -373,8 +373,12 @@ internal class Rygel.ContentDirectory: Service {
      * @param updated_container the container that just got updated
      */
     private void on_container_updated (MediaContainer root_container,
-                                       MediaContainer updated_container) {
+                                       MediaContainer updated_container,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         this.system_update_id++;
+        updated_container.update_id = this.system_update_id++;
 
         if (this.clear_updated_containers) {
             this.updated_containers.clear ();
diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala
index 47ff14e..8aeee09 100644
--- a/src/librygel-server/rygel-media-container.vala
+++ b/src/librygel-server/rygel-media-container.vala
@@ -27,6 +27,12 @@
 using GUPnP;
 using Gee;
 
+public enum Rygel.ObjectEventType {
+    ADDED = 0,
+    MODIFIED = 1,
+    DELETED = 2
+}
+
 /**
  * This is a container (folder) for media items and child containers.
  *
@@ -54,11 +60,29 @@ public abstract class Rygel.MediaContainer : MediaObject {
 
     /**
      * The container_updated signal is emitted if a child container under the
-     * tree of this container has been updated.
+     * tree of this container has been updated. object is set to
+     * the MediaObject being the source of container update. Note that
+     * it may be even set to container itself.
      *
      * @param container The child container that has been updated.
+     * @param object the object that got changed.
+     * @param event_type describes what actually happened to object.
+     * @param sub_tree_update whether the modification is part of
+     * sub-tree update.
+     */
+    public signal void container_updated (MediaContainer container,
+                                          MediaObject object,
+                                          ObjectEventType event_type,
+                                          bool sub_tree_update);
+
+    /**
+     * sub_tree_updates_finished signal is emitted when all of
+     * sub-tree operations are finished.
+     *
+     * @param sub_tree_root - root of a sub-tree where all operations
+     * were performed.
      */
-    public signal void container_updated (MediaContainer container);
+    public signal void sub_tree_updates_finished (MediaObject sub_tree_root);
 
     public int child_count;
     public uint32 update_id;
@@ -110,6 +134,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
         this.upnp_class = STORAGE_FOLDER;
 
         this.container_updated.connect (on_container_updated);
+        this.sub_tree_updates_finished.connect (on_sub_tree_updates_finished);
     }
 
     public MediaContainer.root (string title,
@@ -152,11 +177,11 @@ public abstract class Rygel.MediaContainer : MediaObject {
      * for this container, if items under it are removed or added, if
      * there are metadata changes to items under it, etc.
      */
-    public void updated () {
-        this.update_id++;
-
+    public void updated (MediaObject object = this,
+                         ObjectEventType event_type = ObjectEventType.MODIFIED,
+                         bool sub_tree_update = false) {
         // Emit the signal that will start the bump-up process for this event.
-        this.container_updated (this);
+        this.container_updated (this, object, event_type, sub_tree_update);
     }
 
     internal override DIDLLiteObject serialize (DIDLLiteWriter writer,
@@ -205,9 +230,22 @@ public abstract class Rygel.MediaContainer : MediaObject {
      * @param updated_container the container that just got updated
      */
     private void on_container_updated (MediaContainer container,
-                                       MediaContainer updated_container) {
+                                       MediaContainer updated_container,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
+        if (this.parent != null) {
+            this.parent.container_updated (updated_container,
+                                           object,
+                                           event_type,
+                                           sub_tree_update);
+        }
+    }
+
+    private void on_sub_tree_updates_finished (MediaContainer container,
+                                               MediaObject sub_tree_root) {
         if (this.parent != null) {
-            this.parent.container_updated (updated_container);
+            this.parent.sub_tree_updates_finished (sub_tree_root);
         }
     }
 }
diff --git a/src/librygel-server/rygel-media-server-plugin.vala b/src/librygel-server/rygel-media-server-plugin.vala
index 23a9bd7..56297f8 100644
--- a/src/librygel-server/rygel-media-server-plugin.vala
+++ b/src/librygel-server/rygel-media-server-plugin.vala
@@ -95,7 +95,10 @@ public abstract class Rygel.MediaServerPlugin : Rygel.Plugin {
     }
 
     private void on_container_updated (MediaContainer root_container,
-                                       MediaContainer updated) {
+                                       MediaContainer updated,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         if (updated != root_container || updated.child_count == 0) {
             return;
         }
diff --git a/src/librygel-server/rygel-simple-container.vala b/src/librygel-server/rygel-simple-container.vala
index 13a10fb..ee5ced5 100644
--- a/src/librygel-server/rygel-simple-container.vala
+++ b/src/librygel-server/rygel-simple-container.vala
@@ -127,6 +127,7 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
      * from the container.
      */
     public void clear () {
+        // TODO: this will have to emit sub-tree events of object being deleted.
         this.children.clear ();
 
         this.child_count = 0;
@@ -257,7 +258,10 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer,
     }
 
     private void on_container_updated (MediaContainer source,
-                                       MediaContainer updated) {
+                                       MediaContainer updated,
+                                       MediaObject object,
+                                       ObjectEventType event_type,
+                                       bool sub_tree_update) {
         if (updated.child_count > 0) {
             if (!(updated in this.empty_children)) {
                 return;
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index f78a236..6785353 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -32,12 +32,11 @@ public class Rygel.MediaExport.DBContainer : MediaContainer,
 
         this.media_db = media_db;
         this.search_classes = new ArrayList<string> ();
-        this.container_updated.connect (on_db_container_updated);
-        this.on_db_container_updated (this, this);
+        this.container_updated.connect ( () => { this.count_children (); });
+        this.count_children;
     }
 
-    private void on_db_container_updated (MediaContainer container,
-                                          MediaContainer container_updated) {
+    private void count_children () {
         try {
             this.child_count = this.media_db.get_child_count (this.id);
         } catch (DatabaseError error) {
diff --git a/src/plugins/media-export/rygel-media-export-harvesting-task.vala b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
index d8d89b3..a0fdb67 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -273,7 +273,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
                                             this.flag);
                 } catch (Error error) {};
             }
-            parent.updated ();
+            parent.updated (parent);
 
             this.completed ();
         }
@@ -352,7 +352,8 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
             try {
                 var cache = MediaCache.get_default ();
                 if (cache.get_child_count (container.id) > 0) {
-                    this.containers.peek_head ().updated ();
+                    var head = this.containers.peek_head ();
+                    head.updated (head);
                 } else {
                     cache.remove_by_id (container.id);
                 }



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