git-svn-id: http://moon:8086/svn/software/trunk/projects/FsmEval@139 b431acfa-c32f-4a4a-93f1-934dc6c82436
134 lines
2.0 KiB
C++
134 lines
2.0 KiB
C++
/*
|
|
* File: FsmProcess.hpp
|
|
* Author: jens
|
|
*
|
|
* Created on 24. Januar 2015, 15:45
|
|
*/
|
|
|
|
#ifndef FSMPROCESS_HPP
|
|
#define FSMPROCESS_HPP
|
|
|
|
#include "AStateMachine.hpp"
|
|
|
|
typedef struct {} Mode0;
|
|
typedef struct {} Mode1;
|
|
|
|
class Context
|
|
{
|
|
public:
|
|
Context()
|
|
: m_count(0)
|
|
{
|
|
|
|
}
|
|
|
|
~Context() {}
|
|
|
|
int m_count;
|
|
|
|
};
|
|
class IFsmProcess
|
|
{
|
|
public:
|
|
|
|
enum StateId
|
|
{
|
|
INIT=0,
|
|
IDLE,
|
|
ACTIVE_0,
|
|
ACTIVE_1,
|
|
NUM_STATES
|
|
};
|
|
|
|
IFsmProcess()
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~IFsmProcess()
|
|
{
|
|
|
|
}
|
|
|
|
virtual void process(int x)
|
|
{
|
|
printf("%s() x=%d\n", __PRETTY_FUNCTION__, x);
|
|
}
|
|
|
|
};
|
|
|
|
template <class modeType>
|
|
class FsmProcess : public AStateMachine<IFsmProcess::StateId>
|
|
{
|
|
public:
|
|
|
|
FsmProcess(Context &context);
|
|
~FsmProcess();
|
|
void process(int x);
|
|
|
|
private:
|
|
class StateInit : public AState<IFsmProcess::StateId>, public IFsmProcess
|
|
{
|
|
public:
|
|
StateInit(IFsmProcess::StateId id, Context &context);
|
|
~StateInit();
|
|
|
|
// Transition to Init is reset
|
|
void onTransition();
|
|
void process(int x);
|
|
|
|
private:
|
|
Context &m_context;
|
|
};
|
|
|
|
class StateIdle : public AState<IFsmProcess::StateId>, public IFsmProcess
|
|
{
|
|
public:
|
|
StateIdle(IFsmProcess::StateId id, Context &context);
|
|
~StateIdle();
|
|
|
|
void onTransition();
|
|
void process(int x);
|
|
|
|
private:
|
|
Context &m_context;
|
|
};
|
|
|
|
class StateActive0 : public AState<IFsmProcess::StateId>, public IFsmProcess
|
|
{
|
|
public:
|
|
StateActive0(IFsmProcess::StateId id, Context &context);
|
|
~StateActive0();
|
|
|
|
void onTransition();
|
|
void process(int x);
|
|
|
|
private:
|
|
Context &m_context;
|
|
};
|
|
|
|
class StateActive1 : public AState<IFsmProcess::StateId>, public IFsmProcess
|
|
{
|
|
public:
|
|
StateActive1(IFsmProcess::StateId id, Context &context);
|
|
~StateActive1();
|
|
|
|
void onTransition();
|
|
void process(int x);
|
|
|
|
private:
|
|
Context &m_context;
|
|
};
|
|
|
|
StateInit init;
|
|
StateIdle idle;
|
|
StateActive0 active0;
|
|
StateActive1 active1;
|
|
|
|
};
|
|
#include "FsmProcess.tcc"
|
|
|
|
|
|
#endif /* FSMPROCESS_HPP */
|
|
|