From 7cbd45053add8c0ee042a69a51f7c8e4dc40bc06 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sat, 19 Jul 2008 19:10:42 -0400 Subject: [PATCH] added an interupt handler has SIGINT was being ignored... ? --- src/Makefile | 1 + src/handleSignal.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/handleSignal.h | 8 ++++++++ src/main.cpp | 9 ++++++--- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/handleSignal.cpp create mode 100644 src/handleSignal.h diff --git a/src/Makefile b/src/Makefile index 4ae7179..32cfc49 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 index 0000000..d449b8a --- /dev/null +++ b/src/handleSignal.cpp @@ -0,0 +1,42 @@ +#include "handleSignal.h" + +#include +#include + +/// ***** 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 index 0000000..4fd66ad --- /dev/null +++ b/src/handleSignal.h @@ -0,0 +1,8 @@ +#ifndef HANDLESIGNAL_H +#define HANDLESIGNAL_H + +/// ***** Public Methods ***** + +void installSignal(); + +#endif // HANDLESIGNAL_H diff --git a/src/main.cpp b/src/main.cpp index 98565a6..7313306 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,10 +2,8 @@ #include #include -#include -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(); -- 2.10.2