#include <iostream>
#include <string>
struct run_result
{
std::string m_result;
};
{
public :
pinger(
context_t ctx,
, m_parent(
std::move(parent) )
{}
}
[this](mhood_t< pong >) {
++m_pongs;
} );
}
}
m_parent,
"pongs: " + std::to_string( m_pongs ) );
}
private :
unsigned int m_pongs = 0;
};
{
public :
, m_parent(
std::move(parent) )
{}
}
[this](mhood_t< ping >) {
++m_pings;
} );
}
m_parent,
"pings: " + std::to_string( m_pings ) );
}
private :
unsigned int m_pings = 0;
};
{
public :
parent( context_t ctx ) :
so_5::agent_t( ctx )
{}
m_child,
} );
st_first_result_got.
event( &parent::evt_second_result );
}
*this,
a_pinger->set_ponger_mbox( a_ponger->so_direct_mbox() );
a_ponger->set_pinger_mbox( a_pinger->so_direct_mbox() );
*this, std::chrono::seconds( 1 ) );
}
private :
const state_t st_first_result_got{ this };
std::string m_results;
void evt_first_result( const run_result & evt ) {
m_results = evt.m_result + "; ";
this >>= st_first_result_got;
}
void evt_second_result( const run_result & evt ) {
m_results += evt.m_result;
std::cout << m_results << std::endl;
}
};
int main()
{
try
{
{
} );
}
catch( const std::exception & x )
{
std::cerr << "Exception: " << x.what() << std::endl;
}
}
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.
virtual void so_evt_finish()
Hook of agent finish in SObjectizer.
const mbox_t & so_direct_mbox() const
Get the agent's direct mbox.
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
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.
Type of smart handle for a cooperation.
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.
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register a cooperation.
void deregister_coop(coop_handle_t coop, int reason) noexcept
Deregister the cooperation.
A base class for agent signals.
const state_t & event(Args &&... args) const
Helper for subscription of event handler in this state.
const int normal
Normal deregistration.
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.
@ mbox
The source is a mbox.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
void send(Target &&to, Args &&... args)
A utility function for creating and delivering a message or a signal.
coop_unique_holder_t create_child_coop(agent_t &owner, Args &&... args)
A simple way for creating child cooperation.
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.