main: Add signal handler for SIGINT
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>
Wed, 2 Jan 2013 17:37:49 +0000 (11:37 -0600)
committerUwe Hermann <uwe@hermann-uwe.de>
Wed, 20 Feb 2013 09:36:46 +0000 (10:36 +0100)
Add a SIGINT handler as requested here:
http://www.airwebreathe.org.uk/projects/index.php?title=PulseView#Make_PulseView_respond_properly_to_SIGINT

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
main.cpp

index f4506787364fa11ea01286cf2e569ffed5587c15..a7ab89fbf7422ada41d7050ac57715ce33f7f05d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -20,6 +20,7 @@
 
 extern "C" {
 #include <sigrokdecode.h> /* First, so we avoid a _POSIX_C_SOURCE warning. */
+#include <signal.h>
 #include <stdint.h>
 #include <libsigrok/libsigrok.h>
 }
@@ -45,11 +46,26 @@ void usage()
                "\n", PV_BIN_NAME, PV_DESCRIPTION);
 }
 
+/*
+ * SIGINT handler (likely recieved Ctrl-C from terminal)
+ */
+void sigint(int param)
+{
+       (void) param;
+       
+       qDebug("pv: Recieved SIGINT");
+       
+       /* TODO: Handle SIGINT */
+}
+
 int main(int argc, char *argv[])
 {
        int ret = 0;
        struct sr_context *sr_ctx = NULL;
 
+       // Register a SIGINT handler
+       signal (SIGINT, sigint);
+
        QApplication a(argc, argv);
 
        // Set some application metadata