virtual void so_define_agent() override { so_set_delivery_filter( m_data_mbox, []( const data & msg ) { return 1 == std::get<0>( msg ); } ); so_default_state() .event( m_data_mbox, [this]( const data & msg ) { const auto value = std::get<0>( msg ); if( 1 != value ) throw std::runtime_error( "unexpected data value: " + std::to_string( value ) ); ++m_values_accepted; } ) .event< finish >( [this] { if( 2 != m_values_accepted ) throw std::runtime_error( "unexpected count of " "accepted data instances: " + std::to_string( m_values_accepted ) ); so_deregister_agent_coop_normally(); } ); }
void my_agent_t::so_define_agent() { std::cout << "so_define_agent()" << std::endl; st_first.event( &my_agent_t::change_state_event_handler ); st_second.event( &my_agent_t::change_state_event_handler ); so_default_state().event( &my_agent_t::change_state_event_handler ); std::cout << "\tsubscribe my_event_handler in " << st_first.query_name() << std::endl; st_first.event( &my_agent_t::my_event_handler ); std::cout << "\tsubscribe my_another_event_handler in " << st_first.query_name() << std::endl; st_first.event( &my_agent_t::my_another_event_handler ); std::cout << "\tsubscribe my_event_handler in " << st_second.query_name() << std::endl; st_second.event( &my_agent_t::my_event_handler ); }
virtual void so_define_agent() override { so_default_state().event< msg_your_turn >( [this] { if( m_next ) so_5::send< msg_your_turn >( m_next ); else so_deregister_agent_coop_normally(); } ); }
virtual void so_define_agent() { so_subscribe( so_direct_mbox() ) .in( so_default_state() ) .event( &a_ordinary_t::some_handler ); so_direct_mbox()->deliver_signal< some_message >(); }
virtual void so_define_agent() { so_5::mbox_t mbox = so_environment() .create_mbox( g_test_mbox_name ); so_subscribe( mbox ) .in( so_default_state() ) .event( &a_ordinary_t::some_handler ); // Give time to test message sender. std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); }
void my_agent_t::change_state_event_handler( const change_state_message & message ) { std::cout << "change_state_event_handler()" << std::endl; if( DEFAULT_STATE == message.m_next_state ) { this >>= so_default_state(); std::cout << "\tswitched to default state and shutdown..." << std::endl; so_environment().stop(); }
virtual void so_evt_start() { so_5::mbox_t mbox = so_environment() .create_mbox( so_coop_name() + "_mbox" ); so_subscribe( mbox ) .in( so_default_state() ) .event( &a_master_t::evt_slave_finished ); so_environment().register_agent_as_coop( so_coop_name() + "_slave", new a_slave_t( so_environment(), mbox ) ); }
virtual void so_define_agent() override { so_default_state() .event< msg_one >( [&]{ ++m_received; } ) .event< msg_two >( [&]{ if( 2 != m_received ) throw std::runtime_error( "unexpected count of " "received msg_one instances: " + std::to_string( m_received ) ); so_deregister_agent_coop_normally(); } ); }
virtual void so_define_agent() override { so_default_state() .event( [this]( const so_5::msg_coop_deregistered & ) { so_5::send< data >( m_data_mbox, 0 ); so_5::send< data >( m_data_mbox, 1 ); so_5::send< data >( m_data_mbox, 2 ); so_5::send_to_agent< finish >( *this ); } ) .event< finish >( [this] { so_deregister_agent_coop_normally(); } ); }
void a_key_value_storage_t::so_define_agent() { // All events will be handled in the default state. // // All events are implemented by lambda-functions. // This allows to hide the actual implementation of // agent's internals from agent's users. // so_default_state() .event( [this]( const msg_register_pair & evt ) { m_impl->register_pair( *this, evt ); } ) .event( [this]( const msg_request_by_key & evt ) { return m_impl->handle_request_for_pair( evt ); } ) .event( [this]( const internals_t::msg_lifetime_expired & evt ) { m_impl->handle_lifetime_expiration( evt ); } ); }
virtual void so_define_agent() override { // A notification on complete children cooperation deregistration // must be received and handled. so_default_state().event( [this]( const so_5::msg_coop_deregistered & ) { --m_remaining_iterations; show_remaining_iterations(); if( m_remaining_iterations ) // There are some iterations left. // New child cooperation must be created and started. create_new_child_coop(); else { // Example must be finished. std::cout << "no more iterations left, finishing..." << std::endl; so_deregister_agent_coop_normally(); } } ); }