123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #pragma once
- #include "rotor/supervisor.h"
- #include "rotor/asio/export.h"
- #include "supervisor_config_asio.h"
- #include "system_context_asio.h"
- #include "forwarder.hpp"
- #include <boost/asio.hpp>
- #include <unordered_map>
- #include <memory>
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4251)
- #endif
- namespace rotor {
- namespace asio {
- namespace asio = boost::asio;
- namespace sys = boost::system;
- template <typename Actor, typename Handler, typename ArgsCount, typename ErrHandler> struct forwarder_t;
- struct ROTOR_ASIO_API supervisor_asio_t : public supervisor_t {
-
- using config_t = supervisor_config_asio_t;
-
- template <typename Supervisor> using config_builder_t = supervisor_config_asio_builder_t<Supervisor>;
-
- supervisor_asio_t(supervisor_config_asio_t &config);
- virtual address_ptr_t make_address() noexcept override;
- virtual void start() noexcept override;
- virtual void shutdown() noexcept override;
- virtual void enqueue(message_ptr_t message) noexcept override;
- virtual void shutdown_finish() noexcept override;
-
- template <typename Handler, typename ErrHandler>
- auto create_forwarder(Handler &&handler, ErrHandler &&err_handler) {
- return forwarder_t{*this, std::move(handler), std::move(err_handler)};
- }
-
- template <typename Handler> auto create_forwarder(Handler &&handler) {
- return forwarder_t{*this, std::move(handler)};
- }
-
- inline asio::io_context::strand &get_strand() noexcept { return *strand; }
-
- void do_process() noexcept;
- protected:
-
- struct timer_t : public asio::deadline_timer {
-
- timer_handler_base_t *handler;
-
- timer_t(timer_handler_base_t *handler_, asio::io_context &io_context)
- : asio::deadline_timer(io_context), handler{handler_} {}
- };
-
- using timer_ptr_t = std::unique_ptr<timer_t>;
-
- using timers_map_t = std::unordered_map<request_id_t, timer_ptr_t>;
- void do_start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept override;
- void do_cancel_timer(request_id_t timer_id) noexcept override;
-
- using guard_t = asio::executor_work_guard<asio::io_context::executor_type>;
-
- using guard_ptr_t = std::unique_ptr<guard_t>;
-
- timers_map_t timers_map;
-
- supervisor_config_asio_t::strand_ptr_t strand;
-
- guard_ptr_t guard;
- private:
- void invoke_shutdown() noexcept;
- };
- template <typename Actor> inline boost::asio::io_context::strand &get_strand(Actor &actor) {
- return actor.get_strand();
- }
- }
- }
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
|