Skip to content

Commit

Permalink
Merge pull request #26 from SeadexGmbH/yasmine-1.4.3
Browse files Browse the repository at this point in the history
yasmine 1.4.3
  • Loading branch information
SeadexTM authored Nov 10, 2017
2 parents f75d566 + 30bb7fb commit 5cf17b8
Show file tree
Hide file tree
Showing 158 changed files with 3,583 additions and 10,356 deletions.
8 changes: 4 additions & 4 deletions examples/classic_farmroad/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace
const unsigned int DETECTOR_OFF_LOWER_EXTREMITY(1);
const unsigned int DETECTOR_OFF_UPPER_EXTREMITY(12);
const unsigned int DETECTOR_ON_UPPER_EXTREMITY(3);
const unsigned int DETECTOR_ON_LOWER_RXTREMITY(1);
const unsigned int DETECTOR_ON_LOWER_EXTREMITY(1);


}
Expand Down Expand Up @@ -88,7 +88,7 @@ void detector::generate_detector_events()
{
random_generator generator;
is_on_ = false;
{
{
sxe::milliseconds time_to_wait =
sxe::milliseconds( generator.generate( DETECTOR_OFF_LOWER_EXTREMITY, DETECTOR_OFF_UPPER_EXTREMITY ) );
condition_variable_.wait_for( lock, time_to_wait );
Expand All @@ -97,9 +97,9 @@ void detector::generate_detector_events()
if( run_ )
{
is_on_ = true;
{
{
sxe::milliseconds time_to_wait =
sxe::milliseconds( generator.generate( DETECTOR_ON_UPPER_EXTREMITY, DETECTOR_ON_UPPER_EXTREMITY ) );
sxe::milliseconds( generator.generate( DETECTOR_ON_LOWER_EXTREMITY, DETECTOR_ON_UPPER_EXTREMITY ) );
condition_variable_.wait_for( lock, time_to_wait );

detector_callback_.detector_on();
Expand Down
72 changes: 5 additions & 67 deletions examples/classic_farmroad/intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void intersection::minimum_time_not_elapsed() const
}


void intersection::minimum_time_elapsed() const
void intersection::minimum_time_elapsed() const
{
SX_LOG( hermes::log_level::LL_INFO, "Minimum time elapsed." );
}
Expand Down Expand Up @@ -254,7 +254,7 @@ bool intersection::check_detector_is_off()


void intersection::cancel_timer_event_on_detector_off( const sxy::event& _event )
{
{
if( _event.get_id() == detector_off_event::get_event_id() )
{
if( farmroad_maximum_time_event_handle_ > 0 )
Expand Down Expand Up @@ -284,67 +284,35 @@ void intersection::build_intersection_state_machine()
#ifdef SX_CPP03_BOOST
sxy::event_ids EVENTS_EXIT_FARMROAD_OPEN;
EVENTS_EXIT_FARMROAD_OPEN.push_back( detector_on_event::get_event_id() );
EVENTS_EXIT_FARMROAD_OPEN.push_back( event_farmroad_maximum_time_elapsed_event::get_event_id() );
EVENTS_EXIT_FARMROAD_OPEN.push_back( event_farmroad_maximum_time_elapsed_event::get_event_id() );
#endif

sxy::composite_state& root = intersection_state_machine_.get_root_state();
sxy::region& main_region = root.add_region( "main_region" );
sxy::initial_pseudostate& initial_pseudostate = main_region.add_initial_pseudostate( "initial" );

// highway open
#ifdef SX_CPP03_BOOST
sxy::composite_state& l_highway_open =
main_region.add_composite_state( "highway open",
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, highway_open_entry ),
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, highway_open_exit ) );
#else
sxy::composite_state& l_highway_open = main_region.add_composite_state( "highway open",
Y_BEHAVIOR_METHOD2( this, &intersection::highway_open_entry ),
Y_BEHAVIOR_METHOD2( this, &intersection::highway_open_exit ) );
#endif

sxy::region& highway_open_region = l_highway_open.add_region( "highway region" );
sxy::initial_pseudostate& initial_highway = highway_open_region.add_initial_pseudostate( "initial highway" );
sxy::simple_state& initialize_dummy = highway_open_region.add_simple_state( "initialize dummy" );
sxy::junction& detector_junction = highway_open_region.add_junction( "detector junction" );

#ifdef SX_CPP03_BOOST
sxy::simple_state& l_minimum_time_not_elapsed = highway_open_region.add_simple_state( "minimum time not elapsed",
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, minimum_time_not_elapsed ) );
sxy::simple_state& l_minimum_time_elapsed = highway_open_region.add_simple_state( "minimum time elapsed",
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, minimum_time_elapsed ) );
sxy::simple_state& l_minimum_time_not_elapsed_farmroad_waiting = highway_open_region.add_simple_state(
"Minimum time not elapsed and farmroad waiting",
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, minimum_time_not_elapsed_farmroad_waiting ) );
#else
sxy::simple_state& l_minimum_time_not_elapsed = highway_open_region.add_simple_state( "minimum time not elapsed",
Y_BEHAVIOR_METHOD2( this, &intersection::minimum_time_not_elapsed ) );
sxy::simple_state& l_minimum_time_elapsed = highway_open_region.add_simple_state( "minimum time elapsed",
Y_BEHAVIOR_METHOD2( this, &intersection::minimum_time_elapsed ) );
sxy::simple_state& l_minimum_time_not_elapsed_farmroad_waiting = highway_open_region.add_simple_state(
"Minimum time not elapsed and farmroad waiting",
Y_BEHAVIOR_METHOD2( this, &intersection::minimum_time_not_elapsed_farmroad_waiting ) );
#endif


sxy::final_state& highway_finished = highway_open_region.add_final_state( "highway finished" );

// switching highway to farmroad
sxy::composite_state& switching_to_farmroad = main_region.add_composite_state( "switching highway to farmroad" );
sxy::region& switching_to_farmroad_region = switching_to_farmroad.add_region( "region switching to farmroad" );
sxy::initial_pseudostate& initial_switching_to_farmroad =
switching_to_farmroad_region.add_initial_pseudostate( "initial switching highway to farmroad" );

#ifdef SX_CPP03_BOOST
sxy::simple_state& l_switching_to_farmroad_phase_1 = switching_to_farmroad_region.add_simple_state(
"switching to farmroad phase 1", Y_BEHAVIOR_METHOD_NO_EVENT( intersection, switching_to_farmroad_phase_1 ) );
sxy::simple_state& state_switching_to_farmroad_phase_2 = switching_to_farmroad_region.add_simple_state(
"switching to farmroad phase 2", Y_EMPTY_BEHAVIOR,
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, switching_to_farmroad_phase_2 ) );
sxy::simple_state& farmroad_open = main_region.add_simple_state( "farmroad open", Y_EMPTY_BEHAVIOR,
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, farmroad_open_entry ),
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, farmroad_open_exit ) );
#else
switching_to_farmroad_region.add_initial_pseudostate( "initial switching highway to farmroad" );
sxy::simple_state& l_switching_to_farmroad_phase_1 = switching_to_farmroad_region.add_simple_state(
"switching to farmroad phase 1", Y_BEHAVIOR_METHOD2( this, &intersection::switching_to_farmroad_phase_1 ) );
sxy::simple_state& state_switching_to_farmroad_phase_2 = switching_to_farmroad_region.add_simple_state(
Expand All @@ -354,8 +322,6 @@ void intersection::build_intersection_state_machine()
main_region.add_simple_state( "farmroad open", SX_NULLPTR,
Y_BEHAVIOR_METHOD2( this, &intersection::farmroad_open_entry ),
Y_BEHAVIOR_METHOD2( this, &intersection::farmroad_open_exit ) );
#endif

sxy::final_state& switching_to_farmroad_finished =
switching_to_farmroad_region.add_final_state( "switching to farmroad finished" );

Expand All @@ -364,24 +330,12 @@ void intersection::build_intersection_state_machine()
sxy::region& switching_to_highway_region = switching_to_highway.add_region( "region switching to highway" );
sxy::initial_pseudostate& initial_switching_to_highway =
switching_to_highway_region.add_initial_pseudostate( "initial switching to highway" );

#ifdef SX_CPP03_BOOST
sxy::simple_state& l_switching_to_highway_phase_1 = switching_to_highway_region.add_simple_state(
"switching to highway phase 1", Y_EMPTY_BEHAVIOR,
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, switching_to_highway_phase_1 ) );
sxy::simple_state& l_switching_to_highway_phase_2 = switching_to_highway_region.add_simple_state(
"switching to highway phase 2", Y_EMPTY_BEHAVIOR,
Y_BEHAVIOR_METHOD_NO_EVENT( intersection, switching_to_highway_phase_2 ) );
#else
sxy::simple_state& l_switching_to_highway_phase_1 = switching_to_highway_region.add_simple_state(
"switching to highway phase 1", SX_NULLPTR,
Y_BEHAVIOR_METHOD2( this, &intersection::switching_to_highway_phase_1 ) );
sxy::simple_state& l_switching_to_highway_phase_2 = switching_to_highway_region.add_simple_state(
"switching to highway phase 2", SX_NULLPTR,
Y_BEHAVIOR_METHOD2( this, &intersection::switching_to_highway_phase_2 ) );
#endif


