9#include "plugin_base.h"
10#include "link_client.h"
11#include "rotor/error_code.h"
13#include <unordered_map>
17#pragma warning(disable : 4251)
20namespace rotor::plugin {
39 enum class phase_t { discovering, linking };
44 struct ROTOR_API discovery_task_t {
49 enum class state_t { PASSIVE, DISCOVERING, LINKING, OPERATIONAL, CANCELLING };
52 discovery_task_t &
link(
bool operational_only_ =
true) noexcept {
53 link_on_discovery =
true;
54 operational_only = operational_only_;
59 template <
typename Callback>
void callback(Callback &&cb)
noexcept {
60 task_callback = std::forward<Callback>(cb);
64 template <
typename T,
typename... Args>
auto access(Args... args)
noexcept;
67 discovery_task_t(registry_plugin_t &plugin_,
address_ptr_t *address_, std::string service_name_,
bool delayed_)
68 : plugin{&plugin_}, address(address_), service_name{service_name_}, delayed{delayed_},
70 operator bool() const noexcept {
return address; }
72 void do_discover() noexcept;
74 bool do_cancel() noexcept;
80 std::
string service_name;
84 callback_t task_callback;
85 bool link_on_discovery = false;
86 bool operational_only = false;
94 const std::type_index &
identity() const noexcept override;
125 bool delayed = false) noexcept;
131 template <typename T> auto &
access() noexcept;
137 enum class state_t { REGISTERING, LINKING, OPERATIONAL, UNREGISTERING };
138 struct register_info_t {
142 using register_map_t = std::unordered_map<std::string, register_info_t>;
143 using names_t = std::vector<std::string>;
144 using aliases_map_t = std::unordered_map<address_ptr_t, names_t>;
146 enum plugin_state_t : std::uint32_t {
151 std::uint32_t plugin_state = 0;
153 register_map_t register_map;
154 discovery_map_t discovery_map;
155 aliases_map_t aliases_map;
157 void link_registry() noexcept;
158 void on_link(const extended_error_ptr_t &ec) noexcept;
159 bool has_registering() noexcept;
160 virtual
void continue_init(const error_code_t &possible_ec, const extended_error_ptr_t &root_ec) noexcept;
namespace for rotor core messages (which just transform payloads)
Definition messages.hpp:317
intrusive_ptr_t< extended_error_t > extended_error_ptr_t
intrusive pointer to extended error type
Definition extended_error.h:25
state_t
state of actor in rotor
Definition state.h:12
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
universal primitive of concurrent computation
Definition actor_base.h:47
plugin_base_t()=default
default plugin ctor
actor_base_t * actor
non-owning actor pointer
Definition plugin_base.h:179
helper class to invoke callback upon address discovery
Definition registry.h:44
void callback(Callback &&cb) noexcept
discovery progress callback setter
Definition registry.h:59
state_t
stat of the discovery task
Definition registry.h:49
discovery_task_t & link(bool operational_only_=true) noexcept
sets that linking should be performed on operational-only discovered address
Definition registry.h:52
std::function< void(phase_t phase, const extended_error_ptr_t &)> callback_t
callback for the discovery progress
Definition registry.h:46
auto access(Args... args) noexcept
generic non-public methods accessor
handy access to registry_t, for name registration and discovery
Definition registry.h:35
static const std::type_index class_identity
Definition registry.h:92
const std::type_index & identity() const noexcept override
returns pointer, which uniquely identifiess plugin type
auto & access() noexcept
generic non-public fields accessor
void activate(actor_base_t *actor) noexcept override
invoked by actor upon initialization.
phase_t
phase for each discovery task: discovering or linking
Definition registry.h:39
std::unordered_map< std::string, discovery_task_t > discovery_map_t
service name to task mapping
Definition registry.h:134
plugin_base_t()=default
default plugin ctor
virtual void on_future(message::discovery_future_t &message) noexcept
reaction on discovery future
virtual void on_registration(message::registration_response_t &) noexcept
reaction on registration response
virtual void register_name(const std::string &name, const address_ptr_t &address) noexcept
enqueues name/address registration
bool handle_init(message::init_request_t *message) noexcept override
polls plugin, whether it is done with initialization
virtual void on_discovery(message::discovery_response_t &) noexcept
reaction on discovery response
bool handle_shutdown(message::shutdown_request_t *message) noexcept override
polls plugin, whether it is done with shutdown
virtual discovery_task_t & discover_name(const std::string &name, address_ptr_t &address, bool delayed=false) noexcept
creates name discovery task