Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/util/signal_handler.h @ 9337

Last change on this file since 9337 was 9240, checked in by bensch, 18 years ago

orxonox/trunk: better signal handler.
patched by chrigi

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