sxy::final_state& switching_to_highway_finished =
switching_to_highway_region.add_final_state( "switching to highway finished" );

Expand All @@ -390,36 +344,20 @@ void intersection::build_intersection_state_machine()
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, initial_pseudostate, l_highway_open );
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, l_highway_open, switching_to_farmroad );
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, switching_to_farmroad, farmroad_open );
#ifdef SX_CPP03_BOOST
intersection_state_machine_.add_transition( EVENTS_EXIT_FARMROAD_OPEN, farmroad_open, switching_to_highway,
sxy::transition_kind::EXTERNAL, Y_EMPTY_GUARD,
Y_BEHAVIOR_METHOD( intersection, cancel_timer_event_on_detector_off ) );
#else
intersection_state_machine_.add_transition( EVENTS_EXIT_FARMROAD_OPEN, farmroad_open, switching_to_highway,
sxy::transition_kind::EXTERNAL, Y_EMPTY_GUARD,
Y_BEHAVIOR_METHOD2( this, &intersection::cancel_timer_event_on_detector_off ) );
#endif

intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, switching_to_highway, l_highway_open );

// inside highway open
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, initial_highway, initialize_dummy );
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, initialize_dummy, detector_junction );
#ifdef SX_CPP03_BOOST
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, detector_junction,
l_minimum_time_not_elapsed_farmroad_waiting, sxy::transition_kind::EXTERNAL,
Y_GUARD_METHOD_NO_EVENT( intersection, check_detector_is_on ) );
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, detector_junction, l_minimum_time_not_elapsed,
sxy::transition_kind::EXTERNAL, Y_GUARD_METHOD_NO_EVENT( intersection, check_detector_is_off ) );
#else
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, detector_junction,
l_minimum_time_not_elapsed_farmroad_waiting, sxy::transition_kind::EXTERNAL,
Y_GUARD_METHOD2( this, &intersection::check_detector_is_on ) );
intersection_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, detector_junction,
l_minimum_time_not_elapsed, sxy::transition_kind::EXTERNAL,
Y_GUARD_METHOD2( this, &intersection::check_detector_is_off ) );
#endif

