ArSignalHandler Class Reference

#include <ArSignalHandler.h>

Inheritance diagram for ArSignalHandler:

ArASyncTask ArThread List of all members.

Detailed Description

Signal handling class.

This is a signal handling class. It has both a threaded and non-threaded mode of operation. The non-threaded mode will work in a threaded application but it is best to use the threaded mode. The benefit of the threaded mode is that if the signal incures some processing, but does not shutdown the program (ie. SIGUSR1 or SIGUSR2), the threaded mode will handle the signal in its own thread and hopefully that will not hurt the performance of the tight loop robot control. Exaclty how much performance you get out of this depends on your machines physical hardware and exactly what the processing the signal handler does. For instance, a multi-processor machine has a much greater chance of the signal handler not interfering with the robot control loop.

See the Aria main class for how to initialize a default setup of the signal handling.

There are functions to block, unblock, handle and unhandle signals. These functions all must be called before creating the signalhandler. In either single or multi-threaded mode. The functions to block and handle signals creates a set of blocking and handling which is then used by the create functions to tell the Linux kernel what to do.

In the threaded mode, there is a signal handler thread that is created. That thread is created in a detached state, which means it can not be joined on. When the program exits, the signal handler thread will be ignored and that thread will never exit its run loop. This is perfectly fine behavior. There is no state that can be messed up in this fashion. It is just easier to exit the program than to try to wake up that thread and get it to exit itself.

This class is for Linux only. Windows has virtualy no support for signals and the little support that it does have is not realy usefull. There is an empty implementation of this class for Windows so that code can compile in both Linux and Windows. Just do not expect the code that uses this signal handling to do anything in Windows. This should not be a problem since signals are not used in Windows.


Public Types

enum  Signal {
  SigHUP = 1, SigINT, SigQUIT, SigILL,
  SigTRAP, SigABRT, SigBUS, SigFPE,
  SigKILL, SigUSR1, SigSEGV, SigUSR2,
  SigPIPE, SigALRM, SigTERM, SigSTKFLT,
  SigCHLD, SigCONT, SigSTOP, SigTSTP,
  SigTTIN, SigTTOU, SigURG, SigXCPU,
  SigXFSZ, SigVTALRM, SigPROF, SigWINCH,
  SigIO, SigPWR
}

Public Member Functions

virtual void * runThread (void *arg)
virtual ~ArSignalHandler ()
 Destructor.

Static Public Member Functions

static void addHandlerCB (ArFunctor1< int > *func, ArListPos::Pos position)
 Add a handler callback.
static void block (Signal sig)
 Block the given signal.
static void blockAllThisThread ()
 Block all the signals for the calling thread only.
static void blockCommon ()
 Block all the common signals the kill a program.
static void blockCommonThisThread ()
 Block all the common signals for the calling thread only.
static void createHandlerNonThreaded ()
 Setup the signal handling for a non-threaded program.
static void createHandlerThreaded ()
 Setup the signal handling for a multi-threaded program.
static void delAllHandlerCBs (void)
 Removes all the handlers.
static void delHandlerCB (ArFunctor1< int > *func)
 Remove a handler callback.
static ArSignalHandlergetHandler ()
 Get a pointer to the single ArSignalHandler instance.
static void handle (Signal sig)
 Handle the given signal.
static void logThread (void)
static const char * nameSignal (int sig)
 Get the name of the given signal.
static void signalCB (int sig)
static void unblock (Signal sig)
 Unblock the given signal.
static void unblockAll ()
 Unblock all the signals.
static void unhandle (Signal sig)
 Dont handle the given signal.

Static Protected Member Functions

static void initSigMap ()

Protected Attributes

bool ourIgnoreQUIT

Static Protected Attributes

static sigset_t ourBlockSigSet
static std::list< ArFunctor1<
int > * > 
ourHandlerList
static sigset_t ourHandleSigSet
static ArStrMap ourSigMap
static ArSignalHandlerourSignalHandler


The documentation for this class was generated from the following file:
Generated on Thu Aug 6 09:39:37 2009 for Aria by  doxygen 1.5.1