mirror of
https://github.com/boostorg/msm.git
synced 2026-02-02 21:12:10 +00:00
merged revisions 72032-72035
[SVN r72036]
This commit is contained in:
@@ -27,7 +27,7 @@ namespace
|
||||
struct open_close {};
|
||||
|
||||
// A "complicated" event type that carries some data.
|
||||
enum DiskTypeEnum
|
||||
enum DiskTypeEnum
|
||||
{
|
||||
DISK_CD=0,
|
||||
DISK_DVD=1
|
||||
@@ -46,6 +46,17 @@ namespace
|
||||
// front-end: define the FSM structure
|
||||
struct player_ : public msm::front::state_machine_def<player_>
|
||||
{
|
||||
template <class Event,class FSM>
|
||||
void on_entry(Event const& ,FSM&)
|
||||
{
|
||||
std::cout << "entering: Player" << std::endl;
|
||||
}
|
||||
template <class Event,class FSM>
|
||||
void on_exit(Event const&,FSM& )
|
||||
{
|
||||
std::cout << "leaving: Player" << std::endl;
|
||||
}
|
||||
|
||||
// The list of FSM states
|
||||
struct Empty : public msm::front::state<>
|
||||
{
|
||||
@@ -56,7 +67,7 @@ namespace
|
||||
void on_exit(Event const&,FSM& ) {std::cout << "leaving: Empty" << std::endl;}
|
||||
};
|
||||
struct Open : public msm::front::state<>
|
||||
{
|
||||
{
|
||||
template <class Event,class FSM>
|
||||
void on_entry(Event const& ,FSM&) {std::cout << "entering: Open" << std::endl;}
|
||||
template <class Event,class FSM>
|
||||
@@ -65,7 +76,7 @@ namespace
|
||||
|
||||
// sm_ptr still supported but deprecated as functors are a much better way to do the same thing
|
||||
struct Stopped : public msm::front::state<msm::front::default_base_state,msm::front::sm_ptr>
|
||||
{
|
||||
{
|
||||
template <class Event,class FSM>
|
||||
void on_entry(Event const& ,FSM&) {std::cout << "entering: Stopped" << std::endl;}
|
||||
template <class Event,class FSM>
|
||||
@@ -102,7 +113,7 @@ namespace
|
||||
void pause_playback(pause const&) { std::cout << "player::pause_playback\n"; }
|
||||
void resume_playback(end_pause const&) { std::cout << "player::resume_playback\n"; }
|
||||
void stop_and_open(open_close const&) { std::cout << "player::stop_and_open\n"; }
|
||||
void stopped_again(stop const&){std::cout << "player::stopped_again\n";}
|
||||
void stopped_again(stop const&) {std::cout << "player::stopped_again\n";}
|
||||
// guard conditions
|
||||
bool good_disk_format(cd_detected const& evt)
|
||||
{
|
||||
@@ -125,7 +136,7 @@ namespace
|
||||
|
||||
// Transition table for player
|
||||
struct transition_table : mpl::vector<
|
||||
// Start Event Next Action Guard
|
||||
// Start Event Next Action Guard
|
||||
// +---------+-------------+---------+---------------------+----------------------+
|
||||
a_row < Stopped , play , Playing , &p::start_playback >,
|
||||
a_row < Stopped , open_close , Open , &p::open_drawer >,
|
||||
@@ -168,7 +179,7 @@ namespace
|
||||
|
||||
void test()
|
||||
{
|
||||
player p;
|
||||
player p;
|
||||
// needed to start the highest-level SM. This will call on_entry and mark the start of the SM
|
||||
p.start();
|
||||
// go to Open, call on_exit on Empty, then action, then on_entry on Open
|
||||
@@ -179,7 +190,7 @@ namespace
|
||||
cd_detected("louie, louie",DISK_DVD)); pstate(p);
|
||||
p.process_event(
|
||||
cd_detected("louie, louie",DISK_CD)); pstate(p);
|
||||
p.process_event(play());
|
||||
p.process_event(play());
|
||||
|
||||
// at this point, Play is active
|
||||
p.process_event(pause()); pstate(p);
|
||||
@@ -190,6 +201,8 @@ namespace
|
||||
// event leading to the same state
|
||||
// no action method called as it is not present in the transition table
|
||||
p.process_event(stop()); pstate(p);
|
||||
std::cout << "stop fsm" << std::endl;
|
||||
p.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user