intersection_state_machine_.add_transition(
detector_on_event::get_event_id(), l_minimum_time_not_elapsed, l_minimum_time_not_elapsed_farmroad_waiting );
intersection_state_machine_.add_transition(
Expand Down
12 changes: 0 additions & 12 deletions examples/classic_farmroad/traffic_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ void traffic_light::build_traffic_light_state_machine()
sxy::initial_pseudostate& initial_pseudostate = main_region.add_initial_pseudostate( "initial" );

// states
#ifdef SX_CPP03_BOOST
sxy::simple_state& red_state =
main_region.add_simple_state( "Red", Y_BEHAVIOR_METHOD_NO_EVENT( traffic_light, on_traffic_light_red ) );
sxy::simple_state& red_yellow_state =
main_region.add_simple_state( "Red-Yellow",
Y_BEHAVIOR_METHOD_NO_EVENT( traffic_light, on_traffic_light_red_yellow ) );
sxy::simple_state& green_state =
main_region.add_simple_state( "Green", Y_BEHAVIOR_METHOD_NO_EVENT( traffic_light, on_traffic_light_green ) );
sxy::simple_state& yellow_state =
main_region.add_simple_state( "Yellow", Y_BEHAVIOR_METHOD_NO_EVENT( traffic_light, on_traffic_light_yellow ) );
#else
sxy::simple_state& red_state = main_region.add_simple_state( "Red",
Y_BEHAVIOR_METHOD2( this, &traffic_light::on_traffic_light_red ) );
sxy::simple_state& red_yellow_state = main_region.add_simple_state( "Red-Yellow",
Expand All @@ -141,7 +130,6 @@ void traffic_light::build_traffic_light_state_machine()
Y_BEHAVIOR_METHOD2( this, &traffic_light::on_traffic_light_green ) );
sxy::simple_state& yellow_state = main_region.add_simple_state( "Yellow",
Y_BEHAVIOR_METHOD2( this, &traffic_light::on_traffic_light_yellow ) );
#endif

// transitions
traffic_light_state_machine_.add_transition( sxy::Y_COMPLETION_EVENT_ID, initial_pseudostate, red_state );
Expand Down
41 changes: 3 additions & 38 deletions examples/event_collector_example/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,21 @@ namespace examples
}


