source: trunk/FACT++/src/StateMachineDim.h@ 13219

Last change on this file since 13219 was 11397, checked in by tbretz, 13 years ago
Made write public to be accessed from Main.h
File size: 2.6 KB
Line 
1#ifndef FACT_StateMachineDim
2#define FACT_StateMachineDim
3
4// ***************************************************************************
5/**
6 @class DimLog
7
8 @brief Ensures that the MessageDimTX is initialized before errors could be redirected to it
9
10**/
11// ***************************************************************************
12#include "MessageDim.h" // MessageDimTX
13
14class DimLog
15{
16 friend class StateMachineDim;
17
18 MessageDimTX fLog;
19 DimLog(std::ostream &out, const std::string &name) : fLog(name, out) { }
20};
21
22// ***************************************************************************
23/**
24 @class DimStart
25
26 @brief Ensures calling DimServer::start() in its constructor and DimServer::stop() in its destructor
27
28**/
29// ***************************************************************************
30#include "DimErrorRedirecter.h"
31
32class DimStart : public DimErrorRedirecter
33{
34protected:
35 DimStart(const std::string &name, MessageImp &imp) : DimErrorRedirecter(imp)
36 {
37 DimServer::start(name.c_str());
38 sleep(1);
39 }
40 ~DimStart()
41 {
42 DimServer::stop();
43 }
44};
45
46// ***************************************************************************
47/**
48 @class StateMachineDim
49
50 @brief Class for a state machine implementation within a DIM network
51
52**/
53// ***************************************************************************
54#include "StateMachine.h" // StateMachien
55
56class StateMachineDim : public DimCommandHandler, public DimLog, public DimStart, public StateMachineImp
57{
58private:
59 static const int fVersion; /// Version number
60
61 DimDescribedService fDescriptionStates; /// DimService propagating the state descriptions
62 DimDescribedService fSrvState; /// DimService offering fCurrentState
63// DimService fSrvVersion; /// DimService offering fVersion
64
65
66 void exitHandler(int code); /// Overwritten DimCommand::exitHandler.
67 void commandHandler(); /// Overwritten DimCommand::commandHandler
68
69 EventImp *CreateEvent(int targetstate, const char *name, const char *fmt);
70
71protected:
72 /// This is an internal function to do some action in case of
73 /// a state change, like updating the corresponding service.
74 std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
75
76 void Lock();
77 void UnLock();
78
79public:
80 StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT");
81
82 /// Redirect our own logging to fLog
83 int Write(const Time &time, const std::string &txt, int qos=kMessage);
84
85 void AddStateName(const int state, const std::string &name, const std::string &doc="");
86};
87
88#endif
Note: See TracBrowser for help on using the repository browser.