Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/script/src/orxonox/core/SignalHandler.h @ 906

Last change on this file since 906 was 906, checked in by bknecht, 17 years ago

created lua branch w/o Media

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    @brief Definition of the SignalHandler class.
31*/
32
33#ifndef _SignalHandler_H__
34#define _SignalHandler_H__
35
36#include <list>
37#include <string>
38
39#include "CorePrereqs.h"
40
41typedef int (*SignalCallback)( void * someData );
42
43#ifndef __WIN32__
44#include <signal.h>
45
46struct SignalRec
47{
48  int signal;
49  sig_t handler;
50};
51
52struct SignalCallbackRec
53{
54  SignalCallback cb;
55  void * someData;
56};
57
58
59typedef std::list<SignalRec> SignalRecList;
60typedef std::list<SignalCallbackRec> SignalCallbackList;
61
62class SignalHandler
63{
64  private:
65    SignalHandler();
66  public:
67    inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
68    ~SignalHandler(){ SignalHandler::singletonRef = NULL; }
69
70    void registerCallback( SignalCallback cb, void * someData );
71
72    void doCatch( const std::string & appName, const std::string & fileName );
73    void dontCatch();
74
75  private:
76    static void sigHandler( int sig );
77
78    void catchSignal( int sig );
79    SignalRecList sigRecList;
80
81    SignalCallbackList callbackList;
82
83    static SignalHandler * singletonRef;
84
85    std::string appName;
86    std::string fileName;
87};
88
89#else /* #ifndef __WIN32__ */
90
91class _CoreExport SignalHandler
92{
93 public:
94   inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
95   void doCatch( const std::string & appName, const std::string & fileName ) {};
96  void dontCatch() {};
97  void registerCallback( SignalCallback cb, void * someData ) {};
98
99 private:
100    static SignalHandler * singletonRef;
101};
102#endif /* #ifndef __WIN32__ */
103
104#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.