| 1 | #ifndef FACT_StateMachineDim
|
|---|
| 2 | #define FACT_StateMachineDim
|
|---|
| 3 |
|
|---|
| 4 | #include "MessageDim.h" // MessageDimTX
|
|---|
| 5 | #include "StateMachine.h" // StateMachien
|
|---|
| 6 |
|
|---|
| 7 | // ***************************************************************************
|
|---|
| 8 | /**
|
|---|
| 9 | @class DimStart
|
|---|
| 10 |
|
|---|
| 11 | @brief Ensures calling DimServer::start() in its constructor and DimServer::stop() in its destructor
|
|---|
| 12 |
|
|---|
| 13 | **/
|
|---|
| 14 | // ***************************************************************************
|
|---|
| 15 | #include "DimErrorRedirecter.h"
|
|---|
| 16 |
|
|---|
| 17 | class DimStart : public DimErrorRedirecter
|
|---|
| 18 | {
|
|---|
| 19 | protected:
|
|---|
| 20 | DimStart(const std::string &name, MessageImp &imp) : DimErrorRedirecter(imp)
|
|---|
| 21 | {
|
|---|
| 22 | DimServer::addErrorHandler(this);
|
|---|
| 23 | DimServer::start(name.c_str());
|
|---|
| 24 | }
|
|---|
| 25 | ~DimStart() { DimServer::stop(); }
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| 28 | class StateMachineDim : public DimCommandHandler, public DimExitHandler, public StateMachine, public DimStart
|
|---|
| 29 | {
|
|---|
| 30 | private:
|
|---|
| 31 | MessageDimTX fLog; /// Logging to the Dim network
|
|---|
| 32 |
|
|---|
| 33 | static const int fVersion; /// Version number
|
|---|
| 34 |
|
|---|
| 35 | DimDescribedService fDescriptionStates; /// DimService propagating the state descriptions
|
|---|
| 36 | DimDescribedService fSrvState; /// DimService offering fCurrentState
|
|---|
| 37 | // DimService fSrvVersion; /// DimService offering fVersion
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | void exitHandler(int code); /// Overwritten DimCommand::exitHandler.
|
|---|
| 41 | void commandHandler(); /// Overwritten DimCommand::commandHandler
|
|---|
| 42 |
|
|---|
| 43 | /// Redirect our own logging to fLog
|
|---|
| 44 | int Write(const Time &time, const std::string &txt, int qos);
|
|---|
| 45 |
|
|---|
| 46 | /// This is an internal function to do some action in case of
|
|---|
| 47 | /// a state change, like updating the corresponding service.
|
|---|
| 48 | std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
|
|---|
| 49 |
|
|---|
| 50 | EventImp *CreateEvent(int targetstate, const char *name, const char *fmt);
|
|---|
| 51 |
|
|---|
| 52 | public:
|
|---|
| 53 | StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT");
|
|---|
| 54 |
|
|---|
| 55 | void AddStateName(const int state, const std::string &name, const std::string &doc="");
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | #endif
|
|---|