From d48ea5bb797037069d641da41da0f195f0124491 Mon Sep 17 00:00:00 2001 From: dan miller Date: Fri, 19 Oct 2007 05:20:48 +0000 Subject: one more for the gipper --- .../tests/CppTestHarness/SignalTranslator.h | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h (limited to 'libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h') diff --git a/libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h b/libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h new file mode 100644 index 0000000..39fc225 --- /dev/null +++ b/libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h @@ -0,0 +1,53 @@ +#ifndef SIGNAL_TRANSLATOR_H +#define SIGNAL_TRANSLATOR_H + +#include +#include + +namespace CppTestHarness +{ + +template +class SignalTranslator { +public: + SignalTranslator() + { + //setup new signal handler + struct sigaction act; + act.sa_handler = signalHandler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + + sigaction(SIGNAL, &act, &m_oldAction); + + if (sigsetjmp(getJumpPoint(), 1) != 0) + { + //if signal thrown we will return here from handler + throw "Unhandled system exception"; + } + } + + ~SignalTranslator() + { + sigaction(SIGNAL, &m_oldAction, 0); + } + +private: + static void signalHandler(int signum) + { + siglongjmp(getJumpPoint(), signum); + } + + static sigjmp_buf& getJumpPoint() + { + static sigjmp_buf jmpPnt; + return jmpPnt; + } + + struct sigaction m_oldAction; +}; + +} //CppTestHarness + +#endif //SIGNAL_TRANSLATOR_H + -- cgit v1.1