2
3
6
7
8
9
10
11
13#include <so_5/impl/subscription_storage_iface.hpp>
19#include <so_5/details/rollback_on_exception.hpp>
28
29
30
31
32
37
38
39
40
41
42
43
44
53 const mbox_t & mbox_ref,
54 const std::type_index & type_index,
56 const state_t & target_state,
57 const event_handler_method_t & method,
64 const std::type_index & msg_type,
65 const state_t & target_state )
noexcept override;
70 const std::type_index & msg_type )
noexcept override;
78 const std::type_index & msg_type,
79 const state_t & current_state )
const noexcept override;
82 debug_dump( std::ostream & to )
const override;
107 std::type_index msg_type,
108 const state_t * state )
136
137
138
139
143
144
148
149
169 const mbox_id_t & mbox_id,
170 const std::type_index & msg_type,
171 const state_t & target_state ) ->
decltype( c.begin() )
173 return c.find(
typename C::key_type {
174 mbox_id, msg_type, &target_state } );
187 return m_id == k.m_mbox_id &&
m_type == k.m_msg_type;
191 template<
class M,
class IT >
197 it->first.m_mbox_id, it->first.m_msg_type };
199 if( it != s.begin() )
201 IT prev = std::prev( it );
202 if( predicate( prev->first ) )
206 IT next = std::next( it );
207 if( next != s.end() )
208 return predicate( next->first );
226 const std::type_index & msg_type,
228 const state_t & target_state,
229 const event_handler_method_t & method,
236 const auto mbox_id = mbox
->id();
239 auto existed_position =
find(
242 if( existed_position !=
m_events.end() )
245 "agent is already subscribed to message, " +
250 key_t { mbox_id
, msg_type
, &target_state
},
253 std::ref( message_sink ),
285 const std::type_index & msg_type,
286 const state_t & target_state )
noexcept
288 auto existed_position =
find(
290 if( existed_position !=
m_events.end() )
299 bool must_unsubscribe_mbox =
308 if( must_unsubscribe_mbox )
318 const std::type_index & msg_type )
noexcept
322 auto lower_bound =
m_events.lower_bound(
325 auto need_erase = [&] {
326 return lower_bound != std::end(
m_events) &&
327 is_same
( lower_bound->first
);
329 const bool events_found = need_erase();
342 while( need_erase() );
361 const std::type_index & msg_type,
362 const state_t & current_state )
const noexcept
417 subscr_info_vector_t result;
424 back_inserter( result ),
425 [](
const subscr_map_t::value_type & e )
449 transform( begin(info), end(info),
450 inserter( events, events.begin() ),
453 return subscr_map_t::value_type {
483 return impl::subscription_storage_unique_ptr_t(
virtual void unsubscribe_event_handler(const std::type_index &type_index, abstract_message_sink_t &subscriber) noexcept=0
Remove all message handlers.
virtual void subscribe_event_handler(const std::type_index &type_index, abstract_message_sink_t &subscriber)=0
Add the message handler.
virtual mbox_id_t id() const =0
Unique ID of this mbox.
Interface for message sink.
A map-based storage for agent's subscriptions information.
void debug_dump(std::ostream &to) const override
void drop_subscription_for_all_states(const mbox_t &mbox, const std::type_index &msg_type) noexcept override
const event_handler_data_t * find_handler(mbox_id_t mbox_id, const std::type_index &msg_type, const state_t ¤t_state) const noexcept override
void drop_all_subscriptions() noexcept override
Drop all subscriptions.
void drop_content() noexcept override
Drop all content.
void create_event_subscription(const mbox_t &mbox_ref, const std::type_index &type_index, abstract_message_sink_t &message_sink, const state_t &target_state, const event_handler_method_t &method, thread_safety_t thread_safety, event_handler_kind_t handler_kind) override
void setup_content(subscription_storage_common::subscr_info_vector_t &&info) override
Setup content from information from another storage object.
void destroy_all_subscriptions() noexcept
std::size_t query_subscriptions_count() const override
Count of subscriptions in the storage.
void drop_subscription(const mbox_t &mbox, const std::type_index &msg_type, const state_t &target_state) noexcept override
subscription_storage_common::subscr_info_vector_t query_content() const override
subscr_map_t m_events
Subscription information.
An interface of subscription storage.
T * operator->() const noexcept
std::string query_name() const
Get textual name of the state.
#define SO_5_THROW_EXCEPTION(error_code, desc)
Some reusable and low-level classes/functions which can be used in public header files.
auto do_with_rollback_on_exception(Main_Action main_action, Rollback_Action rollback_action) -> decltype(main_action())
Helper function for do some action with rollback in the case of an exception.
bool is_known_mbox_msg_pair(M &s, IT it)
auto find(C &c, const mbox_id_t &mbox_id, const std::type_index &msg_type, const state_t &target_state) -> decltype(c.begin())
A map-based storage for agent's subscriptions information.
Common stuff for various subscription storage implementations.
std::string make_subscription_description(const mbox_t &mbox_ref, std::type_index msg_type, const state_t &state)
A helper function for creating subscription description.
Details of SObjectizer run-time implementations.
Private part of message limit implementation.
thread_safety_t
Thread safety indicator.
SO_5_FUNC subscription_storage_factory_t map_based_subscription_storage_factory()
Factory for subscription storage based on std::map.
const int rc_evt_handler_already_provided
A handler for that event/mbox/state is already registered.
event_handler_kind_t
Kind of an event handler.
Information about event_handler and its properties.
thread_safety_t m_thread_safety
Is event handler thread safe or not.
event_handler_method_t m_method
Method for handling event.
event_handler_data_t(event_handler_method_t method, thread_safety_t thread_safety, event_handler_kind_t kind)
event_handler_kind_t m_kind
Kind of this event handler.
bool operator()(const K &k) const
const std::type_index & m_type
Type of key in subscription's map.
bool operator<(const key_t &o) const
std::type_index m_msg_type
key_t(mbox_id_t mbox_id, std::type_index msg_type, const state_t *state)
Type of value for subscription map's item.
const std::reference_wrapper< abstract_message_sink_t > m_message_sink
const mbox_t m_mbox
Reference to mbox.
const event_handler_data_t m_handler
An information about one subscription.
event_handler_data_t m_handler
std::reference_wrapper< abstract_message_sink_t > m_message_sink
Message sink used for subscription.
subscr_info_t(mbox_t mbox, std::type_index msg_type, abstract_message_sink_t &message_sink, const state_t &state, const event_handler_method_t &method, thread_safety_t thread_safety, event_handler_kind_t handler_kind)
mbox_t m_mbox
Reference to mbox.
std::type_index m_msg_type