#ifndef SX_CPP03_BOOST

void action::fire_event_E3( sxy::event_collector& _event_collector )
{
_event_collector.push( examples::E3::create() );
}


void action::fire_event_E4( sxy::event_collector& _event_collector )
{
_event_collector.push( examples::E4::create( "The transition from simple state 'S3' to the final state has been executed!" ) );
}

void action::print_message_from_event( const E4& _event )
{
std::cout << _event.get_message() << std::endl;
}

#else

void action::fire_event_E3( const sxy::event& _event, sxy::event_collector& _event_collector )
{
SX_UNUSED_PARAMETER( _event );
_event_collector.push( examples::E3::create() );
}


void action::fire_event_E4( const sxy::event& _event, sxy::event_collector& _event_collector )
void action::fire_event_E4( sxy::event_collector& _event_collector )
{
SX_UNUSED_PARAMETER( _event );
_event_collector.push( examples::E4::create( "The transition from simple state 'S3' to the final state has been executed!" ) );
}


void action::print_message_from_event( const sxy::event& _event )
void action::print_message_from_event( const E4& _event )
{
const E4* specialized_event = dynamic_cast< const E4* >( &_event );
if( specialized_event )
{
std::cout << specialized_event->get_message() << std::endl;
}
else
{
throw sxe::exception( "Invalid event type!" );
}
std::cout << _event.get_message() << std::endl;
}

#endif




}
7 changes: 0 additions & 7 deletions examples/event_collector_example/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,9 @@ class action SX_FINAL
action();
~action() SX_NOEXCEPT;
SX_NO_COPY( action )
#ifndef SX_CPP03_BOOST
void fire_event_E3( sxy::event_collector& _event_collector );
void fire_event_E4( sxy::event_collector& _event_collector );
void print_message_from_event( const E4& _event );
#else
void fire_event_E3( const sxy::event& _event, sxy::event_collector& _event_collector );
void fire_event_E4( const sxy::event& _event, sxy::event_collector& _event_collector );
void print_message_from_event( const sxy::event& _event );
#endif

};


Expand Down
24 changes: 5 additions & 19 deletions examples/event_collector_example/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,29 @@ namespace examples


state_machine_uptr machine::setup_state_machine( const std::string& _name )
{
{
state_machine_uptr state_machine = SX_MAKE_UNIQUE< sxy::sync_state_machine >( _name );
sxy::composite_state& root_state = state_machine->get_root_state();
sxy::region& main_region = root_state.add_region( "main region" );
sxy::initial_pseudostate& initial = main_region.add_initial_pseudostate( "initial" );
sxy::simple_state& s1 = main_region.add_simple_state( "S1" );
sxy::simple_state& s1 = main_region.add_simple_state( "S1" );
action* action_ptr = &action_;
#ifndef SX_CPP03_BOOST
sxy::simple_state& s2 = main_region.add_simple_state( "S2",
Y_BEHAVIOR_METHOD2( action_ptr, &examples::action::fire_event_E3 ), Y_EMPTY_BEHAVIOR, Y_EMPTY_BEHAVIOR );
#else
sxy::simple_state& s2 = main_region.add_simple_state( "S2",
sxy::behavior_function( sxe::bind( &action::fire_event_E3, action_ptr, sxe::_1, sxe::_2 ) ),
Y_EMPTY_BEHAVIOR, Y_EMPTY_BEHAVIOR );
#endif
sxy::simple_state& s2 = main_region.add_simple_state( "S2",
Y_BEHAVIOR_METHOD2( action_ptr, &action::fire_event_E3 ), Y_EMPTY_BEHAVIOR, Y_EMPTY_BEHAVIOR );
sxy::simple_state& s3 = main_region.add_simple_state( "S3" );
sxy::simple_state& s4 = main_region.add_simple_state( "S4" );
sxy::final_state& final = main_region.add_final_state( "final" );
state_machine->add_transition( sxy::Y_COMPLETION_EVENT_ID, initial, s1 );
state_machine->add_transition( examples::E1::get_event_id(), s1, s2 );
state_machine->add_transition( examples::E2::get_event_id(), s2, s3 );
state_machine->add_transition( examples::E3::get_event_id(), s2, s4 );
#ifndef SX_CPP03_BOOST
state_machine->add_transition( sxy::Y_COMPLETION_EVENT_ID, s4, s3,
Y_BEHAVIOR_METHOD2( action_ptr, &examples::action::fire_event_E4 ) );
state_machine->add_transition( examples::E4::get_event_id(), s3, final,
Y_BEHAVIOR_METHOD2( action_ptr, &examples::action::print_message_from_event ) );
#else
state_machine->add_transition( sxy::Y_COMPLETION_EVENT_ID, s4, s3,
sxy::behavior_function( sxe::bind( &action::fire_event_E4, action_ptr, sxe::_1, sxe::_2 ) ) );
state_machine->add_transition( examples::E4::get_event_id(), s3, final,
sxy::behavior_function( sxe::bind( &action::print_message_from_event, action_ptr, sxe::_1 ) )
);
#endif
state_machine->add_transition( examples::E1::get_event_id(), s3, s2 );

return( sxe::move( state_machine ) );
return( state_machine );
}


Expand Down
12 changes: 6 additions & 6 deletions examples/event_collector_example/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@
#include "essentials/non_copyable.hpp"

#include "action.hpp"


namespace sxy
{


class sync_state_machine;
class sync_state_machine;


}


namespace examples
{
{


typedef sxe::SX_UNIQUE_PTR< sxy::sync_state_machine > state_machine_uptr;


class machine SX_FINAL
{
public:
{

public:
machine();
~machine() SX_NOEXCEPT;
SX_NO_COPY( machine )
Expand Down
Loading

0 comments on commit 5cf17b8

Please sign in to comment.