rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
subscription.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 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 "rotor/subscription_point.h"
12#include "rotor/message.h"
13#include <boost/unordered_map.hpp>
14#include <vector>
15
16#if defined(_MSC_VER)
17#pragma warning(push)
18#pragma warning(disable : 4251)
19#endif
20
21namespace rotor {
22
30struct ROTOR_API subscription_t {
32 using message_type_t = const void *;
33
35 using handlers_t = std::vector<handler_base_t *>;
36
46
47 subscription_t() noexcept;
48
56 subscription_info_ptr_t materialize(const subscription_point_t &point) noexcept;
57
59 void update(subscription_point_t &point, handler_ptr_t &new_handler) noexcept;
60
62 void forget(const subscription_info_ptr_t &info) noexcept;
63
65 const joint_handlers_t *get_recipients(const message_base_t &message) const noexcept;
66
68 template <typename T> auto &access() noexcept;
69
70 private:
71 struct subscription_key_t {
72 address_t *address;
73 message_type_t message_type;
74 inline bool operator==(const subscription_key_t &other) const noexcept {
75 return address == other.address && message_type == other.message_type;
76 }
77 };
78
79 struct subscription_key_hash_t {
80 inline std::size_t operator()(const subscription_key_t &k) const noexcept {
81 return std::size_t(k.address) + 0x9e3779b9 + (size_t(k.message_type) << 6) + (size_t(k.message_type) >> 2);
82 }
83 };
84
85 using addressed_handlers_t = boost::unordered_map<subscription_key_t, joint_handlers_t, subscription_key_hash_t>;
86
87 using info_container_t = boost::unordered_map<address_ptr_t, std::vector<subscription_info_ptr_t>>;
88 address_t *main_address;
89 info_container_t internal_infos;
90 addressed_handlers_t mine_handlers;
91};
92
93} // namespace rotor
94
95#if defined(_MSC_VER)
96#pragma warning(pop)
97#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
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
Message subscription and delivery point.
Definition address.hpp:33
Base class for rotor message.
Definition message.h:52
pair of handler_base_t linked to particular address_t
Definition subscription_point.h:50
pair internal and external handler_t
Definition subscription.h:40
handlers_t internal
internal handlers, i.e. those which belong to actors of the supervisor
Definition subscription.h:42
handlers_t external
external handlers, i.e. those which belong to actors of other supervisor
Definition subscription.h:44
Holds and classifies message handlers on behalf of supervisor.
Definition subscription.h:30
std::vector< handler_base_t * > handlers_t
vector of handler pointers
Definition subscription.h:35
const void * message_type_t
alias for message type (i.e. stringized typeid)
Definition subscription.h:32