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 | DimService fSrvState; /// DimService offering fCurrentState
|
---|
36 | DimService fSrvVersion; /// DimService offering fVersion
|
---|
37 |
|
---|
38 | void exitHandler(int code); /// Overwritten DimCommand::exitHandler.
|
---|
39 | void commandHandler(); /// Overwritten DimCommand::commandHandler
|
---|
40 |
|
---|
41 | /// Redirect our own logging to fLog
|
---|
42 | int Write(const Time &time, const char *txt, int qos);
|
---|
43 |
|
---|
44 | /// This is an internal function to do some action in case of
|
---|
45 | /// a state change, like updating the corresponding service.
|
---|
46 | std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
|
---|
47 |
|
---|
48 | EventImp *CreateEvent(int targetstate, const char *name, const char *fmt);
|
---|
49 |
|
---|
50 | public:
|
---|
51 | StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT");
|
---|
52 | };
|
---|
53 |
|
---|
54 | #endif
|
---|