aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h
diff options
context:
space:
mode:
authordan miller2007-10-19 05:20:48 +0000
committerdan miller2007-10-19 05:20:48 +0000
commitd48ea5bb797037069d641da41da0f195f0124491 (patch)
tree40ff433d94859d629aac933d5ec73b382f62ba1a /libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h
parentdont ask (diff)
downloadopensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.zip
opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.gz
opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.bz2
opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.xz
one more for the gipper
Diffstat (limited to '')
-rw-r--r--libraries/ode-0.9/tests/CppTestHarness/SignalTranslator.h53
1 files changed, 53 insertions, 0 deletions
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 @@
1#ifndef SIGNAL_TRANSLATOR_H
2#define SIGNAL_TRANSLATOR_H
3
4#include <signal.h>
5#include <setjmp.h>
6
7namespace CppTestHarness
8{
9
10template <int SIGNAL>
11class SignalTranslator {
12public:
13 SignalTranslator()
14 {
15 //setup new signal handler
16 struct sigaction act;
17 act.sa_handler = signalHandler;
18 sigemptyset(&act.sa_mask);
19 act.sa_flags = 0;
20
21 sigaction(SIGNAL, &act, &m_oldAction);
22
23 if (sigsetjmp(getJumpPoint(), 1) != 0)
24 {
25 //if signal thrown we will return here from handler
26 throw "Unhandled system exception";
27 }
28 }
29
30 ~SignalTranslator()
31 {
32 sigaction(SIGNAL, &m_oldAction, 0);
33 }
34
35private:
36 static void signalHandler(int signum)
37 {
38 siglongjmp(getJumpPoint(), signum);
39 }
40
41 static sigjmp_buf& getJumpPoint()
42 {
43 static sigjmp_buf jmpPnt;
44 return jmpPnt;
45 }
46
47 struct sigaction m_oldAction;
48};
49
50} //CppTestHarness
51
52#endif //SIGNAL_TRANSLATOR_H
53