#if defined( _MSC_VER )
#if defined( __clang__ )
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <time.h>
struct msg_hello_periodic
{
std::string m_message;
};
{
public:
{
.
event( &a_shutdowner_t::evt_stop_signal );
}
private:
void evt_stop_signal( mhood_t<msg_stop_signal> )
{
time_t t = time( nullptr );
std::cout << asctime( localtime( &t ) )
<< "Stop SObjectizer..." << std::endl;
}
};
{
public:
a_hello_t( context_t ctx )
, m_evt_count( 0 )
{}
private:
unsigned int m_evt_count;
void evt_hello_periodic( const msg_hello_periodic & msg );
};
void a_hello_t::so_define_agent()
{
so_subscribe_self().event( &a_hello_t::evt_hello_periodic );
}
void a_hello_t::so_evt_start()
{
time_t t = time( nullptr );
std::cout << asctime( localtime( &t ) )
<< "a_hello_t::so_evt_start()" << std::endl;
m_hello_timer_id = so_5::send_periodic< msg_hello_periodic >(
*this,
std::chrono::seconds(1),
std::chrono::milliseconds(1250),
"Hello, periodic!" );
m_stop_timer_id = so_5::send_periodic< msg_stop_signal >(
m_shutdowner_mbox,
std::chrono::seconds(2),
std::chrono::seconds::zero() );
}
void a_hello_t::evt_hello_periodic( const msg_hello_periodic & msg )
{
time_t t = time( nullptr );
std::cout << asctime( localtime( &t ) ) << msg.m_message << std::endl;
if( 5 == ++m_evt_count )
{
m_hello_timer_id.release();
}
else
{
m_stop_timer_id = so_5::send_periodic< msg_stop_signal >(
m_shutdowner_mbox,
std::chrono::microseconds(1300000),
std::chrono::seconds::zero() );
}
}
{
}
{
}
{
create_hello_coop( env );
create_shutdowner_coop( env );
}
int main()
{
try
{
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}