151 uint16_t priority = 0);
314 void wait_for_idle();
318 void force_to_start();
320 void set_remain_loop_count(int32_t loop_count)
const;
322 void sub_remain_loop_count()
const;
324 void set_invoke_count(uint64_t invoke_count)
const;
326 uint64_t get_start_time()
const;
328 bool is_once_type()
const;
330 bool has_callback()
const;
335 std::unique_ptr<struct TimerImpl> impl_;
336 static constexpr uint32_t kMinInterval{10'000U};
Event-loop-driven repeating or one-shot timer.
Definition timer.h:81
~Timer()
Destructor. Stops the timer and detaches it from the loop.
static bool call_once(class MessageLoop *message_loop, uint32_t interval_ms, Callback &&callback, uint16_t priority=0)
Posts a one-shot timer to a MessageLoop without creating a Timer object.
int32_t get_loop_count() const
Returns the configured total loop count.
Timer()
Constructs a detached timer with no message loop, interval or callback.
uint64_t get_invoke_count() const
Returns the total number of times the callback has been invoked since start().
void set_interval(uint32_t interval_ms)
Changes the tick interval.
std::function< void()> Callback
Callback type invoked on each timer tick.
Definition timer.h:86
Timer(uint32_t interval_ms, int32_t loop_count=kInfinite, Callback &&callback=nullptr)
Constructs a timer without attaching it to a loop.
class MessageLoop * get_message_loop() const
Returns the MessageLoop this timer is attached to.
uint32_t get_interval() const
Returns the current tick interval in milliseconds.
bool attach(class MessageLoop *message_loop)
Attaches the timer to a MessageLoop.
bool detach()
Detaches the timer from its MessageLoop without stopping it.
friend class MessageLoop
Definition timer.h:334
uint16_t get_priority() const
Returns the task dispatch priority.
bool is_strict() const
Returns true if strict mode is enabled.
void start(Callback &&callback=nullptr)
Arms and starts the timer.
bool is_active() const
Returns true if the timer is currently running (armed and has remaining ticks).
Timer(class MessageLoop *message_loop, uint32_t interval_ms, int32_t loop_count=kInfinite, Callback &&callback=nullptr)
Constructs and fully configures a timer attached to a loop.
void restart()
Resets the countdown to zero and continues firing.
void set_priority(uint16_t priority)
Sets the dispatch priority for the timer task.
void set_loop_count(int32_t loop_count)
Changes the total number of ticks.
Timer(class MessageLoop *message_loop)
Constructs a timer attached to message_loop with no interval or callback yet.
static constexpr int kInfinite
Sentinel loop count meaning repeat indefinitely.
Definition timer.h:91
void stop()
Disarms the timer without destroying it.
void set_callback(Callback &&callback)
Replaces the callback invoked on each tick.
int32_t get_remain_loop_count() const
Returns the number of remaining ticks before the timer stops automatically.
void set_strict(bool strict)
Enables or disables strict (catch-up) firing mode.
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT
Definition macros.h:85
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition macros.h:184