#include <iostream>
struct msg_hello_to_all
{
const std::string m_sender;
};
struct msg_hello_to_you
{
const std::string m_sender;
};
{
public:
a_hello_t( context_t ctx, std::string agent_name )
, m_agent_name(
std::move( agent_name ) )
, m_common_mbox( so_environment().create_mbox( "common_mbox" ) )
{}
void evt_hello_to_all(
const msg_hello_to_all & evt_data );
void evt_hello_to_you(
const msg_hello_to_you & evt_data );
private:
const std::string m_agent_name;
};
void a_hello_t::so_define_agent()
{
so_subscribe( m_common_mbox )
.event( &a_hello_t::evt_hello_to_all );
so_subscribe_self()
.event( &a_hello_t::evt_hello_to_you );
}
void a_hello_t::so_evt_start()
{
std::cout << m_agent_name << ".so_evt_start" << std::endl;
so_5::send< msg_hello_to_all >(
m_common_mbox,
m_agent_name, so_direct_mbox() );
}
void a_hello_t::evt_hello_to_all(
const msg_hello_to_all & evt_data )
{
std::cout << m_agent_name << ".evt_hello_to_all: "
<< evt_data.m_sender << std::endl;
if( m_agent_name != evt_data.m_sender )
{
so_5::send< msg_hello_to_you >( evt_data.m_mbox, m_agent_name );
}
}
void a_hello_t::evt_hello_to_you(
const msg_hello_to_you & evt_data )
{
std::cout << m_agent_name << ".evt_hello_to_you: "
<< evt_data.m_sender << std::endl;
}
{
} );
std::this_thread::sleep_for( std::chrono::milliseconds( 200 ) );
}
int main()
{
try
{
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}