SObjectizer
5.7
|
A class for creating a subscription to messages from the mbox. More...
#include <agent.hpp>
Public Member Functions | |
subscription_bind_t (agent_t &agent, const mbox_t &mbox_ref) | |
subscription_bind_t & | in (const state_t &state) |
Set up a state in which events are allowed be processed. More... | |
template<typename Method_Pointer > | |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t &>::type | event (Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe) |
Make subscription to the message. More... | |
template<class Lambda > | |
std::enable_if< details::lambda_traits::is_lambda< Lambda >::value, subscription_bind_t &>::type | event (Lambda &&lambda, thread_safety_t thread_safety=not_thread_safe) |
Make subscription to the message by lambda-function. More... | |
template<typename Msg > | |
subscription_bind_t & | transfer_to_state (const state_t &target_state) |
An instruction for switching agent to the specified state and transfering event proceessing to new state. More... | |
template<typename Msg > | |
subscription_bind_t & | suppress () |
Suppress processing of event in this state. More... | |
template<typename Msg > | |
subscription_bind_t & | just_switch_to (const state_t &target_state) |
Define handler which only switches agent to the specified state. More... | |
Private Types | |
typedef std::vector< const state_t *> | state_vector_t |
Type of vector of states. More... | |
Private Member Functions | |
void | create_subscription_for_states (const std::type_index &msg_type, const event_handler_method_t &method, thread_safety_t thread_safety, event_handler_kind_t handler_kind) const |
Create subscription of event for all states. More... | |
void | ensure_handler_can_be_used_with_mbox (const so_5::details::msg_type_and_handler_pair_t &handler) const |
Additional check for subscription to a mutable message from MPMC mbox. More... | |
Private Attributes | |
agent_t * | m_agent |
Agent to which we are subscribing. More... | |
mbox_t | m_mbox_ref |
Mbox for messages to subscribe. More... | |
state_vector_t | m_states |
States of agents the event to be subscribed in. More... | |
A class for creating a subscription to messages from the mbox.
This type provides one of the ways to subscribe an agent's event handlers. There are two way to do that. The first one uses so_5::state_t::event() methods:
But this way do not allow to subscribe the same event handler for several states in the compact way.
This can be done via agent_t::so_subscribe(), agent_t::so_subscribe_self() and subscription_bind_t object:
|
private |
Type of vector of states.
agent | Agent to subscribe. |
mbox_ref | Mbox for messages to be subscribed. |
|
inlineprivate |
Create subscription of event for all states.
|
inlineprivate |
Additional check for subscription to a mutable message from MPMC mbox.
Such attempt must be disabled because delivery of mutable messages via MPMC mboxes is prohibited.
so_5::exception_t | if m_mbox_ref is a MPMC mbox and handler is for mutable message. |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t &>::type so_5::subscription_bind_t::event | ( | Method_Pointer | pfn, |
thread_safety_t | thread_safety = not_thread_safe |
||
) |
Make subscription to the message.
pfn | Event handling method. |
thread_safety | Thread safety of the event handler. |
std::enable_if< details::lambda_traits::is_lambda< Lambda >::value, subscription_bind_t &>::type so_5::subscription_bind_t::event | ( | Lambda && | lambda, |
thread_safety_t | thread_safety = not_thread_safe |
||
) |
Make subscription to the message by lambda-function.
lambda | Event handler code. |
thread_safety | Thread safety of the event handler. |
|
inline |
Set up a state in which events are allowed be processed.
state | State in which events are allowed. |
subscription_bind_t & so_5::subscription_bind_t::just_switch_to | ( | const state_t & | target_state | ) |
Define handler which only switches agent to the specified state.
subscription_bind_t & so_5::subscription_bind_t::suppress | ( | ) |
Suppress processing of event in this state.
subscription_bind_t & so_5::subscription_bind_t::transfer_to_state | ( | const state_t & | target_state | ) |
An instruction for switching agent to the specified state and transfering event proceessing to new state.
|
private |
Agent to which we are subscribing.
|
private |
Mbox for messages to subscribe.
|
private |
States of agents the event to be subscribed in.