Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ode/ode-0.9/tests/CppTestHarness/SignalTranslator.h @ 216

Last change on this file since 216 was 216, checked in by mathiask, 16 years ago

[Physik] add ode-0.9

File size: 866 bytes
Line 
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
Note: See TracBrowser for help on using the repository browser.