added an interupt handler has SIGINT was being ignored... ?
authorPatrik Gornicz <Gornicz.P@gmail.com>
Sat, 19 Jul 2008 23:10:42 +0000 (19:10 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Sat, 19 Jul 2008 23:10:42 +0000 (19:10 -0400)
src/Makefile
src/handleSignal.cpp [new file with mode: 0644]
src/handleSignal.h [new file with mode: 0644]
src/main.cpp

index 4ae7179..32cfc49 100644 (file)
@@ -20,6 +20,7 @@ SRCS += main.cpp
 SRCS += mathw.cpp
 SRCS += ticks.cpp
 SRCS += Vector2.cpp
+SRCS += handleSignal.cpp
 
 SRCS += Entities/Ball.cpp
 SRCS += Entities/Entity.cpp
diff --git a/src/handleSignal.cpp b/src/handleSignal.cpp
new file mode 100644 (file)
index 0000000..d449b8a
--- /dev/null
@@ -0,0 +1,42 @@
+#include "handleSignal.h"
+
+#include <iostream>
+#include <signal.h>
+
+/// ***** Private Method Headers *****
+void sighandler( int sig );
+
+
+/// ***** Public Methods *****
+
+void installSignal()
+{
+    // register signal handler
+    struct sigaction sa;
+    sigemptyset( &sa.sa_mask );
+    sa.sa_handler = sighandler;
+    sa.sa_flags = 0;
+
+    if ( sigaction( SIGINT, &sa, NULL ) < 0 )
+    {
+        std::cerr << "could not install SIGINT handler" << std::endl;
+    }
+}
+
+/// ***** Private Methods *****
+
+// signal handler function
+void sighandler( int sig )
+{
+    switch(sig)
+    {
+        case SIGINT:
+            std::cerr << "SIGINT caught" << std::endl;
+            break;
+        default:
+            std::cout << "UNKNOWN caught";
+    }
+
+    // normally an abort is better ... but this is just SIGINT
+    exit(sig);
+}
diff --git a/src/handleSignal.h b/src/handleSignal.h
new file mode 100644 (file)
index 0000000..4fd66ad
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef HANDLESIGNAL_H
+#define HANDLESIGNAL_H
+
+/// ***** Public Methods *****
+
+void installSignal();
+
+#endif // HANDLESIGNAL_H
index 98565a6..7313306 100644 (file)
@@ -2,10 +2,8 @@
 #include <GL/glu.h>
 #include <SDL/SDL.h>
 
-#include <vector>
-using std::vector;
-
 #include "debug.h"
+#include "handleSignal.h"
 
 #include "game.h"
 #include "ticks.h"
@@ -14,9 +12,12 @@ using std::vector;
 #include "input/inputManager.h"
 
 
+
 /// ***** Private Method Headers *****
 void init();
 
+void sighandler( int sig );
+
 void run();
 void cleanUp();
 
@@ -66,6 +67,8 @@ long int last_Second;
 /// ***** Private Methods *****
 void init()
 {
+    installSignal();
+
     graphicsInit();
 
     gameInit();