sample/hello_delay/main.cpp
#include <iostream>
#include <time.h>
#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>
class a_hello_t
  : public so_4::rt::agent_t
{
  
  typedef so_4::rt::agent_t base_type_t;
  public :
    a_hello_t();
    virtual ~a_hello_t();
    virtual const char *
    so_query_type() const;
    virtual void
    so_on_subscription();
    
    struct  msg_hello_time {};
    
    struct  msg_quit_time {};
    
    void
    evt_start();
    
    void
    evt_hello_time();
};
SOL4_CLASS_START( a_hello_t )
  
  SOL4_MSG_START( msg_hello_time, a_hello_t::msg_hello_time )
  SOL4_MSG_FINISH()
  
  SOL4_EVENT( evt_start )
  SOL4_EVENT( evt_hello_time )
  
  SOL4_STATE_START( st_initial )
    SOL4_STATE_EVENT( evt_start )
    SOL4_STATE_EVENT( evt_hello_time )
  SOL4_STATE_FINISH()
SOL4_CLASS_FINISH()
a_hello_t::a_hello_t()
:
  base_type_t( "a_hello" )
{}
a_hello_t::~a_hello_t()
{}
void
a_hello_t::so_on_subscription()
{
  so_subscribe( "evt_start",
    so_4::rt::sobjectizer_agent_name(), "msg_start" );
  so_subscribe( "evt_hello_time", "msg_hello_time" );
}
void
a_hello_t::evt_start()
{
  
  unsigned int sec = 2;
  time_t t = time( 0 );
  std::cout << so_query_name() << ": "
    << asctime( localtime( &t ) )
    << "hello after " << sec << " seconds" << std::endl;
  
  so_4::api::send_msg(
    so_query_name(),
    "msg_hello_time",
    0,
    so_4::api::receiver_unknown(),
    sec * 1000 );
}
void
a_hello_t::evt_hello_time()
{
  time_t t = time( 0 );
  std::cout << so_query_name() << ": "
    << asctime( localtime( &t ) ) << std::flush;
  std::cout << "Hello, World!" << std::endl;
  
  so_4::api::send_msg(
    so_4::rt::sobjectizer_agent_name(),
    "msg_normal_shutdown", 0 );
}
int
main( int, char ** )
{
  
  a_hello_t a_hello;
  
  so_4::rt::agent_coop_t  a_hello_coop( a_hello );
  
  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,
    &a_hello_coop );
  if( rc )
  {
    
    std::cerr << "start: " << rc << std::endl;
  }
  return int( rc );
}