Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Private Attributes
icl::utils::SignalHandler Class Reference

C++ Signal-Handler interface class. More...

#include <SignalHandler.h>

List of all members.

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

Detailed Description

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();
          }
        };

Constructor & Destructor Documentation

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.

Parameters:
signalscomma-separated list of string representations of the following signals:
  • SIGABRT ( process abort signal)
  • SIGALRM ( Alarm clock)
  • SIGBUS ( Access to an undefined portion of a memory object)
  • SIGCHLD ( Child process terminated, stopped or continued)
  • SIGCONT ( Continue executing, if stopped)
  • SIGFPE ( Erroneous arithmetic operation)
  • SIGHUP ( Hangup )
  • SIGILL ( Illegal instruction )
  • SIGINT ( Terminal interrupt signal )
  • SIGKILL ( Kill (cannot be caught or ignored)
  • SIGPIPE ( Write on a pipe with no one to read it)
  • SIGQUIT ( Terminal quit signal )
  • SIGSEGV ( Invalid memory reference )
  • SIGSTOP ( Stop executing (cannot be caught or ignored) )
  • SIGTERM ( Termination signal )
  • SIGTSTP ( Terminal stop signal)
  • SIGTTIN ( Background process attempting read)
  • SIGTTOU ( Background process attempting write)
  • SIGUSR1 ( User-defined signal 1)
  • SIGUSR2 ( User-defined signal 2)
  • SIGPOLL ( Pollable event)
  • SIGPROF ( Profiling timer expired)
  • SIGSYS ( Bad system call)
  • SIGTRAP ( Trace/breakpoint trap )
  • SIGURG ( High bandwidth data is available at a socket)
  • SIGVTALRM ( Virtual timer expired)
  • SIGXCPU ( CPU time limit exceeded)
  • SIGXFSZ ( File size limit exceeded)

Destructor.

When the destructor is called the system default signal handlers are substituted instead of the handleSignals function


Member Function Documentation

virtual void icl::utils::SignalHandler::handleSignals ( const std::string &  signalAsString) [pure virtual]

virtual signal handling function

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.


Member Data Documentation

internal storage of associated signals


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines