// Copyright 2010 Christophe Henry // henry UNDERSCORE christophe AT hotmail DOT com // This is an extended version of the state machine available in the boost::mpl library // Distributed under the same license as the original. // Copyright for the original version: // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed // under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // back-end #include "BackCommon.hpp" //front-end #include #include #ifndef BOOST_MSM_NONSTANDALONE_TEST #define BOOST_TEST_MODULE orthogonal_deferred_euml_test #endif #include namespace msm = boost::msm; namespace mpl = boost::mpl; using namespace boost::msm::front::euml; namespace { // events BOOST_MSM_EUML_EVENT(play) BOOST_MSM_EUML_EVENT(end_pause) BOOST_MSM_EUML_EVENT(stop) BOOST_MSM_EUML_EVENT(pause) BOOST_MSM_EUML_EVENT(open_close) BOOST_MSM_EUML_EVENT(next_song) BOOST_MSM_EUML_EVENT(previous_song) BOOST_MSM_EUML_EVENT(error_found) BOOST_MSM_EUML_EVENT(end_error) BOOST_MSM_EUML_EVENT(do_terminate) // Flags. Allow information about a property of the current state BOOST_MSM_EUML_FLAG(PlayingPaused) BOOST_MSM_EUML_FLAG(CDLoaded) BOOST_MSM_EUML_FLAG(FirstSongPlaying) // A "complicated" event type that carries some data. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(std::string,cd_name) BOOST_MSM_EUML_ATTRIBUTES((attributes_ << cd_name ), cd_detected_attributes) BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(cd_detected,cd_detected_attributes) //states BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,entry_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,exit_counter) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter), attributes_ << entry_counter << exit_counter, configure_ << play),Empty) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter), attributes_ << entry_counter << exit_counter, configure_<< CDLoaded << play),Open) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter), attributes_ << entry_counter << exit_counter, configure_<< CDLoaded),Stopped) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter), attributes_ << entry_counter << exit_counter, configure_<< CDLoaded << PlayingPaused),Paused) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter),attributes_ << entry_counter << exit_counter),AllOk) BOOST_MSM_EUML_TERMINATE_STATE(( ++state_(entry_counter),++state_(exit_counter),attributes_ << entry_counter << exit_counter), ErrorTerminate) BOOST_MSM_EUML_INTERRUPT_STATE(( end_error,++state_(entry_counter),++state_(exit_counter),attributes_ << entry_counter << exit_counter), ErrorMode) // State machine attributes. BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,start_playback_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,can_close_drawer_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,report_error_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,report_end_error_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,start_next_song_counter) BOOST_MSM_EUML_DECLARE_ATTRIBUTE(unsigned int,start_prev_song_guard_counter) // Playing is now a state machine itself. BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter), attributes_ << entry_counter << exit_counter, configure_<< FirstSongPlaying ),Song1) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter),attributes_ << entry_counter << exit_counter),Song2) BOOST_MSM_EUML_STATE(( ++state_(entry_counter),++state_(exit_counter),attributes_ << entry_counter << exit_counter),Song3) template