rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
subscription_point.h
1#pragma once
2
3//
4// Copyright (c) 2019-2025 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 <list>
12
13#if defined(_MSC_VER)
14#pragma warning(push)
15#pragma warning(disable : 4251)
16#endif
17
18namespace rotor {
19
20struct actor_base_t;
21
22namespace tags {
23
24ROTOR_API extern const void *io;
25
26}
27
39enum class owner_tag_t {
40 ANONYMOUS,
41 PLUGIN,
42 SUPERVISOR,
43 FOREIGN,
44};
45
49struct ROTOR_API subscription_point_t {
52
55
58
61
63 subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_) noexcept
64 : handler{handler_}, address{address_}, owner_ptr{nullptr}, owner_tag{owner_tag_t::ANONYMOUS} {}
65
67 subscription_point_t(const handler_ptr_t &handler_, const address_ptr_t &address_, const actor_base_t *owner_ptr_,
68 owner_tag_t owner_tag_) noexcept
69 : handler{handler_}, address{address_}, owner_ptr{owner_ptr_}, owner_tag{owner_tag_} {}
70
73
76
78 bool operator==(const subscription_point_t &other) const;
79};
80
84struct ROTOR_API subscription_info_t : public arc_base_t<subscription_info_t>, subscription_point_t {
86 enum state_t { SUBSCRIBING, ESTABLISHED, UNSUBSCRIBING };
87
89 subscription_info_t(const subscription_point_t &point, bool internal_address_, bool internal_handler_,
90 state_t state_) noexcept
91 : subscription_point_t{point}, internal_address{internal_address_}, internal_handler{internal_handler_},
92 state{state_} {}
93
99 inline void tag_io() noexcept { tag(tags::io); }
100
102 template <typename T> auto &access() noexcept;
103
105 template <typename T, typename... Args> auto access(Args... args) noexcept;
106
107 private:
108 void tag(const void *t) noexcept;
109
111 bool internal_address;
112
114 bool internal_handler;
115
117 state_t state;
118};
119
122
126struct ROTOR_API subscription_container_t : public std::list<subscription_info_ptr_t> {
128 iterator find(const subscription_point_t &point) noexcept;
129};
130
131} // namespace rotor
132
133#if defined(_MSC_VER)
134#pragma warning(pop)
135#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:39
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:121
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:126
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:84
void tag_io() noexcept
marks handler for blocking operations
Definition subscription_point.h:99
state_t
subscription info state (subscribing, established, unsubscribing
Definition subscription_point.h:86
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:89
pair of handler_base_t linked to particular address_t
Definition subscription_point.h:49
bool operator==(const subscription_point_t &other) const
partial comparison by handler and address
const actor_base_t * owner_ptr
non-owning pointer to an actor, which performs subscription
Definition subscription_point.h:57
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:63
owner_tag_t owner_tag
kind of ownership of the subscription point
Definition subscription_point.h:60
address_ptr_t address
intrusive pointer to address
Definition subscription_point.h:54
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:67
subscription_point_t(subscription_point_t &&)=default
move-ctor
handler_ptr_t handler
intrusive pointer to messages' handler
Definition subscription_point.h:51
subscription_point_t(const subscription_point_t &)=default
copy-ctor