summaryrefslogtreecommitdiffstats
path: root/src
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
parent400a54fad59b0fbecb451ce86fc40655ce84139f (diff)
downloadserial-barcode-scanner-22190faeace11d58b452d0c5dea8b7c613c08705.tar.bz2
play audio on shutdown (GH-13)
Diffstat (limited to 'src')
-rw-r--r--src/audio.vala14
-rw-r--r--src/main.vala32
-rw-r--r--src/web.vala2
3 files changed, 41 insertions, 7 deletions
diff --git a/src/audio.vala b/src/audio.vala
index 8e36c70..e30f3b1 100644
--- a/src/audio.vala
+++ b/src/audio.vala
@@ -16,11 +16,25 @@
public class AudioPlayer {
private dynamic Gst.Element p;
+ public signal void end_of_stream();
+
+ private bool bus_callback(Gst.Bus bus, Gst.Message message) {
+ switch (message.type) {
+ case Gst.MessageType.EOS:
+ end_of_stream();
+ break;
+ }
+
+ return true;
+ }
+
public AudioPlayer() {
p = Gst.ElementFactory.make("playbin", "play");
+ p.get_bus().add_watch(bus_callback);
}
public void play(string file) {
+ p.set_state(Gst.State.NULL);
p.uri = "file://"+Environment.get_current_dir()+"/sounds/"+file;
p.set_state(Gst.State.PLAYING);
}
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;
+}
diff --git a/src/web.vala b/src/web.vala
index 2e2e13f..9a77369 100644
--- a/src/web.vala
+++ b/src/web.vala
@@ -728,6 +728,6 @@ public class WebServer {
srv.add_handler("/users", handler_users);
srv.add_handler("/users/import", handler_user_import);
- srv.run();
+ srv.run_async();
}
}