Last change
on this file since 9120 was
9110,
checked in by bensch, 18 years ago
|
orxonox/trunk: merged the Presentation back
|
File size:
1.8 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 | enum GdbRunType{ |
---|
| 15 | GDB_RUN_WRITE_TO_FILE = 1, |
---|
| 16 | GDB_RUN_IN_FOREGROUND |
---|
| 17 | }; |
---|
| 18 | |
---|
[8623] | 19 | typedef int (*SignalCallback)( void * someData ); |
---|
[7439] | 20 | |
---|
| 21 | #ifndef __WIN32__ |
---|
| 22 | #include <signal.h> |
---|
| 23 | |
---|
[7361] | 24 | struct SignalRec |
---|
| 25 | { |
---|
| 26 | int signal; |
---|
[8293] | 27 | sig_t handler; |
---|
[7361] | 28 | }; |
---|
| 29 | |
---|
[8228] | 30 | struct SignalCallbackRec |
---|
| 31 | { |
---|
| 32 | SignalCallback cb; |
---|
| 33 | void * someData; |
---|
| 34 | }; |
---|
[7439] | 35 | |
---|
[8228] | 36 | |
---|
[7361] | 37 | typedef std::list<SignalRec> SignalRecList; |
---|
[8228] | 38 | typedef std::list<SignalCallbackRec> SignalCallbackList; |
---|
[7361] | 39 | |
---|
| 40 | class SignalHandler |
---|
| 41 | { |
---|
| 42 | private: |
---|
| 43 | SignalHandler(); |
---|
| 44 | public: |
---|
[8228] | 45 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } |
---|
[9110] | 46 | ~SignalHandler(){ SignalHandler::singletonRef = NULL; } |
---|
[8623] | 47 | |
---|
[8228] | 48 | void registerCallback( SignalCallback cb, void * someData ); |
---|
[7361] | 49 | |
---|
| 50 | void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE ); |
---|
| 51 | void dontCatch(); |
---|
| 52 | |
---|
| 53 | private: |
---|
| 54 | static void sigHandler( int sig ); |
---|
| 55 | |
---|
| 56 | void catchSignal( int sig ); |
---|
| 57 | SignalRecList sigRecList; |
---|
[8623] | 58 | |
---|
[8228] | 59 | SignalCallbackList callbackList; |
---|
[7361] | 60 | |
---|
| 61 | static SignalHandler * singletonRef; |
---|
| 62 | |
---|
| 63 | GdbRunType type; |
---|
| 64 | |
---|
| 65 | std::string appName; |
---|
| 66 | }; |
---|
| 67 | |
---|
[7439] | 68 | #else /* if defined __WIN32__ */ |
---|
| 69 | class SignalHandler |
---|
| 70 | { |
---|
[7440] | 71 | public: |
---|
[8228] | 72 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; |
---|
[7439] | 73 | void doCatch( std::string appName, GdbRunType type = GDB_RUN_WRITE_TO_FILE ) {}; |
---|
| 74 | void dontCatch() {}; |
---|
[8228] | 75 | void registerCallback( SignalCallback cb, void * someData ) {}; |
---|
[8523] | 76 | |
---|
| 77 | private: |
---|
| 78 | static SignalHandler * singletonRef; |
---|
[7439] | 79 | }; |
---|
| 80 | #endif |
---|
[7361] | 81 | |
---|
| 82 | #endif /* _SIGNAL_HANDLER_H */ |
---|
| 83 | |
---|
Note: See
TracBrowser
for help on using the repository browser.