#include <iostream>
#include <cpp_util_2/h/lexcast.hpp>
#include <so_4/rt/h/rt.hpp>
#include <so_4/api/h/api.hpp>
#include <so_sysconf_2/h/coop_handler.hpp>
#include <so_sysconf_2/h/coop_factory.hpp>
namespace sample_dll3
{
class a_main_t :
public so_4::rt::agent_t
{
typedef so_4::rt::agent_t base_type_t;
public :
a_main_t(
const char * agent_name );
virtual ~a_main_t();
virtual const char *
so_query_type() const;
virtual void
so_on_subscription();
void
evt_start(
const so_4::rt::event_data_t & data,
const so_4::rt::msg_start * );
};
SOL4_CLASS_START( sample_dll3::a_main_t )
SOL4_EVENT_WITH_INCIDENT_TYPE(
evt_start,
so_4::rt::msg_start )
SOL4_STATE_START( st_initial )
SOL4_STATE_EVENT( evt_start )
SOL4_STATE_FINISH()
SOL4_CLASS_FINISH()
a_main_t::a_main_t( const char * agent_name )
:
base_type_t( agent_name )
{
}
a_main_t::~a_main_t()
{
}
void
a_main_t::so_on_subscription()
{
SOL4_SUBSCR_EVENT_START( evt_start, 0 )
SOL4_SUBSCR_EVENT_MSG(
so_4::rt::sobjectizer_agent_name(),
"msg_start" )
SOL4_SUBSCR_EVENT_FINISH()
}
void
a_main_t::evt_start(
const so_4::rt::event_data_t & data,
const so_4::rt::msg_start * )
{
std::cout << so_query_name() << ": evt_start" << std::endl;
}
class test_handler_t :
public so_sysconf_2::coop_handler_t
{
typedef so_sysconf_2::coop_handler_t base_type_t;
public :
test_handler_t(
const char * coop_name );
virtual ~test_handler_t();
virtual bool
reg(
const std::string & cfg_file,
std::string & error_msg )
{
so_4::rt::dyn_agent_coop_helper_t coop_helper(
new so_4::rt::dyn_agent_coop_t(
new a_main_t(
query_coop_name().c_str() ) ) );
if( coop_helper.result() )
{
error_msg = "unable to register coop, error code: " +
cpp_util_2::slexcast( coop_helper.result() );
return false;
}
return true;
}
virtual void
dereg()
{
so_4::api::deregister_coop( query_coop_name() );
}
};
test_handler_t::test_handler_t(
const char * coop_name )
:
base_type_t( "sample_dll3", coop_name )
{
}
test_handler_t::~test_handler_t()
{
}
test_handler_t g_coop_1( "sample_dll3::coop_1" );
test_handler_t g_coop_2( "sample_dll3::coop_2" );
test_handler_t g_coop_3( "sample_dll3::coop_3" );
test_handler_t g_coop_4( "sample_dll3::coop_4" );
test_handler_t g_coop_5( "sample_dll3::coop_5" );
class test_factory_t :
public so_sysconf_2::coop_factory_t
{
typedef so_sysconf_2::coop_factory_t base_type_t;
public :
test_factory_t(
const std::string & factory_name )
:
base_type_t(
"sample_dll3",
factory_name )
{}
virtual ~test_factory_t()
{}
virtual bool
reg(
const std::string & coop_name,
const std::string & cfg_file,
std::string & error_msg )
{
so_4::rt::dyn_agent_coop_helper_t coop_helper(
new so_4::rt::dyn_agent_coop_t(
new a_main_t(
coop_name.c_str() ) ) );
if( coop_helper.result() )
{
error_msg = "unable to register coop, error code: " +
cpp_util_2::slexcast( coop_helper.result() );
return false;
}
return true;
}
};
test_factory_t g_factory_1( "sample_dll3::factory" );
}