Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI/src/SignalHandler.h @ 2209

Last change on this file since 2209 was 464, checked in by landauf, 17 years ago

added signal handler to AI branch

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