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-2009 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 as published by
21 * the Free Software Foundation, either version 3 of the License, or
24 * Anytun is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
33 #ifndef ANYTUN_signalController_h_INCLUDED
34 #define ANYTUN_signalController_h_INCLUDED
39 #include "threadUtils.hpp"
50 virtual ~SignalHandler() {}
52 virtual int handle() { return 0; }
53 virtual int handle(const std::string& msg) { return 0; }
56 SignalHandler(int s) : sigNum(s) {}
60 friend class SignalController;
63 class SigErrorHandler : public SignalHandler
66 SigErrorHandler() : SignalHandler(SIGERROR) {}
67 int handle(const std::string& msg);
71 class SigIntHandler : public SignalHandler
74 SigIntHandler() : SignalHandler(SIGINT) {}
78 class SigQuitHandler : public SignalHandler
81 SigQuitHandler() : SignalHandler(SIGQUIT) {}
85 class SigHupHandler : public SignalHandler
88 SigHupHandler() : SignalHandler(SIGHUP) {}
92 class SigUsr1Handler : public SignalHandler
95 SigUsr1Handler() : SignalHandler(SIGUSR1) {}
99 class SigUsr2Handler : public SignalHandler
102 SigUsr2Handler() : SignalHandler(SIGUSR2) {}
106 class SigTermHandler : public SignalHandler
109 SigTermHandler() : SignalHandler(SIGTERM) {}
115 class CtrlCHandler : public SignalHandler
118 CtrlCHandler() : SignalHandler(CTRL_C_EVENT) {}
122 class CtrlBreakHandler : public SignalHandler
125 CtrlBreakHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
129 class CtrlCloseHandler : public SignalHandler
132 CtrlCloseHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
136 class CtrlLogoffHandler : public SignalHandler
139 CtrlLogoffHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
143 class CtrlShutdownHandler : public SignalHandler
146 CtrlShutdownHandler() : SignalHandler(CTRL_BREAK_EVENT) {}
151 class SignalController
154 static SignalController& instance();
158 static bool handle(DWORD ctrlType);
163 void inject(int sig, const std::string& msg = "");
166 typedef std::map<int, SignalHandler*> HandlerMap;
168 SignalController() {};
170 SignalController(const SignalController &s);
171 void operator=(const SignalController &s);
173 static SignalController* inst;
174 static Mutex instMutex;
175 class instanceCleaner {
176 public: ~instanceCleaner() {
177 if(SignalController::inst != NULL)
178 delete SignalController::inst;
181 friend class instanceCleaner;
183 typedef std::pair<int, std::string> SigPair;
184 std::queue<SigPair> sigQueue;
186 Semaphore sigQueueSem;
191 extern SignalController& gSignalController;