15#include <egt/asio.hpp>
16#include <egt/detail/meta.h>
89 explicit
Timer(std::chrono::milliseconds duration) noexcept;
106 virtual
void start();
112 void start(std::chrono::milliseconds duration)
114 m_duration = duration;
155 EGT_NODISCARD std::chrono::milliseconds
duration()
const {
return m_duration; }
160 EGT_NODISCARD
bool running()
const {
return m_running; }
191 EGT_NODISCARD
const std::string&
name()
const {
return m_name; }
201 void name(
const std::string& name) { m_name =
name; }
225 : callback(std::move(c)),
229 TimerCallback callback;
230 RegisterHandle handle{0};
240 std::chrono::milliseconds m_duration{};
246 bool m_running{
false};
256 void internal_timer_callback(
const asio::error_code& error);
290 void internal_timer_callback(
const asio::error_code& error);
Periodic timer.
Definition timer.h:281
void start() override
Start the timer.
Basic one shot timer.
Definition timer.h:70
void cancel()
Cancel, or stop, the timer.
void clear_handlers()
Clear all handlers.
std::function< void()> TimerCallback
Timer callback function definition.
Definition timer.h:76
Timer() noexcept
Construct a one-shot timer.
std::unique_ptr< TimerImpl > m_impl
Definition timer.h:252
CallbackArray m_callbacks
Array of registered callbacks.
Definition timer.h:243
std::vector< CallbackMeta > CallbackArray
Type for array of registered callbacks.
Definition timer.h:234
void change_duration(std::chrono::milliseconds duration)
Change the duration of the timer.
uint64_t RegisterHandle
Handle type.
Definition timer.h:163
EGT_DEPRECATED void start_with_duration(std::chrono::milliseconds duration)
Start the timer with the specified duration.
EGT_NODISCARD const std::string & name() const
Get the name of the Timer.
Definition timer.h:191
void stop()
Alias for cancel().
Definition timer.h:141
EGT_NODISCARD bool running() const
Returns true if the timer is currently running.
Definition timer.h:160
asio::steady_timer m_timer
Asio timer object.
Definition timer.h:237
RegisterHandle on_timeout(TimerCallback callback)
Add a handler callback to be called with the timer times out.
void name(const std::string &name)
Set the name of the Timer.
Definition timer.h:201
void remove_handler(RegisterHandle handle)
Remove an event handler.
void timeout()
Called when the timer times out.
std::string m_name
A user defined name for the Timer.
Definition timer.h:249
void invoke_handlers()
Invoke any registered handlers.
virtual ~Timer() noexcept
EGT_NODISCARD std::chrono::milliseconds duration() const
Return the current duration of the timer.
Definition timer.h:155
EGT framework namespace.
Definition animation.h:24