NuriaProject Framework
0.1
The NuriaProject Framework
|
Utility class to react to UNIX signals in a Qt fashion. More...
#include <unixsignalhandler.hpp>
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 UnixSignalHandler * | get () |
Utility class to react to UNIX signals in a Qt fashion.
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().
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.
|
override |
Destructor.
|
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.
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.
|
signal |
Emitted on SIGINT
.
|
signal |
Emitted when any signal has been raised.
|
signal |
Emitted on SIGTERM
.
|
signal |
Emitted on SIGUSR1
.
|
signal |
Emitted on SIGUSR2
.