Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/SignalHandler.h @ 745

Last change on this file since 745 was 684, checked in by landauf, 17 years ago
  • added new class: the OutputHandler replaces std::cout in Debug.h and redirects the output not only to the console, but also into orxonox.log (this works, of course, only for output using COUT(level) from Debug.h)
  • commented DebugLevel
File size: 2.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Christoph Renner
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/*!
29 * @file SignalHandler.h
30 */
31
32#ifndef _SignalHandler_H__
33#define _SignalHandler_H__
34
35#include <list>
36#include <string>
37
38#include "CorePrereqs.h"
39
40typedef int (*SignalCallback)( void * someData );
41
42#ifndef __WIN32__
43#include <signal.h>
44
45struct SignalRec
46{
47  int signal;
48  sig_t handler;
49};
50
51struct SignalCallbackRec
52{
53  SignalCallback cb;
54  void * someData;
55};
56
57
58typedef std::list<SignalRec> SignalRecList;
59typedef std::list<SignalCallbackRec> SignalCallbackList;
60
61class SignalHandler
62{
63  private:
64    SignalHandler();
65  public:
66    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
67    ~SignalHandler(){ SignalHandler::singletonRef = NULL; }
68
69    void registerCallback( SignalCallback cb, void * someData );
70
71    void doCatch( const std::string & appName, const std::string & fileName );
72    void dontCatch();
73
74  private:
75    static void sigHandler( int sig );
76
77    void catchSignal( int sig );
78    SignalRecList sigRecList;
79
80    SignalCallbackList callbackList;
81
82    static SignalHandler * singletonRef;
83
84    std::string appName;
85    std::string fileName;
86};
87
88#else /* #ifndef __WIN32__ */
89
90class _CoreExport SignalHandler
91{
92 public:
93   inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
94   void doCatch( const std::string & appName, const std::string & fileName ) {};
95  void dontCatch() {};
96  void registerCallback( SignalCallback cb, void * someData ) {};
97
98 private:
99    static SignalHandler * singletonRef;
100};
101#endif /* #ifndef __WIN32__ */
102
103#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.