Image Component Library (ICL)
|
C++ Signal-Handler interface class. More...
#include <SignalHandler.h>
Public Member Functions | |
SignalHandler (const std::string &signals="SIGINT,SIGHUP,SIGTERM,SIGSEGV") | |
Create a new Signal handler with a list of signals. | |
virtual | ~SignalHandler () |
Destructor. | |
virtual void | handleSignals (const std::string &signalAsString)=0 |
virtual signal handling function | |
void | oldAction (const std::string &signal) |
calls the original action which was associated to the corresponding signal | |
Static Public Member Functions | |
static void | killCurrentProcess () |
kills the current process | |
Private Attributes | |
std::vector< int > | m_vecAssocitatedSignals |
internal storage of associated signals |
C++ Signal-Handler interface class.
Just create an own signal handler class, implement its handleSignal() function and create a static object of that signal handler.
example:
class MySignalHandler : public icl::utils::SignalHandler{ public: MySignalHandler():SignalHandler("SIGINT,SIGSEGV"){} virtual void handleSignals(const string &signal){ if(signal == "SIGINT") printf("application interrupted! \n"); else printf("Oops something went wrong ...! \n"); killCurrentProcess(); } };
icl::utils::SignalHandler::SignalHandler | ( | const std::string & | signals = "SIGINT,SIGHUP,SIGTERM,SIGSEGV" | ) |
Create a new Signal handler with a list of signals.
The default parameters can be used to catch some common signals that may occur, when the program is uncommonly killed.
signals | comma-separated list of string representations of the following signals:
|
virtual icl::utils::SignalHandler::~SignalHandler | ( | ) | [virtual] |
Destructor.
When the destructor is called the system default signal handlers are substituted instead of the handleSignals function
virtual void icl::utils::SignalHandler::handleSignals | ( | const std::string & | signalAsString | ) | [pure virtual] |
virtual signal handling function
static void icl::utils::SignalHandler::killCurrentProcess | ( | ) | [static] |
kills the current process
internally this function calls kill(getpid(),1) which is mutch stronger than calling exit(0) (see the signal.h manpage)
void icl::utils::SignalHandler::oldAction | ( | const std::string & | signal | ) |
calls the original action which was associated to the corresponding signal
This seems to be not practible, as the old actions are not defined by callable functions in the old action sigaction struct.
std::vector<int > icl::utils::SignalHandler::m_vecAssocitatedSignals [private] |
internal storage of associated signals