Go to the documentation of this file.
20 if ( autostart )
start();
44 while ( is_stopped.wait_until( nextCheck ) == std::future_status::timeout ) {
void stop()
Signal the watchdog thread to stop and wait for it.
void ping()
Function to call to notify the watchdog thread that we are still alive.
time_point getLastPing() const
Get the time of latest ping.
WatchdogThread(std::chrono::seconds timeout, bool autostart=false)
Constructor.
virtual ~WatchdogThread()
Destructor.
virtual void onPing()
User implemented function that will be called when ping is called.
virtual void onStart()
User implemented function that will be called when starting.
void start()
Start the watchdog thread.
virtual void action()
User implemented function that will be called if the time-out is reached.
std::promise< void > m_stop_thread
Flag to mark the thread as running/stopped (avoid possible race conditions).
std::chrono::seconds getTimeout() const
Get the current time-out value.
virtual void onStop()
User implemented function that will be called when stopping.
std::thread m_thread
Running thread;.