#include <SignalHandler.h>
Inheritance diagram for util::SignalHandler:

SignalHandler works by creating a thread that waits for the signals for which a handler has been set. The signals that SignalHandler is waiting for must be blocked by all other threads. This is done automatically when adding new handlers. When a signal is caught, the corresponding handler is invoked.
Example
class MyHandler : public SignalHandler
{
public:
void handleSignal(int signal)
{
switch (signal)
{
case SIGINT: break;
case SIGUSR1: break;
}
}
};
...
MyHandler myHandler;
SignalHandler::addHandler(SIGINT, &myHandler); //myHandler handles SIGINT
SignalHandler::addHandler(SIGUSR1, &myHandler); //... and SIGUSR1
SignalHandler::start();
It is advisable that you create the needed signal handlers before any threads are created in you process to ensure the signal masks are set correctly.
Public Methods | |
| SignalHandler () | |
| virtual | ~SignalHandler () |
| virtual void | handleSignal (int signal)=0 |
| This function is invoked by the SignalHandler when a signal is caught on which a handler is registered. | |
Static Public Methods | |
| void | setHandler (int signal, SignalHandler *handler) throw (InvalidArgumentException&) |
| Set a handler for signal. | |
| void | removeHandler (int signal) throw (InvalidArgumentException&) |
| Remove a signal handler. | |
| void | blockSignals () |
| Block all signals from the calling process. | |
| void | unblockSignals () |
| Unblock all signals from the calling process. | |
| void | blockSignal (int sig) throw (InvalidArgumentException&) |
| Block a signal from the calling process. | |
| void | unblockSignal (int sig) throw (InvalidArgumentException&) |
| Unblock a signal from the calling process. | |
| void | start () |
| Start the signal handling. | |
| void | stop () |
| Halt the signal handler. | |
Friends | |
| class | HandlerThread |
|
|
Block a signal from the calling process. The calling process and all threads created by it after this call will not see the specified signal.
|
|
|
Block all signals from the calling process. The calling process and all threads created by it after this call will not see any signals. |
|
|
This function is invoked by the SignalHandler when a signal is caught on which a handler is registered.
|
|
|
Remove a signal handler. If a handler is removed after the start() method has been called, the signal is still delivered to this SignalHandler. In this case, SignalHandler resends the signal to the owner process.
|
|
||||||||||||
|
Set a handler for signal. The signal numbers are specified in signal.h (see the Unix manual). Typical examples include SIGINT (Ctrl-C), SIGUSR1 (user signal 1) and the like. If a handler is added after the start() method has been called, the newly added signal will be caught only after some other, previously added signal has been caught. The handler of a signal can, however, be changed with no problems.
|
|
|
Start the signal handling. This method starts a thread that waits for the signals specified by setHandler() calls. Only one such thread can be active, and the signals must be blocked by other threads. |
|
|
Halt the signal handler. Actually, the signal handler exits only after one of the signals it has been waiting for is issued. Thus, calling stop() and start() again is not a good idea, unless you explicitly send a signal that causes the handler to exit. |
|
|
Unblock a signal from the calling process. The calling process and all threads created by it after this call will see the specified signal in addition to other unblocked signals.
|
|
|
Unblock all signals from the calling process. The calling process and all threads created by it after this call will see all signals. |