rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
subscription_point.h
1#pragma once
2
3//
4// Copyright (c) 2019-2021 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "rotor/forward.hpp"
10#include "rotor/address.hpp"
11#include <vector>
12#include <list>
13
14#if defined(_MSC_VER)
15#pragma warning(push)
16#pragma warning(disable : 4251)
17#endif
18
19namespace rotor {
20
21struct actor_base_t;
22
23namespace tags {
24
25ROTOR_API extern const void *io;
26
27}
28
40enum class owner_tag_t {
41 ANONYMOUS,
42 PLUGIN,
43 SUPERVISOR,
44 FOREIGN,
45};
46
50struct ROTOR_API subscription_point_t {
53
56
59
62
64 subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_) noexcept
65 : handler{handler_}, address{address_}, owner_ptr{nullptr}, owner_tag{owner_tag_t::ANONYMOUS} {}
66
68 subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_, const actor_base_t *owner_ptr_,
69 owner_tag_t owner_tag_) noexcept
70 : handler{handler_}, address{address_}, owner_ptr{owner_ptr_}, owner_tag{owner_tag_} {}
71
74
77
79 bool operator==(const subscription_point_t &other) const noexcept;
80};
81
85struct ROTOR_API subscription_info_t : public arc_base_t<subscription_info_t>, subscription_point_t {
87 enum state_t { SUBSCRIBING, ESTABLISHED, UNSUBSCRIBING };
88
90 subscription_info_t(const subscription_point_t &point, bool internal_address_, bool internal_handler_,
91 state_t state_) noexcept
92 : subscription_point_t{point}, internal_address{internal_address_}, internal_handler{internal_handler_},
93 state{state_} {}
94
96 inline bool operator==(const subscription_point_t &point) const noexcept {
97 return (subscription_point_t &)(*this) == point;
98 }
99
105 inline void tag_io() noexcept { tag(tags::io); }
106
108 template <typename T> auto &access() noexcept;
109
111 template <typename T, typename... Args> auto access(Args... args) noexcept;
112
113 private:
114 void tag(const void *t) noexcept;
115
117 bool internal_address;
118
120 bool internal_handler;
121
123 state_t state;
124};
125
128
132struct ROTOR_API subscription_container_t : public std::list<subscription_info_ptr_t> {
134 iterator find(const subscription_point_t &point) noexcept;
135};
136
137} // namespace rotor
138
139#if defined(_MSC_VER)
140#pragma warning(pop)
141#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
owner_tag_t
who owns the subscription point
Definition subscription_point.h:40
boost::intrusive_ref_counter< T, counter_policy_t > arc_base_t
base class to inject ref-counter with the specified policy
Definition arc.hpp:24
intrusive_ptr_t< handler_base_t > handler_ptr_t
intrusive pointer for handler
Definition forward.hpp:26
intrusive_ptr_t< subscription_info_t > subscription_info_ptr_t
intrusive pointer for subscription_info_t
Definition subscription_point.h:127
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
list of subscription_info_ptr_t with possibility to find via subscription_point_t
Definition subscription_point.h:132
iterator find(const subscription_point_t &point) noexcept
looks up for the subscription info pointer (returned as iterator) via the subscription point
subscription_point_t with extended information (e.g. state)
Definition subscription_point.h:85
bool operator==(const subscription_point_t &point) const noexcept
uses subscription_point_t comparison
Definition subscription_point.h:96
void tag_io() noexcept
marks handler for blocking operations
Definition subscription_point.h:105
state_t
subscription info state (subscribing, established, unsubscribing
Definition subscription_point.h:87
auto & access() noexcept
generic non-public fields accessor
subscription_info_t(const subscription_point_t &point, bool internal_address_, bool internal_handler_, state_t state_) noexcept
ctor from subscription point, internal address and internal handler and state
Definition subscription_point.h:90
pair of handler_base_t linked to particular address_t
Definition subscription_point.h:50
const actor_base_t * owner_ptr
non-owning pointer to an actor, which performs subscription
Definition subscription_point.h:58
subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_) noexcept
ctor from handler and related address (used for comparison)
Definition subscription_point.h:64
owner_tag_t owner_tag
kind of ownership of the subscription point
Definition subscription_point.h:61
bool operator==(const subscription_point_t &other) const noexcept
partial comparison by handler and address
address_ptr_t address
intrusive pointer to address
Definition subscription_point.h:55
subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_, const actor_base_t *owner_ptr_, owner_tag_t owner_tag_) noexcept
full ctor (handler, address, actor, and owner tag)
Definition subscription_point.h:68
subscription_point_t(subscription_point_t &&)=default
move-ctor
handler_ptr_t handler
intrusive pointer to messages' handler
Definition subscription_point.h:52
subscription_point_t(const subscription_point_t &)=default
copy-ctor