11 #ifndef _UGCS_VSM_TIMER_PROCESSOR_H_
12 #define _UGCS_VSM_TIMER_PROCESSOR_H_
28 template <typename... Args>
32 return singleton.Get_instance(std::forward<Args>(args)...);
45 class Timer:
public std::enable_shared_from_this<Timer> {
51 std::chrono::milliseconds interval);
64 std::chrono::steady_clock::time_point
76 bool is_running =
true;
78 std::chrono::milliseconds interval;
80 std::chrono::steady_clock::time_point fire_time;
84 mutable std::mutex mutex;
86 std::list<Ptr> attached_timers;
102 Destroy(
bool cancel =
false);
110 Attach(std::list<Ptr> &&timers);
143 typedef decltype(std::chrono::milliseconds().count()) Tick_type;
148 std::map<Tick_type, Timer::
Ptr> tree;
150 std::mutex tree_lock;
156 On_enable() override;
160 On_disable() override;
164 On_wait_and_process() override;
168 Timer_process_handler(Timer::
Ptr timer);
172 Timer_handler(Timer::
Ptr timer,
Handler handler,
177 Insert_timer(Timer::
Ptr &timer);
181 Get_ticks(const std::chrono::steady_clock::time_point &time);
185 Create_request(Timer::
Ptr &timer, const
Handler &handler,
Singleton class definition.
void Cancel_timer(Timer::Ptr timer)
Cancel the specified timer in case it is running.
Timer processor manages all timers in the VSM.
Definition: timer_processor.h:23
std::shared_ptr< Timer_processor > Ptr
Pointer type.
Definition: timer_processor.h:24
std::chrono::steady_clock::time_point Get_fire_time() const
Get time of next timer firing.
Definition: timer_processor.h:65
Timer::Ptr Create_timer(std::chrono::milliseconds interval, const Handler &handler, Request_container::Ptr container)
Create and schedule the timer instance.
std::shared_ptr< Request > Ptr
Pointer type.
Definition: request_container.h:38
Request execution context.
Request execution context.
Definition: request_context.h:24
Callback_proxy< bool > Handler
Timer handler.
Definition: timer_processor.h:42
Helper class for proxying callback invocation.
Definition: callback.h:699
static Ptr Get_instance(Args &&...args)
Get global or create new processor instance.
Definition: timer_processor.h:30
Represents timer instance.
Definition: timer_processor.h:45
std::shared_ptr< Request_container > Ptr
Pointer type.
Definition: request_container.h:31
Generic container for queued requests.
Definition: request_container.h:30
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
std::shared_ptr< Timer > Ptr
Pointer type.
Definition: timer_processor.h:46
void Cancel()
Cancel running timer.
bool Is_running() const
Check if the timer still is running - i.e.
Helper class for implementing singletons.
Definition: singleton.h:69