The traditional way of sending messages and signals have two small drawbacks.
- There is some level of verbosity in preparing and sending messages:
auto msg = std::unique_ptr< my_message >( new my_message( some_args ) );
mbox->deliver_message( std::move( msg ) );
Especially when sending a delayed messages:
auto msg = std::unique_ptr< my_message >( new my_message( some_args ) );
so_environment().single_timer( std::move( msg ), mbox, pause );
- There is a difference in sending messages and signals:
mbox->deliver_message( msg );
mbox->deliver_signal< my_signal >();
This makes template-based programming a little bit difficult.
To simplify SObjectizer usage and reduce verbosity of the code a new family of so_5::send functions is introduced.
The simple message sending can be written as:
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
It is an equivalent of:
auto msg = std::unique< my_message >( new my_message( some_args ) );
mbox->deliver_message( std::move( msg ) );
By utilizing variadic templates of C++11 the some_args can me a sequence of arguments:
The same form of so_5::send is used for signal sending:
Usually it is necessary to send messages to the agent's direct mbox. So instead of writing:
it is possible to use so_5::send_to_agent function:
so_5::send_to_agent< msg >( agent, ... );
There are so_5::send_delayed functions for sending delayed messages/signals:
void send_delayed(Target &&target, std::chrono::steady_clock::duration pause, Args &&... args)
A utility function for creating and delivering a delayed message to the specified destination.
There are so_5::send_delayed_to_agent functions for sending delayed messages/signals to an agent's direct mbox:
so_5::send_delayed_to_agent< my_message >( agent, pause, some_args );
so_5::send_delayed_to_agent< my_signal >( agent, pause );
There also are so_5::send_periodic functions for sending periodic messages/signals:
timer_id_t send_periodic(Target &&target, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period, Args &&... args)
A utility function for creating and delivering a periodic message to the specified destination.
There are so_5::send_periodic_to_agent functions for sending periodic messages/signals to an agent's direct mbox:
so_5::send_periodic_to_agent< my_message >( agent, pause, period, some_args );
so_5::send_periodic_to_agent< my_signal >( agent, pause, period );