Class SignalWatcher

Class Documentation

class SignalWatcher

The SignalWatcher waits for SIGINT and SIGTERM. One can wait until the signal has occurred or ask the watcher if it has occurred.

// can be used to loop until SIGINT or SIGTERM has occurred
#include <iceoryx_hoofs/posix/signal_watcher.hpp>
void loopUntilTerminationRequested()
{
    while(!iox::posix::hasTerminationRequested())
    {
        // your algorithm
    }
}

// another possibility is to block until SIGINT or SIGTERM has occurred
void blockUntilCtrlC() {
    // your objects which spawn threads
    iox::posix::waitForTerminationRequest();
}

Public Functions

SignalWatcher(const SignalWatcher&) = delete
SignalWatcher(SignalWatcher&&) = delete
~SignalWatcher() = default
SignalWatcher &operator=(const SignalWatcher&) = delete
SignalWatcher &operator=(SignalWatcher&&) = delete
void waitForSignal() const noexcept

Blocks until either SIGTERM or SIGINT has occurred.

bool wasSignalTriggered() const noexcept

Returns true when SIGTERM or SIGINT has occurred, otherwise false.

Public Static Functions

static SignalWatcher &getInstance() noexcept

Returns the singleton instance of the SignalWatcher.

Protected Functions

SignalWatcher() noexcept