[rygel/wip/dvd: 97/103] wip: Port DVDParser to Subprocess
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel/wip/dvd: 97/103] wip: Port DVDParser to Subprocess
- Date: Wed, 16 Sep 2015 12:25:19 +0000 (UTC)
commit 28bdfc18003f5258cf18528ebe7bd5b299a72073
Author: Jens Georg <mail jensge org>
Date: Sun Aug 9 04:18:02 2015 +0200
wip: Port DVDParser to Subprocess
Signed-off-by: Jens Georg <mail jensge org>
.../rygel-media-export-dvd-parser.vala | 89 ++++++-------------
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 f9af718..43b6f1f 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]