#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_shutdowner_mbox( so_environment().create_mbox( "shutdown" ) )
, 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;
*this,
std::chrono::seconds(1),
std::chrono::milliseconds(1250),
"Hello, periodic!" );
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_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;
}
A helper header file for including all public SObjectizer stuff.
virtual void so_define_agent()
Hook on define agent for SObjectizer.
agent_t(environment_t &env)
Constructor.
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
subscription_bind_t so_subscribe(const mbox_t &mbox_ref)
Initiate subscription.
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
void stop() noexcept
Send a shutdown signal to the Run-Time.
A base class for agent signals.
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, subscription_bind_t & >::type event(Method_Pointer pfn, thread_safety_t thread_safety=not_thread_safe)
Make subscription to the message.
An indentificator for the timer.
Private part of message limit implementation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
timer_id_t send_periodic(Target &&target, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period, Args &&... args)
A utility function for creating and delivering a periodic message to the specified destination.