added signal handlers to cec-client and cec-config. closes #45
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 20 Sep 2012 15:20:55 +0000 (17:20 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 20 Sep 2012 15:26:03 +0000 (17:26 +0200)
src/cec-config/cec-config.cpp
src/testclient/main.cpp

index a3d2b77f5666a592ba6b21d72a5307becf68e913..1f58ccbd4234c77b1c1cd3e330f70760104d9ac8 100644 (file)
@@ -39,6 +39,7 @@
 #include <fstream>
 #include <string>
 #include <sstream>
+#include <signal.h>
 #include "../lib/platform/threads/mutex.h"
 #include "../lib/platform/util/timeutils.h"
 #include "../lib/implementations/CECCommandHandler.h"
@@ -318,8 +319,24 @@ bool PowerOnTV(uint64_t iTimeout = 60000)
   return currentTvPower == CEC_POWER_STATUS_ON;
 }
 
+void sighandler(int iSignal)
+{
+  PrintToStdOut("signal caught: %d - exiting", iSignal);
+
+  g_parser->Close();
+  UnloadLibCec(g_parser);
+
+  exit(1);
+}
+
 int main (int UNUSED(argc), char *UNUSED(argv[]))
 {
+  if (signal(SIGINT, sighandler) == SIG_ERR)
+  {
+    PrintToStdOut("can't register sighandler");
+    return -1;
+  }
+
   g_callbacks.Clear();
   g_config.Clear();
   PrintToStdOut("=== USB-CEC Adapter Configuration ===\n");
index 707d7d686ac0f36ccb2a219fc0597fe532bc82c1..f1687baa3b94cb989bd68c63461787a3181b7544 100644 (file)
@@ -39,6 +39,7 @@
 #include <fstream>
 #include <string>
 #include <sstream>
+#include <signal.h>
 #include "../lib/platform/os.h"
 #include "../lib/implementations/CECCommandHandler.h"
 #include "../lib/platform/util/StdString.h"
@@ -1129,8 +1130,20 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
   return bReturn;
 }
 
+void sighandler(int iSignal)
+{
+  PrintToStdOut("signal caught: %d - exiting", iSignal);
+  g_bExit = true;
+}
+
 int main (int argc, char *argv[])
 {
+  if (signal(SIGINT, sighandler) == SIG_ERR)
+  {
+    PrintToStdOut("can't register sighandler");
+    return -1;
+  }
+
   g_config.Clear();
   g_callbacks.Clear();
   snprintf(g_config.strDeviceName, 13, "CECTester");