Kodi Development  20.0
for Binary and Script based Add-Ons

Detailed Description

Time interval management
Class which enables a time interval to be called up by a given function or class by means of a thread.

His code uses the support of platform-independent thread system introduced with C++11.


Example:

#include <kodi/tools/Timer.h>
class ATTRIBUTE_HIDDEN CExample
{
public:
CExample() : m_timer([this](){TimerCall();})
{
m_timer.Start(5000, true); // let call continuously all 5 seconds
}
void TimerCall()
{
fprintf(stderr, "Hello World\n");
}
private:
};
Definition: Timer.h:59

Modules

 class ITimerCallback
 Callback class of timer
To give on contructor by CTimer(kodi::tools::CTimer::ITimerCallback* callback)
 

Function Documentation

◆ CTimer() [1/2]

CTimer ( kodi::tools::CTimer::ITimerCallback callback)
inlineexplicit

Class constructor to pass individual other class as callback.

Parameters
[in]callbackChild class of parent ITimerCallback with implemented function ITimerCallback::OnTimeout().

◆ CTimer() [2/2]

CTimer ( std::function< void()> const &  callback)
inlineexplicit

Class constructor to pass individual function as callback.

Parameters
[in]callbackFunction to pass as callback about timeout.

Callback function style:

void TimerCallback()
{
}

◆ ~CTimer()

~CTimer ( )
inlineoverride

Class destructor.

◆ Start()

bool Start ( uint64_t  timeout,
bool  interval = false 
)
inline

Start the timer by given time in milliseconds to make his call by arrive of them.

If interval is activated, it calls the associated callback function continuously in the given interval.

Parameters
[in]timeoutTimeout in milliseconds
[in]interval[opt] To run continuously if true, false only one time and default
Returns
True if successfully done, false if not (callback missing, timeout = 0 or was already running.

◆ Stop()

bool Stop ( bool  wait = false)
inline

Stop the timer if it is active.

Parameters
[in]wait[opt] Wait until timer is stopped, false is default and call unblocked
Returns
True if timer was active and was stopped, false if already was stopped.

◆ Restart()

bool Restart ( )
inline

Restart timer complete by stop and restart his thread again.

Note
Restart only possible as long the timer was running and not done his work.
Returns
True if start was successfully done, on error, or if was already finished returned as false

◆ RestartAsync()

void RestartAsync ( uint64_t  timeout)
inline

Restart the timer with new timeout without touch of his thread.

Parameters
[in]timeoutTime as milliseconds to wait for next call

◆ IsRunning()

bool IsRunning ( ) const
inline

Check timer is still active to wait for next call.

Returns
True if active, false if all his work done and no more running

◆ GetElapsedSeconds()

float GetElapsedSeconds ( ) const
inline

Get elapsed time as floating point of timer as seconds.

Returns
Elapsed time

◆ GetElapsedMilliseconds()

float GetElapsedMilliseconds ( ) const
inline

Get elapsed time as floating point of timer as milliseconds.

Returns
Elapsed time