Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

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

Topics

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

Classes

class  kodi::tools::CTimer
 

Functions

 kodi::tools::CTimer::CTimer (kodi::tools::CTimer::ITimerCallback *callback)
 Class constructor to pass individual other class as callback.
 
 kodi::tools::CTimer::CTimer (std::function< void()> const &callback)
 Class constructor to pass individual function as callback.
 
 kodi::tools::CTimer::~CTimer () override
 Class destructor.
 
bool kodi::tools::CTimer::Start (uint64_t timeout, bool interval=false)
 Start the timer by given time in milliseconds to make his call by arrive of them.
 
bool kodi::tools::CTimer::Stop (bool wait=false)
 Stop the timer if it is active.
 
bool kodi::tools::CTimer::Restart ()
 Restart timer complete by stop and restart his thread again.
 
void kodi::tools::CTimer::RestartAsync (uint64_t timeout)
 Restart the timer with new timeout without touch of his thread.
 
bool kodi::tools::CTimer::IsRunning () const
 Check timer is still active to wait for next call.
 
float kodi::tools::CTimer::GetElapsedSeconds () const
 Get elapsed time as floating point of timer as seconds.
 
float kodi::tools::CTimer::GetElapsedMilliseconds () const
 Get elapsed time as floating point of timer as milliseconds.
 

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:

class ATTR_DLL_LOCAL 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:
};
#define ATTR_DLL_LOCAL
Definition addon_base.h:86
Definition addons/kodi-dev-kit/include/kodi/tools/Timer.h:59

Function Documentation

◆ CTimer() [1/2]

kodi::tools::CTimer::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]

kodi::tools::CTimer::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()
{
}

◆ GetElapsedMilliseconds()

float kodi::tools::CTimer::GetElapsedMilliseconds ( ) const
inline

Get elapsed time as floating point of timer as milliseconds.

Returns
Elapsed time

◆ GetElapsedSeconds()

float kodi::tools::CTimer::GetElapsedSeconds ( ) const
inline

Get elapsed time as floating point of timer as seconds.

Returns
Elapsed time

◆ IsRunning()

bool kodi::tools::CTimer::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

◆ Restart()

bool kodi::tools::CTimer::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 kodi::tools::CTimer::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

◆ Start()

bool kodi::tools::CTimer::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 kodi::tools::CTimer::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.

◆ ~CTimer()

kodi::tools::CTimer::~CTimer ( )
inlineoverride

Class destructor.