snapshot/main.cpp
#include <iostream>
#include <memory>
#include <ace/OS_main.h>
#include <so_4/rt/h/rt.hpp>
#include <so_4/api/h/api.hpp>
#include <so_4/timer_thread/simple/h/pub.hpp>
#include <so_4/disp/one_thread/h/pub.hpp>
#include <gemont_1/h/pub.hpp>
#include <gemont_1/snapshot/h/pub.hpp>
class a_data_source_t :
public virtual so_4::rt::agent_t
{
typedef so_4::rt::agent_t agent_type_t;
public :
a_data_source_t();
virtual ~a_data_source_t();
virtual const char *
so_query_type() const;
virtual void
so_on_subscription();
struct msg_tick {};
void
evt_start(
const so_4::rt::event_data_t & );
void
evt_tick(
const so_4::rt::event_data_t & );
private :
unsigned int m_ticker;
gemont_1::str_data_source_t m_parity;
gemont_1::uint_data_source_t m_ticker_monitor;
gemont_1::uint_data_source_t m_2x_ticker_monitor;
gemont_1::uint_data_source_t m_3x_ticker_monitor;
};
SOL4_CLASS_START( a_data_source_t )
SOL4_MSG_START( msg_tick, a_data_source_t::msg_tick )
SOL4_MSG_FINISH()
SOL4_EVENT( evt_start )
SOL4_EVENT( evt_tick )
SOL4_STATE_START( st_normal )
SOL4_STATE_EVENT( evt_start )
SOL4_STATE_EVENT( evt_tick )
SOL4_STATE_FINISH()
SOL4_CLASS_FINISH()
a_data_source_t::a_data_source_t()
:
agent_type_t( "a_data_source" )
, m_ticker( 0 )
, m_parity( "Четность", "parity", "НЕ ИЗВЕСТНО" )
, m_ticker_monitor( "Тикер", "ticker", m_ticker )
, m_2x_ticker_monitor( "Тикер * 2", "2x_ticker", 2 * m_ticker )
, m_3x_ticker_monitor( "Тикер * 3", "3x_ticker", 3 * m_ticker )
{
so_add_traits( m_parity );
}
a_data_source_t::~a_data_source_t()
{
}
void
a_data_source_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_CERR()
SOL4_SUBSCR_EVENT_START( evt_tick, 0 )
SOL4_SUBSCR_EVENT_MSG_SELF(
"msg_tick" )
SOL4_SUBSCR_EVENT_FINISH_CERR()
}
void
a_data_source_t::evt_start(
const so_4::rt::event_data_t & )
{
gemont_1::make_global_agent();
so_4::api::send_msg( so_query_name(), "msg_tick", 0,
so_query_name(), 1500, 1500 );
}
void
a_data_source_t::evt_tick(
const so_4::rt::event_data_t & )
{
++m_ticker;
std::cout << "m_ticker: " << m_ticker << std::endl;
m_parity.set( ( m_ticker & 1 ? "Не четное" : "Четное" ) );
m_ticker_monitor.set( m_ticker );
m_2x_ticker_monitor.set( 2 * m_ticker );
m_3x_ticker_monitor.set( 3 * m_ticker );
}
int
main( int argc, char ** argv ) {
std::auto_ptr< so_4::timer_thread::timer_thread_t >
timer_ptr( so_4::timer_thread::simple::create_timer_thread() );
std::auto_ptr< so_4::rt::dispatcher_t >
disp_ptr( so_4::disp::one_thread::create_disp( *timer_ptr ) );
a_data_source_t a_data_source;
gemont_1::snapshot::a_snapshot_t a_snapshot(
"a_snapshot", "sample_snapshot.log", "%c" );
so_4::rt::agent_t * agents[] =
{
&a_data_source,
&a_snapshot
};
so_4::rt::agent_coop_t coop(
"sample_snapshot",
agents,
sizeof( agents ) / sizeof( agents[ 0 ] ) );
so_4::ret_code_t rc = so_4::api::start( *disp_ptr, &coop );
if( rc ) {
std::cerr << "start: " << rc << std::endl;
}
return int( rc );
}