#include <so_5/all.hpp>
using namespace std::chrono_literals;
class service_provider_t final : public so_5::agent_t
{
public :
using so_5::agent_t::agent_t;
void so_define_agent() override
{
so_subscribe_self().event(
[]( sync_ns::request_mhood_t<int, std::string> cmd ) {
cmd->make_reply( std::to_string(cmd->request() * 2) );
} );
}
};
class consumer_t final : public so_5::agent_t
{
const so_5::mbox_t m_service;
public :
consumer_t( context_t ctx, so_5::mbox_t service )
:
so_5::agent_t{ std::move(ctx) }
, m_service{ std::move(service) }
{}
void so_evt_start() override
{
auto result = sync_ns::request_reply<int, std::string>(
m_service,
500ms,
4 );
std::cout << "The result: " << result << std::endl;
so_deregister_agent_coop_normally();
}
};
int main()
{
so_5::launch( [](so_5::environment_t & env) {
env.introduce_coop(
so_5::disp::active_obj::make_dispatcher( env ).binder(),
[](so_5::coop_t & coop) {
auto service_mbox = coop.make_agent< service_provider_t >()
->so_direct_mbox();
coop.make_agent< consumer_t >( service_mbox );
} );
} );
}
Ranges for error codes of each submodules.
Implementation of synchronous operations on top of SObjectizer.