FACT++  1.0
StateMachineDim.h
Go to the documentation of this file.
1 #ifndef FACT_StateMachineDim
2 #define FACT_StateMachineDim
3 
4 // ***************************************************************************
11 // ***************************************************************************
12 #include "MessageDim.h" // MessageDimTX
13 
14 class DimLog
15 {
16  friend class StateMachineDim;
17 
19  DimLog(std::ostream &out, const std::string &name) : fLog(name, out) { }
20 };
21 
22 // ***************************************************************************
29 // ***************************************************************************
30 #include "DimErrorRedirecter.h"
31 
33 {
34  const bool fIsValidServer;
35 
36 protected:
37  DimStart(const std::string &name, MessageImp &imp) : DimErrorRedirecter(imp), fIsValidServer(!name.empty())
38  {
40  if (fIsValidServer)
41  {
42  DimServer::start(name.c_str());
43 
44  // Give some time to come up before
45  // the first log messages are sent
46  sleep(1);
47  }
48  }
50  {
51  if (!fIsValidServer)
52  return;
53 
54  // Give some time for pending log messages to be
55  // transmitted before the network is stopped
56  sleep(1);
58  }
59 };
60 
61 // ***************************************************************************
68 // ***************************************************************************
69 #include "StateMachine.h" // StateMachien
70 
71 class StateMachineDim : public DimCommandHandler, public DimInfoHandler, public DimLog, public DimStart, public StateMachineImp
72 {
73 private:
74  static const int fVersion;
75 
78 // DimService fSrvVersion; /// DimService offering fVersion
79 
80  void exitHandler(int code);
81  void commandHandler();
82  void infoHandler();
83 
84  EventImp *CreateEvent(const std::string &name, const std::string &fmt);
85  EventImp *CreateService(const std::string &name);
86 
87 protected:
90  std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
91 
92  void Lock();
93  void UnLock();
94 
95 public:
96  StateMachineDim(std::ostream &out=std::cout, const std::string &name="DEFAULT");
97 
99  int Write(const Time &time, const std::string &txt, int qos=kMessage);
100 
101  bool AddStateName(const int state, const std::string &name, const std::string &doc="");
102 
104 };
105 
106 #endif
DimStart(const std::string &name, MessageImp &imp)
DimDescribedService fDescriptionStates
Version number.
friend class StateMachineDim
A general base-class describing events issues in a state machine.
Definition: EventImp.h:11
DimLog(std::ostream &out, const std::string &name)
Base class for a state machine implementation.
A base class taking care of padding, exit handler and error handlers.
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
static const int fVersion
const bool fIsValidServer
static void stop()
Definition: discpp.cxx:545
DimDescribedService fSrvState
DimService propagating the state descriptions.
Based on MessageImp, redirects log-output to a Dim service MESSAGE.
Definition: MessageDim.h:10
uint16_t qos
Definition: HeadersGPS.h:29
bool MessageQueueEmpty() const
MessageDimTX fLog
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
Ensures that the MessageDimTX is initialized before errors could be redirected to it...
Ensures calling DimServer::start() in its constructor and DimServer::stop() in its destructor...
static void start()
Definition: discpp.cxx:512
Class for a state machine implementation within a DIM network.
bool MessageQueueEmpty() const
Definition: MessageDim.h:27
static void setNoDataCopy()
Definition: diccpp.cxx:1236