TSDuck Version 3.22-1914 (TSDuck - The MPEG Transport Stream Toolkit)
ts::WatchDog Class Reference

General-purpose timeout watchdog. More...

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

Public Member Functions

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

Private Member Functions

void getAttributes (ThreadAttributes &attributes)
 Get a copy of the attributes of the thread. More...
UString getTypeName () const
 Get an implementation-specific name of the object class. More...
bool isCurrentThread () const
 Check if the caller is running in the context of this thread. More...
bool setAttributes (const ThreadAttributes &attributes)
 Set new attributes to the thread. More...
void setTypeName (const UString &name=UString())
 Set the type name. More...
bool start ()
 Start the thread. More...
bool waitForTermination ()
 Wait for thread termination. More...

Static Private Member Functions

static void Yield ()
 Yield execution of the current thread. More...

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,
MilliSecond  timeout = 0,
int  id = 0,
Report log = (*(static_cast< ts::Report *>(ts::NullReport::Instance()))) 


[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 ( MilliSecond  timeout,
bool  autoStart = false 

Set a new timeout value.

[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.

[in]hThe new handler. Can be zero.

◆ setWatchDogId()

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

Set some arbitrary "watchdog id" value.

[in]idApplication-defined watchdog id to assign.

◆ watchDogId()

int ts::WatchDog::watchDogId ( ) const

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

The application-defined watchdog id.

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