#include <iostream>
#include <string>
#include <ace/OS.h>
#include <so_5/rt/h/local_mbox.hpp>
struct my_message
:
{
my_message() {}
virtual ~my_message(){}
int x;
};
struct my_unsubscribe_signal
:
{
};
struct my_another_message
:
{
my_another_message() {}
virtual ~my_another_message(){}
std::string s;
};
class my_agent_t
:
{
public:
my_agent_t(
:
m_first_state( self_ptr() ),
m_second_state( self_ptr() ),
m_mbox_ref( mbox_ref )
{}
virtual ~my_agent_t() {}
void
my_event_handler(
message );
void
my_another_event_handler(
message );
virtual void
virtual void
{
std::cout << "so_evt_start()!!\n";
m_mbox_ref->deliver_message< my_unsubscribe_signal >();
}
void
unsubscribe_event_handler(
message );
private:
};
void
my_agent_t::so_define_agent()
{
so_subscribe( m_mbox_ref )
.in( m_first_state )
.event( &my_agent_t::my_event_handler );
so_subscribe( m_mbox_ref )
.in( m_first_state )
.event( &my_agent_t::my_another_event_handler );
so_subscribe( m_mbox_ref )
.in( m_second_state )
.event( &my_agent_t::my_event_handler );
so_subscribe( m_mbox_ref )
.in( m_second_state )
.event( &my_agent_t::my_another_event_handler );
so_subscribe( m_mbox_ref )
.in( so_default_state() )
.event( &my_agent_t::unsubscribe_event_handler );
}
void
my_agent_t::unsubscribe_event_handler(
message )
{
std::cout << "unsubscribe_event_handler()!!\n";
so_unsubscribe( m_mbox_ref )
.in( m_first_state )
.event( &my_agent_t::my_event_handler );
so_unsubscribe( m_mbox_ref )
.in( m_first_state )
.event( &my_agent_t::my_another_event_handler );
so_unsubscribe( m_mbox_ref )
.in( m_second_state )
.event( &my_agent_t::my_event_handler );
so_unsubscribe( m_mbox_ref )
.in( m_second_state )
.event( &my_agent_t::my_another_event_handler );
}
void
my_agent_t::my_event_handler(
message )
{
std::cout << " my_agent_t::my_method:\t"
<< "message.x = " << message->x << "\n";
}
void
my_agent_t::my_another_event_handler(
message )
{
std::cout << " my_agent_t::my_another_event_handler:\t"
<< "message.s = '" << message->s << "'\n";
}
class so_environment_t
:
{
public:
:
base_type_t( so_5::rt::so_environment_params_t()
.mbox_mutex_pool_size( 16 ) ),
m_test_mbox( create_local_mbox(
so_5::rt::nonempty_name_t( "test_mbox" ) ) )
{}
virtual ~so_environment_t(){}
virtual void
{
new my_agent_t( m_test_mbox ) ) );
std::cout << "\nrc = " << rc << "\n\n";
ACE_OS::sleep( 10 );
}
private:
};
int
main( int, char ** )
{
std::cout << "test mboxes \n\n";
so_environment_t so_5_env;
so_5_env.run();
return 0;
}