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

Last change on this file since 11302 was 11280, checked in by tbretz, 13 years ago
Added virtual function for locking; fixed the order of instantiation of the base classes of StateMachineDim.
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 }
39 ~DimStart()
40 {
41 DimServer::stop();
42 }
43};
44
45// ***************************************************************************
46/**
47 @class StateMachineDim
48
49 @brief Class for a state machine implementation within a DIM network
50
51**/
52// ***************************************************************************
53#include "StateMachine.h" // StateMachien
54
55class StateMachineDim : public DimCommandHandler, public DimLog, public DimStart, public StateMachineImp
56{
57private:
58 static const int fVersion; /// Version number
59
60 DimDescribedService fDescriptionStates; /// DimService propagating the state descriptions
61 DimDescribedService fSrvState; /// DimService offering fCurrentState
62// DimService fSrvVersion; /// DimService offering fVersion
63
64
65 void exitHandler(int code); /// Overwritten DimCommand::exitHandler.
66 void commandHandler(); /// Overwritten DimCommand::commandHandler
67
68 /// Redirect our own logging to fLog
69 int Write(const Time &time, const std::string &txt, int qos);
70
71 EventImp *CreateEvent(int targetstate, const char *name, const char *fmt);
72
73protected:
74 /// This is an internal function to do some action in case of
75 /// a state change, like updating the corresponding service.
76 std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
77
78 void Lock();
79 void UnLock();
80
81public:
82 StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT");
83
84 void AddStateName(const int state, const std::string &name, const std::string &doc="");
85};
86
87#endif
Note: See TracBrowser for help on using the repository browser.