|
| | single_sink_binding_t () noexcept=default |
| |
| | ~single_sink_binding_t () noexcept |
| |
| | single_sink_binding_t (const single_sink_binding_t &)=delete |
| |
| single_sink_binding_t & | operator= (const single_sink_binding_t &)=delete |
| |
| | single_sink_binding_t (single_sink_binding_t &&other) noexcept |
| |
| single_sink_binding_t & | operator= (single_sink_binding_t &&other) noexcept |
| |
| bool | has_value () const noexcept |
| |
| bool | empty () const noexcept |
| |
| void | clear () noexcept |
| |
| void | unbind () noexcept |
| |
| void | bind_for_msg_type (const std::type_index &msg_type, const mbox_t &source, const msink_t &sink_owner) |
| |
| template<typename Msg > |
| void | bind (const mbox_t &source, const msink_t &sink_owner) |
| |
| void | bind_for_msg_type (const std::type_index &msg_type, const mbox_t &source, const msink_t &sink_owner, delivery_filter_unique_ptr_t delivery_filter) |
| |
| template<typename Msg > |
| void | bind (const mbox_t &source, const msink_t &sink_owner, delivery_filter_unique_ptr_t delivery_filter) |
| |
| template<typename Msg , typename Lambda > |
| void | bind (const mbox_t &source, const msink_t &sink_owner, Lambda &&filter) |
| |
Helper class for managing single sink bindings.
An instance of single_sink_binding_t drops the binding in the destructor. If it's necessary to drop the binding manually then clear()/unbind() methods can be used.
Usage examples:
{
...
bindings_.
bind<msg_some_data>(broadcasting_mbox_, worker_msink);
...
});
}
};
auto * first = coop.
make_agent<first_worker>(...);
std::make_unique<so_5::single_sink_binding_t>() );
first_binding->bind<msg_some_data>(broadcasting_mbox,
auto * second = coop.
make_agent<second_worker>(...);
std::make_unique<so_5::single_sink_binding_t>() );
second_binding->bind<msg_some_data>(broadcasting_mbox,
...
});
environment_t & environment() const noexcept
Access to SO Environment for which cooperation is bound.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
T * take_under_control(std::unique_ptr< T > resource)
Take a user resouce under cooperation control.
mbox_t create_mbox()
Create an anonymous MPMC mbox.
A message wrapped to be used as type of argument for event handlers.
Helper class for managing single sink bindings.
void bind(const mbox_t &source, const msink_t &sink_owner)
decltype(auto) introduce_child_coop(agent_t &owner, Args &&... args)
A simple way for creating and registering child cooperation.
msink_t SO_5_FUNC wrap_to_msink(const mbox_t &mbox, priority_t sink_priority=prio::p0)
Helper for wrapping an existing mbox into message_sink.
There is a principial difference between single_sink_binding_t and multi_sink_binding_t: if bind() is called for single_sink_binding_t when the binding is exists, then old binding will be dropped and new binding will be created. For example, this is a valid behavior for single_sink_binding_t:
binding.bind<my_message>(source, dest);
...
binding.bind<my_message>(source, dest);
Contrary, multi_sink_binding_t::bind() throws if a binding for triplet (message, source, dest) already exists.
- Attention
- The instance of single_sink_binding_t is not thread safe. If a user wants to work with an instance of single_sink_binding_t from different threads then the user has to protect the instance by her/himself.
- Note
- This class is Moveable, but is not Copyable.
- Since
- v.5.8.0
Definition at line 170 of file single_sink_binding.hpp.
template<typename Msg >
| void so_5::single_sink_binding_t::bind |
( |
const mbox_t & | source, |
|
|
const msink_t & | sink_owner ) |
|
inline |
Create a binding for message/signal of type Msg from mbox source to the destination sink_owner.
This binding won't use a delivery filter.
If the object already holds a binding the current binding will be removed before the creation of a new one.
Usage example:
auto binding = std::make_unique< so_5::single_sink_binding_t >();
binding->bind<my_message>(source, dest);
It it's required to make a binding for a mutable message then so_5::mutable_msg marker has to be used:
auto binding = std::make_unique< so_5::single_sink_binding_t >();
A special marker for mutable message.
- Parameters
-
| source | The source mbox. |
| sink_owner | The destination for messages/signals. |
Definition at line 377 of file single_sink_binding.hpp.
template<typename Msg , typename Lambda >
| void so_5::single_sink_binding_t::bind |
( |
const mbox_t & | source, |
|
|
const msink_t & | sink_owner, |
|
|
Lambda && | filter ) |
|
inline |
Create a binding for message of type Msg from mbox source to the destination sink_owner.
The lambda (or functor) filter will be used as delivery filter for messages.
If the object already holds a binding the current binding will be removed before the creation of a new one.
- Note
- This method can't be used for binding signals.
Usage example:
auto binding = std::make_unique< so_5::single_sink_binding_t >();
binding->bind<my_message>(source, dest,
[](const my_message & msg) {
...
});
It it's required to make a binding for a mutable message then so_5::mutable_msg marker has to be used, but note the type of delivery filter argument:
auto binding = std::make_unique< so_5::single_sink_binding_t >();
[](const my_message & msg) {
...
});
- Parameters
-
| source | The source mbox. |
| sink_owner | The destination for messages. |
| filter | Filter to be used. |
Definition at line 520 of file single_sink_binding.hpp.