core: Wait for new item to appear
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 19 Nov 2010 17:24:15 +0000 (19:24 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 22 Nov 2010 12:43:06 +0000 (14:43 +0200)
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

index 2abb400..80ea6f5 100644 (file)
@@ -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);
+    }
 }