#include <iostream>
#include <stdexcept>
{
public :
a_child_t( context_t ctx, bool should_throw )
, m_should_throw{ should_throw }
{}
{
if( m_should_throw )
throw std::runtime_error( "A child agent failure!" );
}
private :
const bool m_should_throw;
};
{
public :
a_parent_t( context_t ctx )
, m_counter{ 0 }
, m_max_counter{ 3 }
{}
{
.
event( &a_parent_t::evt_child_created )
.
event( &a_parent_t::evt_child_destroyed );
}
{
register_child_coop();
}
private :
int m_counter;
const int m_max_counter;
void evt_child_created(
{
std::cout <<
"coop_reg: " << evt.
m_coop << std::endl;
if( m_counter >= m_max_counter )
}
void evt_child_destroyed(
{
std::cout <<
"coop_dereg: " << evt.
m_coop
++m_counter;
register_child_coop();
}
void register_child_coop()
{
{
coop.
make_agent< a_child_t >( m_counter < m_max_counter );
std::cout <<
"registering coop: " << coop.
handle()
<< std::endl;
} );
}
};
int main()
{
try
{
{
} );
}
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.
virtual void so_define_agent()
Hook on define agent for SObjectizer.
void so_deregister_agent_coop_normally()
A helper method for deregistering agent's coop in case of normal deregistration.
const mbox_t & so_direct_mbox() const
Get the agent's direct mbox.
const state_t & so_default_state() const
Access to the agent's default state.
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
int reason() const noexcept
void add_dereg_notificator(Lambda &¬ificator)
Add notificator about cooperation deregistration event.
coop_handle_t handle() noexcept
Get handle for this coop.
void set_exception_reaction(exception_reaction_t value) noexcept
Set exception reaction for that cooperation.
Agent * make_agent(Args &&... args)
Helper method for simplification of agents creation.
void add_reg_notificator(Lambda &¬ificator)
Add notificator about cooperation registration event.
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.
const state_t & event(Args &&... args) const
Helper for subscription of event handler in this state.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
auto make_coop_reg_notificator(mbox_t target) noexcept
Create notificator about cooperation registration completion.
decltype(auto) introduce_child_coop(agent_t &owner, Args &&... args)
A simple way for creating and registering child cooperation.
auto make_coop_dereg_notificator(mbox_t target) noexcept
Create notificator about cooperation deregistration completion.
Message about cooperation deregistration completion.
const coop_handle_t m_coop
const coop_dereg_reason_t m_reason
Message about cooperation registration completion.
const coop_handle_t m_coop