4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
32 #ifndef _SIGNAL_CONTROLLER_H_
33 #define _SIGNAL_CONTROLLER_H_
38 #include "threadUtils.hpp"
49 virtual ~SignalHandler() {}
51 virtual int handle() { return 0; }
52 virtual int handle(const std::string& msg) { return 0; }
55 SignalHandler(int s) : sigNum(s) {}
59 friend class SignalController;
62 class SigErrorHandler : public SignalHandler
65 SigErrorHandler() : SignalHandler(SIGERROR) {}
66 int handle(const std::string& msg);
70 class SigIntHandler : public SignalHandler
73 SigIntHandler() : SignalHandler(SIGINT) {}
77 class SigQuitHandler : public SignalHandler
80 SigQuitHandler() : SignalHandler(SIGQUIT) {}
84 class SigHupHandler : public SignalHandler
87 SigHupHandler() : SignalHandler(SIGHUP) {}
91 class SigUsr1Handler : public SignalHandler
94 SigUsr1Handler() : SignalHandler(SIGUSR1) {}
98 class SigUsr2Handler : public SignalHandler
101 SigUsr2Handler() : SignalHandler(SIGUSR2) {}
105 class SigTermHandler : public SignalHandler
108 SigTermHandler() : SignalHandler(SIGTERM) {}
114 class CtrlCHandler : public SignalHandler
117 CtrlCHandler() : SignalHandler(CTRL_C_EVENT) {}
121 class CtrlBreakHandler : public SignalHandler
124 CtrlBreakHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
128 class CtrlCloseHandler : public SignalHandler
131 CtrlCloseHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
135 class CtrlLogoffHandler : public SignalHandler
138 CtrlLogoffHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
142 class CtrlShutdownHandler : public SignalHandler
145 CtrlShutdownHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
150 class SignalController
153 static SignalController& instance();
157 static bool handle(DWORD ctrlType);
162 void inject(int sig, const std::string& msg = "");
165 typedef std::map<int, SignalHandler*> HandlerMap;
168 SignalController() : thread(NULL) {};
170 SignalController() {};
173 SignalController(const SignalController &s);
174 void operator=(const SignalController &s);
176 static SignalController* inst;
177 static Mutex instMutex;
178 class instanceCleaner {
179 public: ~instanceCleaner() {
180 if(SignalController::inst != NULL)
181 delete SignalController::inst;
184 friend class instanceCleaner;
186 typedef std::pair<int, std::string> SigPair;
187 std::queue<SigPair> sigQueue;
189 Semaphore sigQueueSem;
192 boost::thread* thread;
197 extern SignalController& gSignalController;