#include <iostream>
namespace example
{
{
public:
, m_source{ std::move(source) }
{}
void so_define_agent() override
{
so_subscribe( m_source ).event( &a_worker_t::evt_do_something );
}
private:
void evt_do_something( mhood_t< msg_do_something > )
{
std::cout << "*** worker handles msg_do_something in child SOEnv (addr="
<< std::addressof(so_environment()) << ")"
<< std::endl;
}
};
{
public:
, m_source{ std::move(source) }
{}
void so_define_agent() override
{
so_subscribe( m_source ).event( &a_soenv_shutdowner_t::evt_shutdown );
}
private:
void evt_shutdown( mhood_t< msg_shutdown_soenv > )
{
std::cout << "*** shutting down SOEnv (addr="
<< std::addressof(so_environment()) << ")"
<< std::endl;
so_environment().stop();
}
};
{
public:
a_child_soenv_runner_t( context_t ctx,
so_5::mbox_t interaction_mbox )
, m_interaction_mbox{ std::move(interaction_mbox) }
{}
void so_evt_start() override
{
[dest = m_interaction_mbox](
{
} );
} );
std::cout << "Initialization of child SOEnv (addr="
<< std::addressof(env) << ")"
<< std::endl;
env.
make_agent< a_soenv_shutdowner_t >( m_interaction_mbox ) );
env.
make_agent< a_worker_t >( m_interaction_mbox ),
} );
std::cout << "Child SOEnv stopped" << std::endl;
}
};
{
public:
a_work_coordinator_t( context_t ctx )
, m_dest{ so_environment().create_mbox() }
{}
void so_define_agent() override
{
so_subscribe_self().event( &a_work_coordinator_t::evt_finish );
}
void so_evt_start() override
{
std::cout << "Work coordinator started in SOEnv (addr="
<< std::addressof(so_environment()) << ")"
<< std::endl;
*this,
{
coop.
make_agent< a_child_soenv_runner_t >( m_dest );
} );
m_dest,
std::chrono::milliseconds{75},
std::chrono::milliseconds{75} );
std::chrono::milliseconds{500} );
}
public:
void evt_finish( mhood_t< msg_finish > )
{
std::cout << "Work coordinator is about to finish its work" << std::endl;
so_deregister_agent_coop_normally();
}
};
}
int main()
{
using namespace example;
try
{
{
std::cout << "Initializing the parent SOEnv (addr="
<< std::addressof(env) << ")"
<< std::endl;
} );
std::cout << "The parent SOEnv stopped" << std::endl;
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
It's a kind of strong typedef for coop's deregistration reason.
Type of smart handle for a cooperation.
void add_dereg_notificator(Lambda &¬ificator)
Add notificator about cooperation deregistration event.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
disp_binder_shptr_t binder() const noexcept
Get a binder for that dispatcher.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
A base class for agent signals.
An indentificator for the timer.
SO_5_FUNC dispatcher_handle_t make_dispatcher(environment_t &env, const std::string_view data_sources_name_base, disp_params_t params)
Create an instance of active_obj dispatcher.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
decltype(auto) introduce_child_coop(agent_t &owner, Args &&... args)
A simple way for creating and registering child cooperation.
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.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
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.