Fetch files from enumerator, asynchronously
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 4 May 2009 14:14:10 +0000 (17:14 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 6 May 2009 12:46:54 +0000 (15:46 +0300)
This is the second (and hopefully) last step towards async plugin loading.

src/rygel/rygel-plugin-loader.vala

index 4d1640f..4b280ad 100644 (file)
@@ -72,9 +72,29 @@ public class Rygel.PluginLoader : Object {
             return;
         }
 
-        FileInfo info;
+        enumerator.next_files_async (int.MAX,
+                                     Priority.DEFAULT,
+                                     null,
+                                     on_next_files_enumerated);
+    }
+
+    private void on_next_files_enumerated (GLib.Object      source_object,
+                                           GLib.AsyncResult res) {
+        FileEnumerator enumerator = (FileEnumerator) source_object;
+        File dir = (File) enumerator.get_container ();
+
+        List<FileInfo> infos;
+        try {
+            infos = enumerator.next_files_finish (res);
+        } catch (Error error) {
+            critical ("Error listing contents of directory '%s': %s\n",
+                      dir.get_path (),
+                      error.message);
+
+            return;
+        }
 
-        while ((info = enumerator.next_file (null)) != null) {
+        foreach (var info in infos) {
             string file_name = info.get_name ();
             string file_path = Path.build_filename (dir.get_path (), file_name);