rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
link_server.h
1#pragma once
2
3//
4// Copyright (c) 2019-2023 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "plugin_base.h"
10#include <string>
11#include <unordered_set>
12#include <functional>
13#include <optional>
14
15#if defined(_MSC_VER)
16#pragma warning(push)
17#pragma warning(disable : 4251)
18#endif
19
20namespace rotor::plugin {
21
32struct ROTOR_API link_server_plugin_t : public plugin_base_t {
33 using plugin_base_t::plugin_base_t;
34
36 static const std::type_index class_identity;
37
38 const std::type_index &identity() const noexcept override;
39
40 void activate(actor_base_t *actor) noexcept override;
41
43 virtual void on_link_request(message::link_request_t &message) noexcept;
44
46 virtual void on_unlink_response(message::unlink_response_t &message) noexcept;
47
49 virtual void on_unlink_notify(message::unlink_notify_t &message) noexcept;
50
51 bool handle_shutdown(message::shutdown_request_t *message) noexcept override;
52 void handle_start(message::start_trigger_t *message) noexcept override;
53
55 virtual bool has_clients() noexcept { return !linked_clients.empty(); }
56
58 virtual void notify_shutdown() noexcept;
59
61 template <typename T> auto &access() noexcept;
62
63 private:
64 enum class link_state_t { PENDING, OPERATIONAL, UNLINKING };
65 using link_request_ptr_t = intrusive_ptr_t<message::link_request_t>;
66 using request_option_t = std::optional<request_id_t>;
67 struct link_info_t {
68 link_info_t(link_state_t state_, link_request_ptr_t request_) noexcept : state{state_}, request{request_} {}
69 link_state_t state;
70 link_request_ptr_t request;
71 request_option_t unlink_request;
72 bool shutdown_notified = false;
73 };
74
75 using linked_clients_t = std::unordered_map<address_ptr_t, link_info_t>;
76 linked_clients_t linked_clients;
77};
78
79} // namespace rotor::plugin
80
81#if defined(_MSC_VER)
82#pragma warning(pop)
83#endif
boost::intrusive_ptr< T > intrusive_ptr_t
alias for intrusive pointer
Definition arc.hpp:27
universal primitive of concurrent computation
Definition actor_base.h:47
base class for all actor plugins
Definition plugin_base.h:23