[682] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[682] | 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 | */ |
---|
| 28 | |
---|
[871] | 29 | /** |
---|
| 30 | @file SignalHandler.h |
---|
| 31 | @brief Definition of the SignalHandler class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[497] | 34 | #ifndef _SignalHandler_H__ |
---|
| 35 | #define _SignalHandler_H__ |
---|
| 36 | |
---|
[1062] | 37 | #include "CorePrereqs.h" |
---|
| 38 | |
---|
[497] | 39 | #include <list> |
---|
| 40 | #include <string> |
---|
| 41 | |
---|
| 42 | typedef int (*SignalCallback)( void * someData ); |
---|
| 43 | |
---|
| 44 | #ifndef __WIN32__ |
---|
| 45 | #include <signal.h> |
---|
[1238] | 46 | #include <X11/Xlib.h> |
---|
[497] | 47 | |
---|
| 48 | struct SignalRec |
---|
| 49 | { |
---|
| 50 | int signal; |
---|
| 51 | sig_t handler; |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | struct SignalCallbackRec |
---|
| 55 | { |
---|
| 56 | SignalCallback cb; |
---|
| 57 | void * someData; |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | typedef std::list<SignalRec> SignalRecList; |
---|
| 62 | typedef std::list<SignalCallbackRec> SignalCallbackList; |
---|
| 63 | |
---|
| 64 | class SignalHandler |
---|
| 65 | { |
---|
| 66 | private: |
---|
| 67 | SignalHandler(); |
---|
| 68 | public: |
---|
| 69 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } |
---|
| 70 | ~SignalHandler(){ SignalHandler::singletonRef = NULL; } |
---|
| 71 | |
---|
| 72 | void registerCallback( SignalCallback cb, void * someData ); |
---|
| 73 | |
---|
| 74 | void doCatch( const std::string & appName, const std::string & fileName ); |
---|
| 75 | void dontCatch(); |
---|
| 76 | |
---|
| 77 | private: |
---|
| 78 | static void sigHandler( int sig ); |
---|
| 79 | |
---|
| 80 | void catchSignal( int sig ); |
---|
| 81 | SignalRecList sigRecList; |
---|
| 82 | |
---|
| 83 | SignalCallbackList callbackList; |
---|
| 84 | |
---|
| 85 | static SignalHandler * singletonRef; |
---|
| 86 | |
---|
| 87 | std::string appName; |
---|
| 88 | std::string fileName; |
---|
[1238] | 89 | |
---|
| 90 | // X Display, used to turn on KeyAutoRepeat if OIS crashes |
---|
| 91 | Display *display_; |
---|
| 92 | bool bXAutoKeyRepeatOn_; |
---|
[497] | 93 | }; |
---|
| 94 | |
---|
[684] | 95 | #else /* #ifndef __WIN32__ */ |
---|
[682] | 96 | |
---|
| 97 | class _CoreExport SignalHandler |
---|
[497] | 98 | { |
---|
| 99 | public: |
---|
| 100 | inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; |
---|
| 101 | void doCatch( const std::string & appName, const std::string & fileName ) {}; |
---|
| 102 | void dontCatch() {}; |
---|
| 103 | void registerCallback( SignalCallback cb, void * someData ) {}; |
---|
| 104 | |
---|
| 105 | private: |
---|
| 106 | static SignalHandler * singletonRef; |
---|
| 107 | }; |
---|
[684] | 108 | #endif /* #ifndef __WIN32__ */ |
---|
[497] | 109 | |
---|
| 110 | #endif /* _SignalHandler_H__ */ |
---|