class ugcs::vsm::Timer_processor¶
Overview¶
Timer processor manages all timers in the VSM. More…
#include <timer_processor.h> class Timer_processor: public ugcs::vsm::Request_context { public: // typedefs typedef std::shared_ptr<Timer_processor> Ptr; typedef std::weak_ptr<Timer_processor> Weak_ptr; typedef Callback_proxy<bool> Handler; // classes class Timer; // methods template <typename... Args> static Ptr Create(Args&&... args); template <typename... Args> static Ptr Get_instance(Args&&... args); Timer::Ptr Create_timer(std::chrono::milliseconds interval, const Handler& handler, Request_container::Ptr container); void Cancel_timer(Timer::Ptr timer); };
Inherited Members¶
public: // typedefs typedef std::shared_ptr<Request_container> Ptr; typedef std::weak_ptr<Request_container> Weak_ptr; typedef std::shared_ptr<Request_context> Ptr; typedef std::weak_ptr<Request_context> Weak_ptr; // enums enum Type; // classes class Request; class Request_waiter; // methods template <typename... Args> static Ptr Create(Args&&... args); virtual Type Get_type() const; bool Check_type(Type mask); void Submit_request(Request::Ptr request); void Submit_request_locked(Request::Ptr request, Request_waiter::Locker locker); int Process_requests(int requests_limit = 0); int Process_requests(std::unique_lock<std::mutex>& lock, int requests_limit = 0); void Set_waiter(Request_waiter::Ptr waiter); Request_waiter::Ptr Get_waiter() const; const std::string& Get_name(); void Enable(); void Disable(); bool Is_enabled() const; template <typename... Args> static Ptr Create(Args&&... args); virtual Type Get_type() const; Request_container(const std::string& name, Request_waiter::Ptr waiter = Request_waiter::Create());
Detailed Documentation¶
Timer processor manages all timers in the VSM.
Typedefs¶
typedef std::shared_ptr<Timer_processor> Ptr
Pointer type.
typedef std::weak_ptr<Timer_processor> Weak_ptr
Pointer type.
typedef Callback_proxy<bool> Handler
Timer handler.
It should return boolean value with the following meanings: false - stop the timer, i.e. do not perform further invocations; true - re-schedule next invocation after the initial interval.
Methods¶
template <typename... Args> static Ptr Create(Args&&... args)
Create an instance.
template <typename... Args> static Ptr Get_instance(Args&&... args)
Get global or create new processor instance.
Timer::Ptr Create_timer(std::chrono::milliseconds interval, const Handler& handler, Request_container::Ptr container)
Create and schedule the timer instance.
First time it is fired after the specified interval (since the creation moment). Is it periodic or one-shot is defined by the provided handler - while it is returning “true” the timer is re-scheduled with the same interval.
Parameters:
interval |
Timer interval. |
handler |
Handler to invoke, should be non-empty. See Handler. |
container |
Container where the handler will be executed. |
Invalid_param_exception |
if Handler or container is not set. |
Returns:
Timer object which can be used, for example, to cancel running timer.
void Cancel_timer(Timer::Ptr timer)
Cancel the specified timer in case it is running.