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
45
46
47
48
53 std::size_t initial_capacity );
58 const mbox_t & mbox_ref,
59 const std::type_index & type_index,
61 const state_t & target_state,
62 const event_handler_method_t & method,
69 const std::type_index & msg_type,
70 const state_t & target_state )
noexcept override;
75 const std::type_index & msg_type )
noexcept override;
83 const std::type_index & msg_type,
84 const state_t & current_state )
const noexcept override;
87 debug_dump( std::ostream & to )
const override;
104 using subscr_info_vector_t =
131 template<
class Container >
134 const mbox_id_t & mbox_id,
135 const std::type_index & msg_type,
136 const state_t & target_state ) ->
decltype( c.begin() )
140 return find_if( begin( c ), end( c ),
141 [&](
typename Container::value_type
const & o ) {
142 return ( o.m_mbox->id() == mbox_id &&
143 o.m_msg_type == msg_type &&
144 o.m_state == &target_state );
151 std::size_t initial_capacity )
153 m_events.reserve( initial_capacity );
164 const std::type_index & msg_type,
166 const state_t & target_state,
167 const event_handler_method_t & method,
174 const auto mbox_id = mbox
->id();
177 bool has_subscriptions_from_that_mbox =
false;
184 has_subscriptions_from_that_mbox =
true;
185 if( it->
m_state == std::addressof(target_state) )
188 "agent is already subscribed to message, " +
211 if( !has_subscriptions_from_that_mbox )
229 const std::type_index & msg_type,
230 const state_t & target_state )
noexcept
234 const auto mbox_id = mbox
->id();
238 std::size_t number_of_subscriptions{};
239 subscr_info_vector_t::iterator it =
m_events.begin();
240 subscr_info_vector_t::iterator it_end =
m_events.end();
242 for(; it != it_end; ++it )
247 ++number_of_subscriptions;
248 if( it->
m_state == std::addressof(target_state) )
260 --number_of_subscriptions;
268 if( !number_of_subscriptions )
273 number_of_subscriptions = 1;
278 if( !number_of_subscriptions )
291 const std::type_index & msg_type )
noexcept
307 remove_if( it, end(
m_events ), predicate ),
326 const std::type_index & msg_type,
327 const state_t & current_state )
const noexcept
361 [](
const auto & a,
const auto & b )
363 return a.m_mbox->id() < b.m_mbox->id() ||
364 ( a.m_mbox->id() == b.m_mbox->id() &&
365 a.m_msg_type < b.m_msg_type );
371 const auto total_items =
m_events.size();
372 for( std::size_t i = 0u; i < total_items; )
374 auto & current_info =
m_events[ i ];
382 for( ; (i+j) < total_items; ++j )
384 const auto & next_info =
m_events[ i+j ];
430 std::size_t initial_capacity )
432 return [initial_capacity]() {
433 return impl::subscription_storage_unique_ptr_t(
435 initial_capacity
) );
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.
An interface of subscription storage.
A vector-based storage for agent's subscriptions information.
void drop_all_subscriptions() noexcept override
Drop all subscriptions.
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
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
subscription_storage_common::subscr_info_vector_t query_content() const override
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
virtual 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
storage_t(std::size_t initial_capacity)
subscr_info_vector_t m_events
Subscription information.
void drop_content() noexcept override
Drop all content.
std::size_t query_subscriptions_count() const override
Count of subscriptions in the storage.
virtual void drop_subscription(const mbox_t &mbox, const std::type_index &msg_type, const state_t &target_state) noexcept override
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.
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.
auto find(Container &c, const mbox_id_t &mbox_id, const std::type_index &msg_type, const state_t &target_state) -> decltype(c.begin())
A vector-based storage for agent's subscriptions information.
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 vector_based_subscription_storage_factory(std::size_t initial_capacity)
Factory for subscription storage based on unsorted std::vector.
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.
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.
mbox_t m_mbox
Reference to mbox.
std::type_index m_msg_type
const std::type_index & m_type
bool operator()(const info_t &info) const