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 | |
---|
[8623] | 12 | typedef int (*SignalCallback)( void * someData ); |
---|
[7439] | 13 | |
---|
[9423] | 14 | #ifdef __LINUX__ |
---|
[7439] | 15 | #include <signal.h> |
---|
| 16 | |
---|
[7361] | 17 | struct SignalRec |
---|
| 18 | { |
---|
| 19 | int signal; |
---|
[8293] | 20 | sig_t handler; |
---|
[7361] | 21 | }; |
---|
| 22 | |
---|
[8228] | 23 | struct SignalCallbackRec |
---|
| 24 | { |
---|
| 25 | SignalCallback cb; |
---|
| 26 | void * someData; |
---|
| 27 | }; |
---|
[7439] | 28 | |
---|
[8228] | 29 | |
---|
[7361] | 30 | typedef std::list<SignalRec> SignalRecList; |
---|
[8228] | 31 | typedef std::list<SignalCallbackRec> SignalCallbackList; |
---|
[7361] | 32 | |
---|
| 33 | class SignalHandler |
---|
| 34 | { |
---|
| 35 | private: |
---|
| 36 | SignalHandler(); |
---|
| 37 | public: |
---|
[8228] | 38 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } |
---|
[9110] | 39 | ~SignalHandler(){ SignalHandler::singletonRef = NULL; } |
---|
[8623] | 40 | |
---|
[8228] | 41 | void registerCallback( SignalCallback cb, void * someData ); |
---|
[7361] | 42 | |
---|
[9406] | 43 | void doCatch( const std::string & appName, const std::string & fileName ); |
---|
[7361] | 44 | void dontCatch(); |
---|
| 45 | |
---|
| 46 | private: |
---|
| 47 | static void sigHandler( int sig ); |
---|
| 48 | |
---|
| 49 | void catchSignal( int sig ); |
---|
| 50 | SignalRecList sigRecList; |
---|
[8623] | 51 | |
---|
[8228] | 52 | SignalCallbackList callbackList; |
---|
[7361] | 53 | |
---|
| 54 | static SignalHandler * singletonRef; |
---|
| 55 | |
---|
| 56 | std::string appName; |
---|
[9406] | 57 | std::string fileName; |
---|
[7361] | 58 | }; |
---|
| 59 | |
---|
[7439] | 60 | #else /* if defined __WIN32__ */ |
---|
| 61 | class SignalHandler |
---|
| 62 | { |
---|
[7440] | 63 | public: |
---|
[8228] | 64 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; |
---|
[9423] | 65 | void doCatch( const std::string & appName, const std::string & fileName ) {} |
---|
| 66 | void dontCatch() {} |
---|
[8228] | 67 | void registerCallback( SignalCallback cb, void * someData ) {}; |
---|
[8523] | 68 | |
---|
| 69 | private: |
---|
| 70 | static SignalHandler * singletonRef; |
---|
[7439] | 71 | }; |
---|
| 72 | #endif |
---|
[7361] | 73 | |
---|
| 74 | #endif /* _SIGNAL_HANDLER_H */ |
---|
| 75 | |
---|
Note: See
TracBrowser
for help on using the repository browser.