00001
00002
00003
00004
00005
00006 #include <iostream>
00007
00008 #include <so_4/api/h/api.hpp>
00009 #include <so_4/rt/h/rt.hpp>
00010
00011 #include <so_4/timer_thread/simple/h/pub.hpp>
00012 #include <so_4/disp/one_thread/h/pub.hpp>
00013
00014
00015
00016
00017 class my_obj_t
00018 : private cpp_util_2::nocopy_t
00019 {
00020 private :
00021 std::string m_value;
00022
00023 public :
00024 my_obj_t(
00025 const std::string & value )
00026 :
00027 m_value( value )
00028 {}
00029 ~my_obj_t()
00030 {
00031
00032
00033 std::cout << "~my_obj_t: " << m_value <<std::endl;
00034 }
00035
00036 const std::string &
00037 get() const
00038 {
00039 return m_value;
00040 }
00041 };
00042
00043
00044
00045
00046 class a_my_t
00047 : public so_4::rt::agent_t
00048 {
00049 typedef so_4::rt::agent_t base_type_t;
00050 private :
00051
00052
00053 const my_obj_t & m_a;
00054 const my_obj_t & m_b;
00055
00056 public :
00057 a_my_t(
00058 const std::string & self_name,
00059 const my_obj_t & a,
00060 const my_obj_t & b )
00061 :
00062 base_type_t( self_name )
00063 , m_a( a )
00064 , m_b( b )
00065 {}
00066 virtual ~a_my_t()
00067 {
00068
00069
00070 std::cout << "~a_my_t: " << so_query_name() << std::endl;
00071 }
00072
00073 virtual const char *
00074 so_query_type() const;
00075
00076 virtual void
00077 so_on_subscription()
00078 {
00079 so_subscribe( "evt_start",
00080 so_4::rt::sobjectizer_agent_name(), "msg_start" );
00081 }
00082
00083
00084 void
00085 evt_start()
00086 {
00087 std::cout << so_query_name() << ":\n\t"
00088 << m_a.get() << "\n\t"
00089 << m_b.get() << std::endl;
00090 }
00091 };
00092
00093 SOL4_CLASS_START( a_my_t )
00094
00095 SOL4_EVENT( evt_start )
00096
00097 SOL4_STATE_START( st_normal )
00098 SOL4_STATE_EVENT( evt_start )
00099 SOL4_STATE_FINISH()
00100
00101 SOL4_CLASS_FINISH()
00102
00103
00104 class a_shutdowner_t
00105 : public so_4::rt::agent_t
00106 {
00107 typedef so_4::rt::agent_t base_type_t;
00108 public :
00109 a_shutdowner_t()
00110 : base_type_t( "a_shutdowner" )
00111 {}
00112 virtual ~a_shutdowner_t()
00113 {}
00114
00115 virtual const char *
00116 so_query_type() const;
00117
00118 virtual void
00119 so_on_subscription()
00120 {
00121 so_subscribe( "evt_start",
00122 so_4::rt::sobjectizer_agent_name(), "msg_start" );
00123 }
00124
00125 void
00126 evt_start()
00127 {
00128 so_4::api::send_msg( so_4::rt::sobjectizer_agent_name(),
00129 "msg_normal_shutdown", 0 );
00130 }
00131 };
00132
00133 SOL4_CLASS_START( a_shutdowner_t )
00134
00135 SOL4_EVENT( evt_start )
00136
00137 SOL4_STATE_START( st_normal )
00138 SOL4_STATE_EVENT( evt_start )
00139 SOL4_STATE_FINISH()
00140
00141 SOL4_CLASS_FINISH()
00142
00143 int
00144 main()
00145 {
00146
00147 my_obj_t * a = new my_obj_t( "a" );
00148 my_obj_t * b = new my_obj_t( "b" );
00149 my_obj_t * c = new my_obj_t( "c" );
00150
00151 a_my_t * a_1 = new a_my_t( "a_1", *a, *b );
00152 a_my_t * a_2 = new a_my_t( "a_2", *b, *c );
00153 a_shutdowner_t * a_shutdowner = new a_shutdowner_t();
00154
00155 so_4::rt::agent_t * agents[] = { a_1, a_2, a_shutdowner };
00156 so_4::rt::dyn_agent_coop_t * coop = new so_4::rt::dyn_agent_coop_t(
00157 "sample", agents, sizeof( agents ) / sizeof( agents[ 0 ] ) );
00158
00159
00160 so_4::rt::dyn_coop_controlled( *coop, a );
00161 so_4::rt::dyn_coop_controlled( *coop, b );
00162 so_4::rt::dyn_coop_controlled( *coop, c );
00163
00164 so_4::ret_code_t rc = so_4::api::start(
00165
00166 so_4::disp::one_thread::create_disp(
00167
00168 so_4::timer_thread::simple::create_timer_thread(),
00169 so_4::auto_destroy_timer ),
00170 so_4::auto_destroy_disp,
00171 coop );
00172 if( rc )
00173 {
00174 std::cerr << "start: " << rc << std::endl;
00175 }
00176
00177 return int( rc );
00178 }