[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Christoph Renner |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[682] | 28 | |
---|
[1505] | 29 | /** |
---|
[2030] | 30 | @file |
---|
[1755] | 31 | @brief Declaration of the SignalHandler class. |
---|
[1505] | 32 | */ |
---|
| 33 | |
---|
[497] | 34 | #ifndef _SignalHandler_H__ |
---|
| 35 | #define _SignalHandler_H__ |
---|
| 36 | |
---|
[2030] | 37 | #include "UtilPrereqs.h" |
---|
[1062] | 38 | |
---|
[497] | 39 | #include <list> |
---|
| 40 | #include <string> |
---|
| 41 | |
---|
| 42 | typedef int (*SignalCallback)( void * someData ); |
---|
| 43 | |
---|
[1607] | 44 | #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 |
---|
[497] | 45 | #include <signal.h> |
---|
| 46 | |
---|
| 47 | struct SignalRec |
---|
| 48 | { |
---|
| 49 | int signal; |
---|
| 50 | sig_t handler; |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | struct SignalCallbackRec |
---|
| 54 | { |
---|
| 55 | SignalCallback cb; |
---|
| 56 | void * someData; |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | typedef std::list<SignalRec> SignalRecList; |
---|
| 61 | typedef std::list<SignalCallbackRec> SignalCallbackList; |
---|
| 62 | |
---|
| 63 | class SignalHandler |
---|
| 64 | { |
---|
| 65 | private: |
---|
| 66 | SignalHandler(); |
---|
| 67 | public: |
---|
| 68 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } |
---|
| 69 | ~SignalHandler(){ SignalHandler::singletonRef = NULL; } |
---|
| 70 | |
---|
| 71 | void registerCallback( SignalCallback cb, void * someData ); |
---|
| 72 | |
---|
[2103] | 73 | void doCatch( const std::string & appName, const std::string & filename ); |
---|
[497] | 74 | void dontCatch(); |
---|
| 75 | |
---|
| 76 | private: |
---|
| 77 | static void sigHandler( int sig ); |
---|
| 78 | |
---|
| 79 | void catchSignal( int sig ); |
---|
| 80 | SignalRecList sigRecList; |
---|
| 81 | |
---|
| 82 | SignalCallbackList callbackList; |
---|
| 83 | |
---|
| 84 | static SignalHandler * singletonRef; |
---|
| 85 | |
---|
| 86 | std::string appName; |
---|
[2103] | 87 | std::string filename; |
---|
[1293] | 88 | |
---|
| 89 | // used to turn on KeyAutoRepeat if OIS crashes |
---|
| 90 | static bool bXAutoKeyRepeatOn_; |
---|
[497] | 91 | }; |
---|
| 92 | |
---|
[1607] | 93 | #else /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 */ |
---|
[682] | 94 | |
---|
[2030] | 95 | class _UtilExport SignalHandler |
---|
[497] | 96 | { |
---|
[1607] | 97 | public: |
---|
| 98 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; |
---|
[2103] | 99 | void doCatch( const std::string & appName, const std::string & filename ) {}; |
---|
[1607] | 100 | void dontCatch() {}; |
---|
| 101 | void registerCallback( SignalCallback cb, void * someData ) {}; |
---|
[497] | 102 | |
---|
[1607] | 103 | private: |
---|
[497] | 104 | static SignalHandler * singletonRef; |
---|
| 105 | }; |
---|
| 106 | |
---|
[1607] | 107 | #endif /* ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 */ |
---|
| 108 | |
---|
[497] | 109 | #endif /* _SignalHandler_H__ */ |
---|