rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
timer_handler.hpp
1#pragma once
2
3//
4// Copyright (c) 2019-2020 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "forward.hpp"
10#include <memory>
11
12namespace rotor {
13
18
21
24
26 timer_handler_base_t(actor_base_t *owner_, request_id_t request_id_) noexcept
27 : owner{owner_}, request_id{request_id_} {}
28
30 virtual void trigger(bool cancelled) noexcept = 0;
31
32 virtual ~timer_handler_base_t() = default;
33};
34
36using timer_handler_ptr_t = std::unique_ptr<timer_handler_base_t>;
37
42template <typename Object, typename Method> struct timer_handler_t : timer_handler_base_t {
44 Object *object;
45
47 Method method;
48
51 timer_handler_t(actor_base_t *owner_, request_id_t request_id_, Object *object_, Method method_) noexcept
52 : timer_handler_base_t{owner_, request_id_}, object{object_}, method{std::forward<Method>(method_)} {}
53
54 void trigger(bool cancelled) noexcept override { std::invoke(method, object, request_id, cancelled); }
55};
56
57} // namespace rotor
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
std::unique_ptr< timer_handler_base_t > timer_handler_ptr_t
alias for timer smart pointer
Definition timer_handler.hpp:36
universal primitive of concurrent computation
Definition actor_base.h:47
Base class for timer handler.
Definition timer_handler.hpp:17
actor_base_t * owner
actor, which "owns" timer, i.e. where "start_timer" was invoked"
Definition timer_handler.hpp:20
request_id_t request_id
timer identity (aka timer request id)
Definition timer_handler.hpp:23
timer_handler_base_t(actor_base_t *owner_, request_id_t request_id_) noexcept
constructs timer handler from non-owning pointer to timer and timer request id
Definition timer_handler.hpp:26
virtual void trigger(bool cancelled) noexcept=0
an action when timer was triggered or cancelled
templated implementation of timer handler
Definition timer_handler.hpp:42
timer_handler_t(actor_base_t *owner_, request_id_t request_id_, Object *object_, Method method_) noexcept
constructs timer handler from non-owning pointer to timer, timer request id, delegate and callback (o...
Definition timer_handler.hpp:51
void trigger(bool cancelled) noexcept override
an action when timer was triggered or cancelled
Definition timer_handler.hpp:54
Method method
timer callback
Definition timer_handler.hpp:47
Object * object
delegate object, i.e. that one on which the callback (method) will be invoked
Definition timer_handler.hpp:44