00001
00002
00003
00004
00005 #include <iostream>
00006
00007 #include <so_4/api/h/api.hpp>
00008 #include <so_4/rt/h/rt.hpp>
00009
00010 #include <so_4/timer_thread/simple/h/pub.hpp>
00011 #include <so_4/disp/active_obj/h/pub.hpp>
00012
00013
00014 class a_child_t
00015 : public so_4::rt::agent_t
00016 {
00017 typedef so_4::rt::agent_t base_type_t;
00018 public :
00019 a_child_t(
00020 const std::string & self_name )
00021 :
00022 base_type_t( self_name )
00023 {
00024 std::cout << "add traits 1." << std::endl;
00025 so_add_traits(
00026 so_4::disp::active_obj::query_active_obj_traits() );
00027 std::cout << "add traits 2." << std::endl;
00028 }
00029 virtual ~a_child_t()
00030 {}
00031
00032 struct msg_hello {};
00033 struct msg_bye {};
00034
00035 virtual const char *
00036 so_query_type() const;
00037
00038 virtual void
00039 so_on_subscription()
00040 {
00041 so_subscribe( "evt_start",
00042 so_4::rt::sobjectizer_agent_name(), "msg_start" );
00043 }
00044
00045 void
00046 evt_start()
00047 {
00048 so_4::api::send_msg( so_query_name(), "msg_hello", 0 );
00049 so_4::api::send_msg( so_query_name(), "msg_bye", 0 );
00050 }
00051 };
00052
00053 SOL4_CLASS_START( a_child_t )
00054
00055 SOL4_MSG_START( msg_hello, a_child_t::msg_hello )
00056 SOL4_MSG_FINISH()
00057
00058 SOL4_MSG_START( msg_bye, a_child_t::msg_bye )
00059 SOL4_MSG_FINISH()
00060
00061 SOL4_EVENT( evt_start )
00062
00063 SOL4_STATE_START( st_normal )
00064 SOL4_STATE_EVENT( evt_start )
00065 SOL4_STATE_FINISH()
00066
00067 SOL4_CLASS_FINISH()
00068
00069
00070
00071
00072 class a_owner_t
00073 : public so_4::rt::agent_t
00074 {
00075 typedef so_4::rt::agent_t base_type_t;
00076 public :
00077 a_owner_t()
00078 : base_type_t( "a_owner" )
00079 {}
00080 virtual ~a_owner_t()
00081 {}
00082
00083 virtual const char *
00084 so_query_type() const;
00085
00086 virtual void
00087 so_on_subscription()
00088 {
00089 so_subscribe( "evt_start",
00090 so_4::rt::sobjectizer_agent_name(), "msg_start" );
00091 }
00092
00093 void
00094 evt_start()
00095 {
00096
00097 a_child_t * child = new a_child_t( "a_child" );
00098 so_4::rt::dyn_agent_coop_t * child_coop =
00099 new so_4::rt::dyn_agent_coop_t( child );
00100
00101
00102 so_4::rt::def_subscr_hook( *child_coop,
00103
00104 *this, "evt_hello",
00105
00106
00107 *child, "msg_hello" );
00108 so_4::rt::def_subscr_hook( *child_coop,
00109
00110 *this, "evt_bye",
00111
00112
00113 "a_child", "msg_bye" );
00114
00115
00116 so_4::rt::dyn_agent_coop_helper_t child_coop_helper(
00117 child_coop );
00118 }
00119
00120 void
00121 evt_hello()
00122 {
00123 std::cout << "hello!" << std::endl;
00124 }
00125
00126 void
00127 evt_bye()
00128 {
00129 std::cout << "bye!" << std::endl;
00130
00131 so_4::api::send_msg( so_4::rt::sobjectizer_agent_name(),
00132 "msg_normal_shutdown", 0 );
00133 }
00134 };
00135
00136 SOL4_CLASS_START( a_owner_t )
00137
00138 SOL4_EVENT( evt_start )
00139 SOL4_EVENT( evt_hello )
00140 SOL4_EVENT( evt_bye )
00141
00142 SOL4_STATE_START( st_normal )
00143 SOL4_STATE_EVENT( evt_start )
00144 SOL4_STATE_EVENT( evt_hello )
00145 SOL4_STATE_EVENT( evt_bye )
00146 SOL4_STATE_FINISH()
00147
00148 SOL4_CLASS_FINISH()
00149
00150 int
00151 main()
00152 {
00153 a_owner_t a_owner;
00154 so_4::rt::agent_coop_t coop( a_owner );
00155
00156 std::cout << "main 1." << std::endl;
00157 so_4::ret_code_t rc = so_4::api::start(
00158
00159 so_4::disp::active_obj::create_disp(
00160
00161 so_4::timer_thread::simple::create_timer_thread(),
00162 so_4::auto_destroy_timer ),
00163 so_4::auto_destroy_disp,
00164 &coop );
00165 if( rc )
00166 {
00167 std::cerr << "start: " << rc << std::endl;
00168 }
00169 else
00170 std::cerr << "successful finish" << std::endl;
00171
00172 return int( rc );
00173 }