All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::WatchDog Exception Referencefinal

A guard that is used to make sure that programs do not get stuck. More...

#include <Radiant/WatchDog.hpp>

Inheritance diagram for Radiant::WatchDog:
Radiant::Thread

Public Member Functions

long addListener (std::function< void()> callback)
 Add a listener that is called just before the watchdog is shutting down the process. More...
 
void forgetHost (void *key)
 Instructs the Watchdog to forget some hosting object. More...
 
void hostIsAlive (void *key)
 Inform the watchdog that the host application is working. More...
 
void pause ()
 Pauses the watchdog.
 
bool paused () const
 Check if the watchdog is paused. More...
 
void removeListener (long id)
 Remove listener. More...
 
void setInterval (float seconds)
 Sets the interval for checking if the host is alive. More...
 
void stop ()
 Stops the watchdog. More...
 
void unpause ()
 Unpause the watchdog.
 
 WatchDog ()
 Constructor.
 
 ~WatchDog ()
 Destructor.
 

Static Public Member Functions

static bool isEnabled ()
 Is the watchdog disabled by the user. More...
 
static void setEnabled (bool enabled)
 Enable or disable the watchdog. More...
 

Additional Inherited Members

- Private Types inherited from Radiant::Thread
typedef void * id_t
 Thread id type. More...
 
- Private Member Functions inherited from Radiant::Thread
bool isRunning () const
 Check if the thread is running. More...
 
void run ()
 Starts the thread.
 
void setName (const QString &name)
 Set the thread name. More...
 
 Thread (const QString &name="Radiant::Thread")
 Construct a thread structure. More...
 
bool waitEnd (int timeoutms=0)
 Waits until thread is finished. More...
 
virtual ~Thread ()
 Destructor. More...
 
- Static Private Member Functions inherited from Radiant::Thread
static id_t myThreadId ()
 The id of the calling thread. More...
 

Detailed Description

A guard that is used to make sure that programs do not get stuck.

If the program appears to be stuck (not calling hostIsAlive for given time) then this class simply shuts down the application.

Member Function Documentation

long Radiant::WatchDog::addListener ( std::function< void()>  callback)

Add a listener that is called just before the watchdog is shutting down the process.

Returns
listener id
void Radiant::WatchDog::forgetHost ( void *  key)

Instructs the Watchdog to forget some hosting object.

Parameters
keyThe identifier of the calling object.
void Radiant::WatchDog::hostIsAlive ( void *  key)

Inform the watchdog that the host application is working.

You can call this function at any time, and the call is fully thread-safe. After calling this method for the first time, you need to keep calling it periodically, to make sure that the watchdog knows you are there.

Parameters
keyThe identifier of the calling object. This is usually a point to some object which provides a handy way of generating unique keys in C/C++.
static bool Radiant::WatchDog::isEnabled ( )
static

Is the watchdog disabled by the user.

Returns
true if watchdog is enabled
See Also
setEnabled
bool Radiant::WatchDog::paused ( ) const
inline

Check if the watchdog is paused.

Returns
true if paused; otherwise false
void Radiant::WatchDog::removeListener ( long  id)

Remove listener.

Parameters
idlistener id
static void Radiant::WatchDog::setEnabled ( bool  enabled)
static

Enable or disable the watchdog.

This function only sets the flag if the watchdog should be used. It is up to the user the check the flag.

Parameters
enabledshould the watchdog be enabled?
See Also
isEnabled
void Radiant::WatchDog::setInterval ( float  seconds)
inline

Sets the interval for checking if the host is alive.

Parameters
secondsLength of the interval in seconds
void Radiant::WatchDog::stop ( )

Stops the watchdog.