Main Page   Class Hierarchy   Compound List   Compound Members  

ArSignalHandler Class Reference

Signal handling class. More...

#include <ArSignalHandler.h>

Inheritance diagram for ArSignalHandler::

ArASyncTask ArThread List of all members.

Public Methods

virtual ~ArSignalHandler ()
 Destructor.

virtual void * runThread (void *arg)
 The main run loop. More...


Static Public Methods

void createHandlerNonThreaded ()
 Setup the signal handling for a non-threaded program. More...

void createHandlerThreaded ()
 Setup the signal handling for a multi-threaded program. More...

void blockCommon ()
 Block all the common signals the kill a program. More...

void unblockAll ()
 Unblock all the signals. More...

void block (Signal sig)
 Block the given signal. More...

void unblock (Signal sig)
 Unblock the given signal. More...

void handle (Signal sig)
 Handle the given signal. More...

void unhandle (Signal sig)
 Dont handle the given signal. More...

void addHandlerCB (ArFunctor1< int > *func, ArListPos::Pos position)
 Add a handler callback. More...

void delHandlerCB (ArFunctor1< int > *func)
 Remove a handler callback. More...

ArSignalHandler * getHandler ()
 Get a pointer to the single ArSignalHandler instance. More...

std::string nameSignal (int sig)
 Get the name of the given signal.

void blockCommonThisThread ()
 Block all the common signals for the calling thread only. More...


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.


Member Function Documentation

void ArSignalHandler::addHandlerCB ArFunctor1< int > *    func,
ArListPos::Pos    position
[static]
 

Add a handler callback.

Add a handler callback to the list of callbacks. When there is a signal sent to the process, the list of callbacks are invoked and passed the signal number.

Parameters:
functor  functor created from ArFunctorC1<int> which refers to the function to call.
position  whether to place the functor first or last

void ArSignalHandler::block Signal    sig [static]
 

Block the given signal.

Block the given signal. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

Parameters:
sig  the number of the signal

void ArSignalHandler::blockCommon   [static]
 

Block all the common signals the kill a program.

Sets the signal handler to block all the common signals. The 'common' signals are SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGSEGV, and SIGPIPE. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

void ArSignalHandler::blockCommonThisThread   [static]
 

Block all the common signals for the calling thread only.

Block all the common signals for the calling thread. The calling thread will never recieve the common signals which are SIGHUP, SIGINT, SIGQUIT, and SIGTERM. This function can be called at any time.

void ArSignalHandler::createHandlerNonThreaded   [static]
 

Setup the signal handling for a non-threaded program.

Sets up the signal handling for a non-threaded program. When the program This uses the system call signal(2). This should not be used if you have a threaded program.

See also:
createHandlerThreaded

void ArSignalHandler::createHandlerThreaded   [static]
 

Setup the signal handling for a multi-threaded program.

Sets up the signal handling for a non-threaded program. This call is only usefull for Linux. This will create a dedicated thread in which to handle signals. The thread calls sigwait(3) and waits for a signal to be sent. By default all ArThread instances block all signals. Thus the signal is sent to the signal handler thread. This will allow the other threads to continue uninterrupted and not skew their timing loops.

See also:
createHandlerNonThreaded

void ArSignalHandler::delHandlerCB ArFunctor1< int > *    func [static]
 

Remove a handler callback.

Remove a handler callback from the list of callbacks.

Parameters:
functor  functor created from ArFunctorC1<int> which refers to the function to call.

ArSignalHandler * ArSignalHandler::getHandler   [static]
 

Get a pointer to the single ArSignalHandler instance.

Get a pointer to the single instance of the ArSignalHandler. The signal handler uses the singleton model, which means there can only be one instance of ArSignalHandler. If the single instance of ArSignalHandler has not been created, getHandler will create it. This is how the handler should be created.

Returns:
returns a pointer to the instance of the signal handler

void ArSignalHandler::handle Signal    sig [static]
 

Handle the given signal.

Handle the given signal. All the handler callbacks will be called with this signal when it is recieved. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

Parameters:
sig  the number of the signal

void * ArSignalHandler::runThread void *    arg [virtual]
 

The main run loop.

Override this function and put your taskes run loop here. Check the value of getRunning() or myRunning periodicly in your loop. If the value goes false, the loop should exit and runThread() should return.

Reimplemented from ArASyncTask.

void ArSignalHandler::unblock Signal    sig [static]
 

Unblock the given signal.

Unblock the given signal. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

Parameters:
sig  the number of the signal

void ArSignalHandler::unblockAll   [static]
 

Unblock all the signals.

Unblock all the signals. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

void ArSignalHandler::unhandle Signal    sig [static]
 

Dont handle the given signal.

Do not handle the given signal. Call this before calling createHandlerNonThreaded or createHandlerThreaded.

Parameters:
sig  the number of the signal


The documentation for this class was generated from the following files:
Generated on Tue Nov 12 17:44:05 2002 for Aria by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001