TSDuck v3.40-4033
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::WatchDog Class Reference

General-purpose timeout watchdog. More...

#include <tsWatchDog.h>

Inheritance diagram for ts::WatchDog:
Collaboration diagram for ts::WatchDog:

Public Member Functions

 WatchDog (WatchDogHandlerInterface *handler=nullptr, cn::milliseconds timeout=cn::milliseconds::zero(), int id=0, Report &log=(ts::NullReport::Instance()))
 Constructor.
 
virtual ~WatchDog () override
 Destructor.
 
void restart ()
 Restart the watchdog, the previous timeout is canceled.
 
void setTimeout (cn::milliseconds timeout, bool autoStart=false)
 Set a new timeout value.
 
void setWatchDogHandler (WatchDogHandlerInterface *h)
 Replace the watchdog handler.
 
void setWatchDogId (int id)
 Set some arbitrary "watchdog id" value.
 
void suspend ()
 Suspend the watchdog, the previous timeout is canceled.
 
int watchDogId () const
 Get the "watchdog id" value, as previously stored by the application.
 

Detailed Description

General-purpose timeout watchdog.

The watchdog is initially suspended. A call to restart() reinitializes the timer and starts the watchdog. After the timeout, the watchdog automatically triggers a "next input". To avoid this, restart() or suspend() must be called before the timeout expires.

A WatchDog instance contains an internal thread which is started in the constructor and terminated in the destructor.

Constructor & Destructor Documentation

◆ WatchDog()

ts::WatchDog::WatchDog ( WatchDogHandlerInterface handler = nullptr,
cn::milliseconds  timeout = cn::milliseconds::zero(),
int  id = 0,
Report log = (ts::NullReport::Instance()) 
)

Constructor.

Parameters
[in]handlerInitial handler to call at expiration of the watchdog timeout.
[in]timeoutInitial watchdog timeout in milliseconds. Zero means no timeout.
[in]idApplication-defined watchdog id to assign. This value is chosen and set by the application. It can be retrieved later if a handler is used by several watchdogs. The id is not interpreted by the watchdog, it is only stored for the application.
[in,out]logLog report.

Member Function Documentation

◆ setTimeout()

void ts::WatchDog::setTimeout ( cn::milliseconds  timeout,
bool  autoStart = false 
)

Set a new timeout value.

Parameters
[in]timeoutNew watchdog timeout in milliseconds. Zero means no timeout.
[in]autoStartIf true and timeout is non zero, the timeout is automatically started. Otherwise, it is suspended. The previous timeout, if active, is automatically canceled.

◆ setWatchDogHandler()

void ts::WatchDog::setWatchDogHandler ( WatchDogHandlerInterface h)

Replace the watchdog handler.

Parameters
[in]hThe new handler. Can be zero.

◆ setWatchDogId()

void ts::WatchDog::setWatchDogId ( int  id)
inline

Set some arbitrary "watchdog id" value.

Parameters
[in]idApplication-defined watchdog id to assign.

◆ watchDogId()

int ts::WatchDog::watchDogId ( ) const
inline

Get the "watchdog id" value, as previously stored by the application.

Returns
The application-defined watchdog id.

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