rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
supervisor_ev.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "rotor/supervisor.h"
10#include "rotor/ev/export.h"
11#include "rotor/ev/supervisor_config_ev.h"
12#include "rotor/ev/system_context_ev.h"
13#include "rotor/system_context.h"
14#include <ev.h>
15#include <memory>
16#include <unordered_map>
17
18namespace rotor {
19namespace ev {
20
35struct ROTOR_EV_API supervisor_ev_t : public supervisor_t {
38
40 template <typename Supervisor> using config_builder_t = supervisor_config_ev_builder_t<Supervisor>;
41
56
58 using timer_ptr_t = std::unique_ptr<timer_t>;
59
62 virtual void do_initialize(system_context_t *ctx) noexcept override;
64
65 void start() noexcept override;
66 void shutdown() noexcept override;
67 void enqueue(message_ptr_t message) noexcept override;
68 void shutdown_finish() noexcept override;
69
71 inline struct ev_loop *get_loop() noexcept { return loop; }
72
74 template <typename T> auto &access() noexcept;
75
76 protected:
78 using timers_map_t = std::unordered_map<request_id_t, timer_ptr_t>;
79
81 static void async_cb(EV_P_ ev_async *w, int revents) noexcept;
82
83 void do_start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept override;
84 void do_cancel_timer(request_id_t timer_id) noexcept override;
85
93 virtual void on_async() noexcept;
94
96 struct ev_loop *loop;
97
99 bool loop_ownership;
100
102 ev_async async_watcher;
103
105 ev_tstamp poll_duration;
106
108 timers_map_t timers_map;
109
110 friend struct supervisor_ev_shutdown_t;
111
112 private:
113 void move_inbound_queue() noexcept;
114};
115
116} // namespace ev
117} // namespace rotor
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< message_base_t > message_ptr_t
intrusive pointer for message
Definition message.h:118
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
boost::intrusive_ptr< T > intrusive_ptr_t
alias for intrusive pointer
Definition arc.hpp:27
CRTP supervisor ev config builder.
Definition supervisor_config_ev.h:30
libev supervisor config, which holds a pointer to the ev event loop and a loop ownership flag
Definition supervisor_config_ev.h:19
inheritance of ev_timer, which holds rotor timer_id
Definition supervisor_ev.h:45
supervisor_ptr_t sup
intrusive pointer to the supervisor
Definition supervisor_ev.h:54
intrusive_ptr_t< supervisor_ev_t > supervisor_ptr_t
intrusive pointer to ev supervisor (type)
Definition supervisor_ev.h:48
timer_handler_base_t * handler
non-owning pointer to timer handler
Definition supervisor_ev.h:51
delivers rotor-messages on top of libev event loop
Definition supervisor_ev.h:35
supervisor_ev_t(supervisor_config_ev_t &config)
constructs new supervisor from ev supervisor config
std::unordered_map< request_id_t, timer_ptr_t > timers_map_t
a type for mapping timer_id to timer pointer
Definition supervisor_ev.h:78
void start() noexcept override
thread-safe version of do_process
auto & access() noexcept
generic non-public fields accessor
virtual void do_initialize(system_context_t *ctx) noexcept override
early actor initialization (pre-initialization)
std::unique_ptr< timer_t > timer_ptr_t
an alias for unique pointer, holding timer_t
Definition supervisor_ev.h:58
supervisor is responsible for managing actors (workers) lifetime
Definition supervisor.h:69
The system context holds root supervisor_t (intrusive pointer) and may be loop-related details in der...
Definition system_context.h:32
Base class for timer handler.
Definition timer_handler.hpp:17