[rygel] core: Wait for new item to appear



commit 4a2a815389ed286e90c8947c7fea9ee545c105e8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Nov 19 19:24:15 2010 +0200

    core: Wait for new item to appear
    
    After adding a new item in a container, wair for it to actually appear
    under the container in the hierarchy. This is needed to satisfy DLNA CTT
    testcase 7.3.26.4,5.

 src/rygel/rygel-item-creator.vala |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 2abb400..80ea6f5 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -116,6 +116,9 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
             this.item.id = this.item.uris[0];
 
             yield container.add_item (this.item, this.cancellable);
+
+            yield this.wait_for_item (container);
+
             this.item.serialize (didl_writer, this.content_dir.http_server);
 
             // Conclude the successful action
@@ -281,5 +284,36 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
 
         return file.get_uri ();
     }
+
+    private async void wait_for_item (WritableContainer container) {
+        debug ("Waiting for new item to appear under container '%s'..",
+               container.id);
+        var not_added = true;
+
+        while (not_added) {
+            var id = container.container_updated.connect ((container) => {
+                this.wait_for_item.callback ();
+            });
+
+            yield;
+
+            container.disconnect (id);
+
+            try {
+                var item = yield container.find_object (this.item.id,
+                                                        this.cancellable);
+                if (item != null) {
+                    not_added = false;
+                }
+            } catch (Error error) {
+                warning ("Error from container '%s' on trying to find newly " +
+                         "added child item '%s' in it",
+                         container.id,
+                         this.item.id);
+            }
+        }
+        debug ("Finished waiting for new item to appear under container '%s'",
+               container.id);
+    }
 }
 



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