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:
{
state_t st_first{
this}, st_second{
this}, st_third{
this};
...
st_first.
event(some_mbox, &subscribe_demo::event_handler_1);
st_second
.
event(some_mbox, &subscribe_demo::event_handler_1)
.
event(some_mbox, &subscribe_demo::event_handler_2);
st_third
.
event(some_mbox, &subscribe_demo::event_handler_1)
.
event(some_mbox, &subscribe_demo::event_handler_3)
}
};
virtual void so_define_agent()
Hook on define agent for SObjectizer.
Class for the representing agent state.
const state_t & event(Args &&... args) const
Helper for subscription of event handler in this state.
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:
{
state_t st_first{
this}, st_second{
this}, st_third{
this};
...
.
event(&subscribe_demo::event_handler_1);
.
event(&subscribe_demo::event_handler_2);
.
event(&subscribe_demo::event_handler_3)
}
};
subscription_bind_t so_subscribe(const mbox_t &mbox_ref)
Initiate subscription.
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.
subscription_bind_t & in(const state_t &state)
Set up a state in which events are allowed be processed.
- Some words about binder logic...
- An object of type subscription_bind_t collects list of states enumerated by calls to subscription_bind_t::in() method. Every call to in() method add a state to that list. It means:
so_subscribe(some_mbox)
.in(st_first)
.in(st_second)
.in(st_third)
...
A call to event() or suppress() or just_switch_to() applies subscription to all states which are currently in the list. But these calls do not remove the content of that list. It means: so_subscribe(some_mbox)
.in(st_first)
.event(handler_1)
.in(st_second)
.event(handler_2)
.in(st_third)
.event(handler_3)
...
Definition at line 173 of file agent.hpp.