diff options
author | Christian Pointner <equinox@anytun.org> | 2010-01-20 06:52:41 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2010-01-20 06:52:41 +0000 |
commit | 1bdddd7da2ebe39b0b817e08673aef7756438796 (patch) | |
tree | df35725629db0a5a056e3168207b89aade1e3132 /src/signalController.cpp | |
parent | fixed signal handler on windows (diff) |
moved from SignalHandler Classes to boost::functions
Diffstat (limited to 'src/signalController.cpp')
-rw-r--r-- | src/signalController.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/signalController.cpp b/src/signalController.cpp index cc31c75..f0191fe 100644 --- a/src/signalController.cpp +++ b/src/signalController.cpp @@ -32,13 +32,13 @@ #include <map> #include <iostream> +#include <boost/bind.hpp> #include "signalController.h" #include "log.h" #include "anytunError.h" #include "threadUtils.hpp" - SignalController* SignalController::inst = NULL; Mutex SignalController::instMutex; SignalController& gSignalController = SignalController::instance(); @@ -53,30 +53,24 @@ SignalController& SignalController::instance() return *inst; } -int SigErrorHandler::handle(const std::string& msg) +int SigErrorHandler(const SigNum& /*sig*/, const std::string& msg) { AnytunError::throwErr() << msg; return 0; } -// use system specific signal handler +//use system specific signal handler #ifndef _MSC_VER #include "signalHandler.hpp" #else #include "win32/signalHandler.hpp" #endif -SignalController::~SignalController() -{ - for(HandlerMap::iterator it = handler.begin(); it != handler.end(); ++it) - delete it->second; -} - void SignalController::init() { registerSignalHandler(*this); - handler[SIGERROR] = new SigErrorHandler; + handler[SIGERROR] = boost::bind(SigErrorHandler, _1, _2); } void SignalController::inject(int sig, const std::string& msg) @@ -90,6 +84,11 @@ void SignalController::inject(int sig, const std::string& msg) int SignalController::run() { + for(CallbackMap::iterator it = callbacks.begin(); it != callbacks.end(); ++it) + if(it->first == CALLB_RUNNING) + it->second(CALLB_RUNNING); + + int ret = 0; while(1) { sigQueueSem.down(); SigPair sig; @@ -102,18 +101,19 @@ int SignalController::run() HandlerMap::iterator it = handler.find(sig.first); if(it != handler.end()) { - int ret; - if(sig.second == "") - ret = it->second->handle(); - else - ret = it->second->handle(sig.second); + ret = it->second(sig.first, sig.second); if(ret) - return ret; + break; } else cLog.msg(Log::PRIO_NOTICE) << "SIG " << sig.first << " caught with message '" << sig.second << "' - ignoring"; } - return 0; + + for(CallbackMap::iterator it = callbacks.begin(); it != callbacks.end(); ++it) + if(it->first == CALLB_STOPPING) + it->second(CALLB_STOPPING); + + return ret; } |