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...
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:
{
public:
CExample() : m_timer([this](){TimerCall();})
{
m_timer.Start(5000, true);
}
void TimerCall()
{
fprintf(stderr, "Hello World\n");
}
private:
};
#define ATTR_DLL_LOCAL
Definition addon_base.h:86
◆ CTimer() [1/2]
Class constructor to pass individual other class as callback.
- Parameters
-
◆ CTimer() [2/2]
kodi::tools::CTimer::CTimer |
( |
std::function< void()> const & | callback | ) |
|
|
inlineexplicit |
Class constructor to pass individual function as callback.
- Parameters
-
[in] | callback | Function to pass as callback about timeout. |
Callback function style:
◆ 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] | timeout | Time 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] | timeout | Timeout 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 |