blob: d29cdabb4fe04fa7dfecc23eccc56485c6b6a0fb (
plain)
1 ////////////////////////////////////////////////////////////////////////
2 // FILE: signaldispatcher.h
3 // AUTHOR: Johannes Winkelmann, jw@tks6.net
4 // COPYRIGHT: (c) 2002 by Johannes Winkelmann
5 // ---------------------------------------------------------------------
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 ////////////////////////////////////////////////////////////////////////
11
12 #ifndef _SIGNALDISPATCHER_H_
13 #define _SIGNALDISPATCHER_H_
14
15 #include <map>
16
17 /*!
18 signal handler for the SignalDispatcher class. Implement this class to
19 receive signals
20 \brief SignalHandler for SignalDispatcher
21 */
22 class SignalHandler
23 {
24 public:
25 /*! Result of a handlSignal() call */
26 enum HandlerResult {
27 SIGNAL_NOT_HANDLED, /*!< not handled */
28 EXIT, /*!< signal handled, exit now */
29 CONTINUE /*!< signal handled, don't exit */
30 };
31 virtual HandlerResult handleSignal( int signalNumber ) = 0;
32 };
33
34 /*!
35 dispatches signals. Singleton, use the instance() method to access
36 the instance of this class. Register your SignalHandler to handle signals
37
38 \brief Dispatch unix signals
39 */
40 class SignalDispatcher
41 {
42 public:
43 static SignalDispatcher* instance();
44 static void dispatch( int signalNumber );
45
46 void registerHandler( SignalHandler* handler, int signalNumber );
47 void unregisterHandler( int signalNumber );
48
49 protected:
50 SignalDispatcher();
51
52 private:
53 static SignalDispatcher* m_instance;
54 std::map<int, SignalHandler*> m_signalHandlers;
55
56 };
57
58 #endif /* _SIGNALDISPATCHER_H_ */
|