signalController.h

Go to the documentation of this file.
00001 /*
00002  *  anytun
00003  *
00004  *  The secure anycast tunneling protocol (satp) defines a protocol used
00005  *  for communication between any combination of unicast and anycast
00006  *  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
00007  *  mode and allows tunneling of every ETHER TYPE protocol (e.g.
00008  *  ethernet, ip, arp ...). satp directly includes cryptography and
00009  *  message authentication based on the methodes used by SRTP.  It is
00010  *  intended to deliver a generic, scaleable and secure solution for
00011  *  tunneling and relaying of packets of any protocol.
00012  *
00013  *
00014  *  Copyright (C) 2007 anytun.org <satp@wirdorange.org>
00015  *
00016  *  This program is free software; you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License version 2
00018  *  as published by the Free Software Foundation.
00019  *
00020  *  This program is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  You should have received a copy of the GNU General Public License
00026  *  along with this program (see the file COPYING included with this
00027  *  distribution); if not, write to the Free Software Foundation, Inc.,
00028  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  */
00030 
00031 #ifndef _SIGNAL_CONTROLLER_H_
00032 #define _SIGNAL_CONTROLLER_H_
00033 
00034 #include <csignal>
00035 #include <map>
00036 #include <queue>
00037 
00038 #include "threadUtils.hpp"
00039 
00040 class SignalHandler
00041 {
00042 public:
00043   virtual ~SignalHandler() {}
00044 
00045   virtual int handle() { return 0; }
00046 
00047 protected:
00048   SignalHandler(int s) : sigNum(s) {}
00049 
00050 private:
00051   int sigNum;
00052   friend class SignalController;
00053 };
00054 
00055 class SigIntHandler : public SignalHandler
00056 {
00057 public:
00058   SigIntHandler() : SignalHandler(SIGINT) {}
00059   int handle();
00060 };
00061 
00062 class SigQuitHandler : public SignalHandler
00063 {
00064 public:
00065   SigQuitHandler() : SignalHandler(SIGQUIT) {}
00066   int handle();
00067 };
00068 
00069 class SigHupHandler : public SignalHandler
00070 {
00071 public:
00072   SigHupHandler() : SignalHandler(SIGHUP) {}
00073   int handle();
00074 };
00075 
00076 class SigUsr1Handler : public SignalHandler
00077 {
00078 public:
00079   SigUsr1Handler() : SignalHandler(SIGUSR1) {}
00080   int handle();
00081 };
00082 
00083 class SigUsr2Handler : public SignalHandler
00084 {
00085 public:
00086   SigUsr2Handler() : SignalHandler(SIGUSR2) {}
00087   int handle();
00088 };
00089 
00090 class SigTermHandler : public SignalHandler
00091 {
00092 public:
00093   SigTermHandler() : SignalHandler(SIGTERM) {}
00094   int handle();
00095 };
00096 
00097 class SignalController
00098 {
00099 public:
00100   SignalController() {}
00101   ~SignalController();
00102   static void* handle(void* s);
00103 
00104   void init();
00105   int run();
00106 
00107 private:
00108   typedef std::map<int, SignalHandler*> HandlerMap;
00109 
00110   SignalController(const SignalController &s);
00111   void operator=(const SignalController &s);
00112   
00113   std::queue<int> sigQueue;
00114   Mutex sigQueueMutex;
00115   Semaphore sigQueueSem;
00116 
00117   pthread_t thread;
00118   HandlerMap handler;
00119 };
00120 
00121 #endif

Generated on Mon Dec 3 11:49:24 2007 for anytun by  doxygen 1.5.1