#ifndef __INCLUDE_STATEMACHINE_H__
#define __INCLUDE_STATEMACHINE_H__
/* INCLUDES */
#include <string.h>
#include <iostream>
#include <./boost/statechart/event.hpp>
#include <./boost/statechart/custom_reaction.hpp>
#include <./boost/statechart/state_machine.hpp>
#include <./boost/statechart/simple_state.hpp>
#include <./boost/statechart/transition.hpp>
#include <./boost/mpl/list.hpp>
using namespace std;
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
// Elevator events
struct EventGoUp : sc::event< EventGoUp > {};
struct EventGoDown : sc::event< EventGoDown > {};
struct EventStopAtFloor : sc::event< EventStopAtFloor > {};
struct EventObstructionOn : sc::event< EventObstructionOn > {};
struct EventObstructionOff : sc::event< EventObstructionOff > {};
struct EventEmergency : sc::event< EventEmergency > {};
// Elevator states
struct ElevatorActive;
struct ElevatorIdle;
struct ElevatorGoingUp;
struct ElevatorGoingDown;
struct ElevatorStopAtFloor;
struct ElevatorEmergency;
struct ElevatorObstruction;
class Elevator{
public:
Elevator(){};
void test123(){
cout << "This works" << endl;
}
private:
};
// Create state machine, use ElevatorActive as initial state
struct ElevatorSM : sc::state_machine< ElevatorSM, ElevatorActive >
{
Elevator* e;
ElevatorSM(Elevator* ePtr) : e(ePtr) {};
};
// Implement ElevatorActive state
struct ElevatorActive : sc::simple_state< ElevatorActive, ElevatorSM, ElevatorIdle >
{
//Incluce elevator initialization sequence
ElevatorActive();
~ElevatorActive();
};
// Implement ElevatorIdle state
struct ElevatorIdle : sc::simple_state< ElevatorIdle, ElevatorActive >
{
typedef mpl::list<
sc::transition < EventGoUp, ElevatorGoingUp >,
sc::transition < EventGoDown, ElevatorGoingDown >,
sc::transition < EventStopAtFloor, ElevatorStopAtFloor >,
sc::transition < EventObstructionOn, ElevatorObstruction >,
sc::transition < EventEmergency, ElevatorEmergency >
> reactions;
ElevatorIdle();
~ElevatorIdle();
};
// Implement ElevatorGoingUp state
struct ElevatorGoingUp : sc::simple_state< ElevatorGoingUp, ElevatorActive >
{
typedef mpl::list<
sc::transition < EventStopAtFloor, ElevatorStopAtFloor >,
sc::transition < EventObstructionOn, ElevatorObstruction >,
sc::transition < EventEmergency, ElevatorEmergency >
> reactions;
ElevatorGoingUp();
~ElevatorGoingUp();
};
// Implement ElevatorGoingDown state
struct ElevatorGoingDown : sc::simple_state< ElevatorGoingDown, ElevatorActive >
{
typedef mpl::list<
sc::transition < EventStopAtFloor, ElevatorStopAtFloor >,
sc::transition < EventObstructionOn, ElevatorObstruction >,
sc::transition < EventEmergency, ElevatorEmergency >
> reactions;
ElevatorGoingDown();
~ElevatorGoingDown();
};
// Implement ElevatorStopAtFloor state
struct ElevatorStopAtFloor : sc::simple_state< ElevatorStopAtFloor, ElevatorActive >
{
typedef mpl::list<
sc::transition < EventObstructionOn, ElevatorObstruction >,
sc::transition < EventEmergency, ElevatorEmergency >
> reactions;
ElevatorStopAtFloor();
~ElevatorStopAtFloor();
};
// Implement ElevatorEmergency state
struct ElevatorEmergency : sc::simple_state< ElevatorEmergency, ElevatorActive >
{
typedef mpl::list<
sc::transition < EventGoUp, ElevatorGoingUp >,
sc::transition < EventGoDown, ElevatorGoingDown >
> reactions;
ElevatorEmergency();
~ElevatorEmergency();
};
// Implement ElevatorObstruction state
struct ElevatorObstruction : sc::simple_state< ElevatorObstruction, ElevatorActive >
{
typedef mpl::list<
//sc::custom_reaction < EventObstructionOff >,
sc::transition < EventEmergency, ElevatorEmergency >
> reactions;
ElevatorObstruction();
~ElevatorObstruction();
sc::result react( const EventObstructionOff & );
};
#endif