|
| 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< 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<typename Message , typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, subscription_bind_t &>::type | event (signal_indicator_t< Message >(), Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe) |
| Make subscription to the signal. 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<class Message , class Lambda > |
std::enable_if< details::lambda_traits::is_lambda< Lambda >::value, subscription_bind_t &>::type | event (signal_indicator_t< Message >(), Lambda &&lambda, thread_safety_t thread_safety=not_thread_safe) |
| Make subscription to the signal by lambda-function. More...
|
|
template<typename Signal , typename... Args> |
subscription_bind_t & | event (Args &&... args) |
| Make subscription to the signal. 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...
|
|
template<class Message , class Lambda> |
std::enable_if< details::lambda_traits::is_lambda< Lambda >::value, subscription_bind_t &>::type | event (signal_indicator_t< Message >(*)(), Lambda &&lambda, thread_safety_t thread_safety) |
|
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};
...
virtual void so_define_agent() override {
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)
}
};
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};
...
virtual void so_define_agent() override {
so_subscribe(some_mbox)
.in(st_first)
.in(st_second)
.in(st_third)
.
event(&subscribe_demo::event_handler_1);
so_subscribe(some_mbox)
.in(st_second)
.
event(&subscribe_demo::event_handler_2);
so_subscribe(some_mbox)
.in(st_third)
.
event(&subscribe_demo::event_handler_3)
}
};
- 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)
...