NuriaProject Framework  0.1
The NuriaProject Framework
Signals | Public Member Functions | Static Public Member Functions | List of all members
Nuria::UnixSignalHandler Class Reference

Utility class to react to UNIX signals in a Qt fashion. More...

#include <unixsignalhandler.hpp>

Inheritance diagram for Nuria::UnixSignalHandler:

Signals

void sigInterrupt ()
 
void signalRaised (int signalId)
 
void sigTerm ()
 
void sigUser1 ()
 
void sigUser2 ()
 

Public Member Functions

 ~UnixSignalHandler () override
 
bool ignoreUnixSignal (int signalId)
 
void invokeOnSignal (int signalId, const Callback &callback)
 
bool isListeningTo (int signalId)
 
bool listenToUnixSignal (int signalId)
 

Static Public Member Functions

static UnixSignalHandlerget ()
 

Detailed Description

Utility class to react to UNIX signals in a Qt fashion.

Usage

To install your own handler, all you have to do is to tell the class that it should install a signal handler itself using listenToUnixSignal(). After that, you can connect to the various Qt signals which are emitted when a UNIX signal was triggered.

To uninstall a UNIX handler use ignoreUnixSignal().

Note
Connected signals and callbacks don't have to be signal-safe as they're run outside the signal itself.
Restrictions

Please note that the UNIX signal system is quite fragile. Other code may replace the installed signal handlers without warning.

When unregistering, the class tries to restore the old handler. If the old handler is invalid at this point, the result will be undefined behaviour likely crashing the process.

If there is another UNIX signal handler at time of registration, the old one will not be called, which can potentionally break other code. Please note that Qt installs a handler on SIGCHLD for QProcess - Thus you should not install your own handler on that UNIX signal.

See also sigaction(3) for in-depth details.

Constructor & Destructor Documentation

Nuria::UnixSignalHandler::~UnixSignalHandler ( )
override

Destructor.

Member Function Documentation

static UnixSignalHandler* Nuria::UnixSignalHandler::get ( )
static

Returns the global instance.

bool Nuria::UnixSignalHandler::ignoreUnixSignal ( int  signalId)

Will unregister the handler of signalId. Returns true on success. Returns false when signalId is not listened to or if deregistration failed.

void Nuria::UnixSignalHandler::invokeOnSignal ( int  signalId,
const Callback callback 
)

Instructs the class to invoke callback when unixSignal has been caught. unixSignal may be AllSignals. callback will receive the signal identifier of type int as only argument.

Note
The method will try to register a handler for unixSignal if it's not already listened to by the class.
bool Nuria::UnixSignalHandler::isListeningTo ( int  signalId)

Returns true if signalId is currently listened to, that means, if the class has a registered handler for it.

bool Nuria::UnixSignalHandler::listenToUnixSignal ( int  signalId)

The class will attempt to register as signal handler for signalId. If registration fails, false is returned. When already listening to signalId, true is returned.

void Nuria::UnixSignalHandler::sigInterrupt ( )
signal

Emitted on SIGINT.

void Nuria::UnixSignalHandler::signalRaised ( int  signalId)
signal

Emitted when any signal has been raised.

See also
listenToUnixSignal
void Nuria::UnixSignalHandler::sigTerm ( )
signal

Emitted on SIGTERM.

void Nuria::UnixSignalHandler::sigUser1 ( )
signal

Emitted on SIGUSR1.

void Nuria::UnixSignalHandler::sigUser2 ( )
signal

Emitted on SIGUSR2.


The documentation for this class was generated from the following file: