summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2015-08-09 04:18:02 +0200
committerJens Georg <mail@jensge.org>2016-01-03 12:55:25 +0100
commit741d6265e6c1956aa65ac2561059f12fb9f5b002 (patch)
tree6d741d357ed04ed2d1cd6129f66fcd1f9f3309c3
parenta27fa66b1c2f94b85838a1e38fe2dae47a52106d (diff)
downloadrygel-741d6265e6c1956aa65ac2561059f12fb9f5b002.tar.gz
wip: Port DVDParser to Subprocess
Signed-off-by: Jens Georg <mail@jensge.org>
-rw-r--r--src/plugins/media-export/rygel-media-export-dvd-parser.vala89
1 files changed, 28 insertions, 61 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 f9af7186..43b6f1fb 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Jens Georg <mail@jensge.org>.
+ * Copyright (C) 2013,2015 Jens Georg <mail@jensge.org>.
*
* Author: Jens Georg <mail@jensge.org>
*
@@ -58,68 +58,35 @@ internal class Rygel.DVDParser : GLib.Object {
Xml.ParserOption.NOWARNING);
}
- Pid pid;
- int stdout_fd;
-
try {
- Process.spawn_async_with_pipes (null,
- { "/usr/bin/lsdvd",
- "-Ox",
- "-x",
- "-q",
- this.file.get_path (),
- null },
- null,
- SpawnFlags.DO_NOT_REAP_CHILD |
- SpawnFlags.STDERR_TO_DEV_NULL,
- null,
- out pid,
- null,
- out stdout_fd);
- var data = new StringBuilder ();
- var io_channel = new IOChannel.unix_new (stdout_fd);
- var io_watch = io_channel.add_watch (IOCondition.IN |
- IOCondition.PRI,
- () => {
- string line;
-
- try {
- io_channel.read_to_end (out line, null);
- data.append (line);
- } catch (Error error) { }
-
- return true;
- });
-
- uint child_watch = 0;
- child_watch = ChildWatch.add (pid, () => {
- Source.remove (child_watch);
- Source.remove (io_watch);
- Process.close_pid (pid);
-
- get_information.callback ();
- });
-
- yield;
-
- try {
- this.cache_file.replace_contents (data.str.data,
- null,
- false,
- FileCreateFlags.NONE,
- null);
- } catch (Error rc_error) {
- debug ("Failed to cache lsdvd output: %s", rc_error.message);
+ 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);
+
+ 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");
}
-
- return Xml.Parser.read_memory (data.str,
- (int) data.len,
- null,
- null,
- Xml.ParserOption.NOERROR |
- Xml.ParserOption.NOWARNING);
- } catch (SpawnError error) {
- debug ("Failed to run lsdvd: %s", error.message);
+ } catch (Error error) {
+ warning ("Failed to run lsdvd: %s", error.message);
}
return null;