#include <iostream>
#include <string>
#include <ace/OS_main.h>
#include <so_4/rt/h/rt.hpp>
#include <so_4/api/h/api.hpp>
#include <so_4/timer_thread/simple/h/pub.hpp>
#include <so_4/disp/one_thread/h/pub.hpp>
#include <so_sysconf_2/h/pub.hpp>
#include <so_sysconf_2/h/agent_with_fatal_state.hpp>
class a_sample_t
: public so_sysconf_2::agent_with_fatal_state_t
{
typedef so_sysconf_2::agent_with_fatal_state_t base_type_t;
public :
a_sample_t();
virtual const char *
so_query_type() const;
virtual void
so_on_subscription();
struct msg_timeout {};
void
evt_start();
void
evt_timeout();
};
SOL4_CLASS_START( a_sample_t )
SOL4_SUPER_CLASS( so_sysconf_2::agent_with_fatal_state_t )
SOL4_INITIAL_STATE( st_normal )
SOL4_MSG_START( msg_timeout, a_sample_t::msg_timeout )
SOL4_MSG_FINISH()
SOL4_EVENT( evt_start )
SOL4_EVENT( evt_timeout )
SOL4_STATE_START( st_normal )
SOL4_STATE_EVENT( evt_start )
SOL4_STATE_EVENT( evt_timeout )
SOL4_STATE_FINISH()
SOL4_CLASS_FINISH()
a_sample_t::a_sample_t()
: base_type_t( "a_sample" )
{}
void
a_sample_t::so_on_subscription()
{
so_subscribe( "evt_start",
so_4::rt::sobjectizer_agent_name(),
"msg_start" );
so_subscribe( "evt_timeout", "msg_timeout" );
}
void
a_sample_t::evt_start()
{
so_sysconf_2::register_coop();
std::cout << "so_sysconf_2 subsystem started" << std::endl;
so_4::api::send_msg( so_query_name(), "msg_timeout", 0, "", 2000 );
std::cout << "awaiting time out..." << std::endl;
}
void
a_sample_t::evt_timeout()
{
switch_to_fatal_state( "timed_out", "sample time is out" );
}
int
main( int argc, char ** argv )
{
a_sample_t a_sample;
so_4::rt::agent_coop_t sample_coop( a_sample );
so_4::ret_code_t rc = so_4::api::start(
so_4::disp::one_thread::create_disp(
so_4::timer_thread::simple::create_timer_thread(),
so_4::auto_destroy_timer ),
so_4::auto_destroy_disp,
&sample_coop );
return rc;
}