[rygel/wip/dvd: 45/56] WIP



commit 9ca9fda4e10d9c515fc8cf4643cfc4aeb30ff9bf
Author: Jens Georg <mail jensge org>
Date:   Sun Aug 9 09:12:11 2015 +0200

    WIP

 .../rygel-media-export-dvd-parser.vala             |   62 ++++++++-----------
 1 files changed, 26 insertions(+), 36 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-dvd-parser.vala 
b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
index 43b6f1f..522c9cd 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -20,6 +20,10 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+internal errordomain DVDParserError {
+    GENERAL;
+}
+
 internal class Rygel.DVDParser : GLib.Object {
     /// URI to the image / toplevel directory
     public File file { public get; construct; }
@@ -43,53 +47,39 @@ internal class Rygel.DVDParser : GLib.Object {
         this.cache_file = File.new_for_path (cache_path);
     }
 
-    public async void run () {
+    public async void run () throws Error {
         var doc = yield this.get_information ();
         if (doc != null) {
             doc->children;
         }
     }
 
-    public async Xml.Doc* get_information () {
-        if (this.cache_file.query_exists ()) {
-            return Xml.Parser.read_file (this.cache_file.get_path (),
-                                         null,
-                                         Xml.ParserOption.NOERROR |
-                                         Xml.ParserOption.NOWARNING);
-        }
+    public async Xml.Doc* get_information () throws Error {
+        if (!this.cache_file.query_exists ()) {
+            var launcher = new SubprocessLauncher (SubprocessFlags.STDERR_SILENCE);
+            launcher.set_stdout_file_path (this.cache_file.get_path ());
+            string[] args = {
+                "/usr/bin/lsdvd",
+                "-Ox",
+                "-x",
+                "-q",
+                this.file.get_path (),
+                null
+            };
 
-        try {
-            string output = null;
-            var process = new Subprocess (SubprocessFlags.STDERR_SILENCE,
-                                          "/usr/bin/lsdvd",
-                                          "-Ox",
-                                          "-x",
-                                          "-q",
-                                          this.file.get_path (),
-                                          null);
-            yield process.communicate_utf8_async (null, null, out output, null);
-            if (process.get_if_exited () && process.get_exit_status () == 0) {
-                yield this.cache_file.replace_contents_async (output.data,
-                                                              null,
-                                                              false,
-                                                              FileCreateFlags.NONE,
-                                                              null,
-                                                              null);
+            var process = launcher.spawnv (args);
+            yield process.wait_async ();
 
-                return Xml.Parser.read_memory (output,
-                                               output.length,
-                                               null,
-                                               null,
-                                               Xml.ParserOption.NOERROR |
-                                               Xml.ParserOption.NOWARNING);
-            } else {
-                warning ("lsdvd did die or file is not a DVD");
+            if (!(process.get_if_exited () &&
+                process.get_exit_status () == 0)) {
+                throw new DVDParserError.GENERAL ("lsdvd did die or file is not a DVD");
             }
-        } catch (Error error) {
-            warning ("Failed to run lsdvd: %s", error.message);
         }
 
-        return null;
+        return Xml.Parser.read_file (this.cache_file.get_path (),
+                                     null,
+                                     Xml.ParserOption.NOERROR |
+                                     Xml.ParserOption.NOWARNING);
     }
 
     private string get_id (File file) {


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