aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/SignalHandler.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/SignalHandler.cc')
-rw-r--r--src/FbTk/SignalHandler.cc60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/FbTk/SignalHandler.cc b/src/FbTk/SignalHandler.cc
index ddb3766..adbcbc0 100644
--- a/src/FbTk/SignalHandler.cc
+++ b/src/FbTk/SignalHandler.cc
@@ -19,7 +19,7 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: SignalHandler.cc,v 1.2 2002/11/27 21:47:46 fluxgen Exp $ 22// $Id: SignalHandler.cc,v 1.3 2002/12/01 13:42:14 rathnor Exp $
23 23
24#include "SignalHandler.hh" 24#include "SignalHandler.hh"
25 25
@@ -28,52 +28,52 @@ namespace FbTk {
28SignalEventHandler *SignalHandler::s_signal_handler[NSIG]; 28SignalEventHandler *SignalHandler::s_signal_handler[NSIG];
29 29
30SignalHandler::SignalHandler() { 30SignalHandler::SignalHandler() {
31 // clear signal list 31 // clear signal list
32 for (int i=0; i < NSIG; ++i) 32 for (int i=0; i < NSIG; ++i)
33 s_signal_handler[i] = 0; 33 s_signal_handler[i] = 0;
34} 34}
35 35
36SignalHandler *SignalHandler::instance() { 36SignalHandler *SignalHandler::instance() {
37 static SignalHandler singleton; 37 static SignalHandler singleton;
38 return &singleton; 38 return &singleton;
39} 39}
40 40
41bool SignalHandler::registerHandler(int signum, SignalEventHandler *eh, 41bool SignalHandler::registerHandler(int signum, SignalEventHandler *eh,
42 SignalEventHandler **oldhandler_ret) { 42 SignalEventHandler **oldhandler_ret) {
43 // must be less than NSIG 43 // must be less than NSIG
44 if (signum >= NSIG) 44 if (signum >= NSIG)
45 return false; 45 return false;
46 46
47 // get old signal handler for this signum 47 // get old signal handler for this signum
48 if (oldhandler_ret != 0) 48 if (oldhandler_ret != 0)
49 *oldhandler_ret = s_signal_handler[signum]; 49 *oldhandler_ret = s_signal_handler[signum];
50 50
51 struct sigaction sa; 51 struct sigaction sa;
52 // set callback 52 // set callback
53 sa.sa_handler = SignalHandler::handleSignal; 53 sa.sa_handler = SignalHandler::handleSignal;
54 sigemptyset (&sa.sa_mask); 54 sigemptyset (&sa.sa_mask);
55 sa.sa_flags = 0; 55 sa.sa_flags = 0;
56 56
57 if (sigaction(signum, &sa, 0) == -1) 57 if (sigaction(signum, &sa, 0) == -1)
58 return false; 58 return false;
59 59
60 s_signal_handler[signum] = eh; 60 s_signal_handler[signum] = eh;
61 61
62 return true; 62 return true;
63} 63}
64 64
65void SignalHandler::removeHandler(int signum) { 65void SignalHandler::removeHandler(int signum) {
66 if (signum < NSIG) 66 if (signum < NSIG)
67 s_signal_handler[signum] = 0; // clear handler pointer 67 s_signal_handler[signum] = 0; // clear handler pointer
68} 68}
69 69
70void SignalHandler::handleSignal(int signum) { 70void SignalHandler::handleSignal(int signum) {
71 if (signum >= NSIG) 71 if (signum >= NSIG)
72 return; 72 return;
73 // make sure we got a handler for this signal 73 // make sure we got a handler for this signal
74 if (s_signal_handler[signum] != 0) { 74 if (s_signal_handler[signum] != 0) {
75 s_signal_handler[signum]->handleSignal(signum); 75 s_signal_handler[signum]->handleSignal(signum);
76 } 76 }
77} 77}
78 78
79}; 79};