Last change
on this file since 9247 was
9240,
checked in by bensch, 18 years ago
|
orxonox/trunk: better signal handler.
patched by chrigi
|
File size:
1.6 KB
|
Rev | Line | |
---|
[7361] | 1 | /*! |
---|
| 2 | * @file signalhandler.h |
---|
| 3 | * Defines game rules for this game |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _SIGNAL_HANDLER_H |
---|
| 7 | #define _SIGNAL_HANDLER_H |
---|
| 8 | |
---|
| 9 | #include <list> |
---|
| 10 | #include <string> |
---|
| 11 | |
---|
[8293] | 12 | |
---|
[7361] | 13 | #define GDB_BT_FILE "orxonox.backtrace" |
---|
[7439] | 14 | |
---|
[8623] | 15 | typedef int (*SignalCallback)( void * someData ); |
---|
[7439] | 16 | |
---|
| 17 | #ifndef __WIN32__ |
---|
| 18 | #include <signal.h> |
---|
| 19 | |
---|
[7361] | 20 | struct SignalRec |
---|
| 21 | { |
---|
| 22 | int signal; |
---|
[8293] | 23 | sig_t handler; |
---|
[7361] | 24 | }; |
---|
| 25 | |
---|
[8228] | 26 | struct SignalCallbackRec |
---|
| 27 | { |
---|
| 28 | SignalCallback cb; |
---|
| 29 | void * someData; |
---|
| 30 | }; |
---|
[7439] | 31 | |
---|
[8228] | 32 | |
---|
[7361] | 33 | typedef std::list<SignalRec> SignalRecList; |
---|
[8228] | 34 | typedef std::list<SignalCallbackRec> SignalCallbackList; |
---|
[7361] | 35 | |
---|
| 36 | class SignalHandler |
---|
| 37 | { |
---|
| 38 | private: |
---|
| 39 | SignalHandler(); |
---|
| 40 | public: |
---|
[8228] | 41 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } |
---|
[9110] | 42 | ~SignalHandler(){ SignalHandler::singletonRef = NULL; } |
---|
[8623] | 43 | |
---|
[8228] | 44 | void registerCallback( SignalCallback cb, void * someData ); |
---|
[7361] | 45 | |
---|
[9240] | 46 | void doCatch( std::string appName ); |
---|
[7361] | 47 | void dontCatch(); |
---|
| 48 | |
---|
| 49 | private: |
---|
| 50 | static void sigHandler( int sig ); |
---|
| 51 | |
---|
| 52 | void catchSignal( int sig ); |
---|
| 53 | SignalRecList sigRecList; |
---|
[8623] | 54 | |
---|
[8228] | 55 | SignalCallbackList callbackList; |
---|
[7361] | 56 | |
---|
| 57 | static SignalHandler * singletonRef; |
---|
| 58 | |
---|
| 59 | std::string appName; |
---|
| 60 | }; |
---|
| 61 | |
---|
[7439] | 62 | #else /* if defined __WIN32__ */ |
---|
| 63 | class SignalHandler |
---|
| 64 | { |
---|
[7440] | 65 | public: |
---|
[8228] | 66 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; |
---|
[9240] | 67 | void doCatch( std::string appName ) {}; |
---|
[7439] | 68 | void dontCatch() {}; |
---|
[8228] | 69 | void registerCallback( SignalCallback cb, void * someData ) {}; |
---|
[8523] | 70 | |
---|
| 71 | private: |
---|
| 72 | static SignalHandler * singletonRef; |
---|
[7439] | 73 | }; |
---|
| 74 | #endif |
---|
[7361] | 75 | |
---|
| 76 | #endif /* _SIGNAL_HANDLER_H */ |
---|
| 77 | |
---|
Note: See
TracBrowser
for help on using the repository browser.