summaryrefslogtreecommitdiffstats
path: root/src/main.vala
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-10-05 22:26:47 +0200
committerSebastian Reichel <sre@ring0.de>2012-10-05 22:26:47 +0200
commit22190faeace11d58b452d0c5dea8b7c613c08705 (patch)
treef884921f6e17cc9ca886c752e58d8f0892e72909 /src/main.vala
parent400a54fad59b0fbecb451ce86fc40655ce84139f (diff)
downloadserial-barcode-scanner-22190faeace11d58b452d0c5dea8b7c613c08705.tar.bz2
play audio on shutdown (GH-13)
Diffstat (limited to 'src/main.vala')
-rw-r--r--src/main.vala32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/main.vala b/src/main.vala
index eccd171..eff3a9d 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -17,6 +17,7 @@ public Device dev;
public Database db;
public AudioPlayer audio;
public CSVMemberFile csvimport;
+public MainLoop loop;
public static int main(string[] args) {
Gst.init(ref args);
@@ -26,9 +27,15 @@ public static int main(string[] args) {
return 1;
}
- dev = new Device(args[1], 9600, 8, 1);
- db = new Database("shop.db");
+ /* handle unix signals */
+ Unix.signal_add(Posix.SIGTERM, handle_signals);
+ Unix.signal_add(Posix.SIGINT, handle_signals);
+
+
+ dev = new Device(args[1], 9600, 8, 1);
+ db = new Database("shop.db");
audio = new AudioPlayer();
+ loop = new MainLoop();
dev.received_barcode.connect((data) => {
if(interpret(data))
@@ -42,11 +49,19 @@ public static int main(string[] args) {
new WebServer();
/* run mainloop */
- new MainLoop().run();
+ loop.run();
+
+ write_to_log("Stopping Shop System");
+ audio.play("system/shutdown.ogg");
- /* call destructors */
- dev = null;
- db = null;
+ /* we need to run the mainloop to play audio */
+ audio.end_of_stream.connect(() => { loop.quit(); });
+ loop.run();
+
+ /* explicitly call destructors */
+ dev = null;
+ db = null;
+ audio = null;
return 0;
}
@@ -117,3 +132,8 @@ public static bool interpret(string data) {
}
}
}
+
+bool handle_signals() {
+ loop.quit();
+ return false;
+}