1.10 |
Periodic timer. More...
#include <timer.h>
Public Member Functions | |
virtual void | start () |
Start the timer. | |
void | start () override |
Start the timer. | |
void | start (std::chrono::milliseconds duration) |
Start the timer with the specified duration. | |
Timer () noexcept | |
Construct a one-shot timer. | |
Timer (const Timer &)=delete | |
Timer (std::chrono::milliseconds duration) noexcept | |
Construct a one-shot timer with the specified duration. | |
Timer (Timer &&) | |
Public Member Functions inherited from Timer | |
Timer () noexcept | |
Construct a one-shot timer. | |
Timer (const Timer &)=delete | |
Timer (std::chrono::milliseconds duration) noexcept | |
Construct a one-shot timer with the specified duration. | |
Timer (Timer &&) | |
virtual | ~Timer () noexcept |
void | cancel () |
Cancel, or stop, the timer. | |
void | change_duration (std::chrono::milliseconds duration) |
Change the duration of the timer. | |
void | clear_handlers () |
Clear all handlers. | |
EGT_NODISCARD std::chrono::milliseconds | duration () const |
Return the current duration of the timer. | |
EGT_NODISCARD const std::string & | name () const |
Get the name of the Timer. | |
void | name (const std::string &name) |
Set the name of the Timer. | |
RegisterHandle | on_timeout (TimerCallback callback) |
Add a handler callback to be called with the timer times out. | |
Timer & | operator= (const Timer &)=delete |
Timer & | operator= (Timer &&) |
void | remove_handler (RegisterHandle handle) |
Remove an event handler. | |
EGT_NODISCARD bool | running () const |
Returns true if the timer is currently running. | |
void | start (std::chrono::milliseconds duration) |
Start the timer with the specified duration. | |
EGT_DEPRECATED void | start_with_duration (std::chrono::milliseconds duration) |
Start the timer with the specified duration. | |
void | stop () |
Alias for cancel(). | |
void | timeout () |
Called when the timer times out. | |
Additional Inherited Members | |
Public Types inherited from Timer | |
using | RegisterHandle = uint64_t |
Handle type. | |
using | TimerCallback = std::function< void()> |
Timer callback function definition. | |
Protected Types inherited from Timer | |
using | CallbackArray = std::vector< CallbackMeta > |
Type for array of registered callbacks. | |
Protected Member Functions inherited from Timer | |
void | invoke_handlers () |
Invoke any registered handlers. | |
Protected Attributes inherited from Timer | |
CallbackArray | m_callbacks |
Array of registered callbacks. | |
std::chrono::milliseconds | m_duration {} |
The duration of the timer. | |
RegisterHandle | m_handle_counter {0} |
Counter used to generate unique handles for each callback registration. | |
std::unique_ptr< TimerImpl > | m_impl |
std::string | m_name |
A user defined name for the Timer. | |
bool | m_running {false} |
When true, currently running. | |
asio::steady_timer | m_timer |
Asio timer object. | |
Periodic timer.
This is a timer that will keep firing at the duration interval until it is stopped by calling cancel().
Example
|
virtual |
|
overridevirtual |
|
inline |
Start the timer with the specified duration.
This overwrites any duration specified previously.
|
noexcept |
Construct a one-shot timer.
The duration of the timer can be specified when calling start_with_duration() when using this constructor.
|
explicitnoexcept |
Construct a one-shot timer with the specified duration.