FACT++  1.0
StateMachineDimControl.h
Go to the documentation of this file.
1 #ifndef FACT_StateMachineDimControl
2 #define FACT_StateMachineDimControl
3 
4 #include <set>
5 
6 #include "DimState.h"
7 #include "StateMachineDim.h"
8 
9 class Configuration;
10 
12 {
13  std::mutex fMutex;
14 
15  std::vector<DimDescriptions*> fDimDescriptionsList;
16 
17  std::set<std::string> fServerList;
18  std::set<Service> fServiceList;
19  std::map<std::string, std::vector<std::string>> fCommandList;
20  std::map<std::string, State> fCurrentStateList;
21  std::map<std::pair<std::string, int32_t>, std::pair<std::string, std::string>> fStateDescriptionList;
22  std::map<std::string, std::vector<Description>> fServiceDescriptionList;
23 
24  std::function<void(const std::string &, const State&)> fStateCallback;
25 
28 
30  bool fDebug;
31 
32  std::string fUser;
33  std::string fScriptUser;
34 
36  std::string fArgumentsJS;
37 
38  std::function<int(const EventImp &)> fInterruptHandler;
39 
40  std::string Line(const std::string &txt, char fill);
41 
42 public:
43  static bool fIsServer;
44 
45  int ChangeState(int qos, const Time &time, int scriptdepth, std::string scriptfile, std::string user);
46  int ChangeState(int state);
47 
48  int StartScript(const EventImp &imp, const std::string &cmd);
49  int StopScript(const EventImp &imp);
50  int InterruptScript(const EventImp &imp);
51 
52  int HandleStateChange(const std::string &server, DimDescriptions *state);
54  int HandleStates(const std::string &server, DimDescriptions *state);
55  int HandleServerAdd(const std::string &server);
56  int HandleServerRemove(const std::string &server);
57  int HandleAddService(const Service &svc);
58 
59  bool HasServer(const std::string &server);
60 
61  std::vector<std::string> GetServerList();
62  std::vector<std::string> GetCommandList(const std::string &server);
63  std::vector<std::string> GetCommandList();
64  std::vector<Description> GetDescription(const std::string &service);
65  std::vector<State> GetStates(const std::string &server);
66  std::set<Service> GetServiceList();
67 
68  int PrintStates(std::ostream &out, const std::string &serv="");
69  int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="");
70 
71  State GetServerState(const std::string &server);
72 
73  bool SendDimCommand(const std::string &server, std::string str, std::ostream &lout);
74 
75  void SetStateCallback(const std::function<void(const std::string &, const State &)> &func) { fStateCallback = func; }
76 
77  void SetInterruptHandler(const std::function<int(const EventImp &)> &func=std::function<int(const EventImp &)>()) { fInterruptHandler = func; }
78 
79  void Stop(int code=0);
80 
81 public:
82  StateMachineDimControl(std::ostream &out=std::cout);
84 
85  int EvalOptions(Configuration &conf);
86 };
87 
88 #endif
void Stop(int code=0)
Request to stop the mainloop.
void SetInterruptHandler(const std::function< int(const EventImp &)> &func=std::function< int(const EventImp &)>())
A general base-class describing events issues in a state machine.
Definition: EventImp.h:11
int HandleAddService(const Service &svc)
bool SendDimCommand(const std::string &server, std::string str, std::ostream &lout)
std::function< void(const std::string &, const State &)> fStateCallback
std::function< int(const EventImp &)> fInterruptHandler
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
int HandleStates(const std::string &server, DimDescriptions *state)
std::map< std::string, std::vector< std::string > > fCommandList
void SetStateCallback(const std::function< void(const std::string &, const State &)> &func)
int EvalOptions(Configuration &conf)
std::map< std::pair< std::string, int32_t >, std::pair< std::string, std::string > > fStateDescriptionList
StateMachineDimControl(std::ostream &out=std::cout)
int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="")
int HandleDescriptions(DimDescriptions *state)
int PrintStates(std::ostream &out, const std::string &serv="")
int HandleStateChange(const std::string &server, DimDescriptions *state)
std::map< std::string, State > fCurrentStateList
Definition: dis.c:69
uint16_t qos
Definition: HeadersGPS.h:29
std::set< Service > GetServiceList()
std::string fArgumentsJS
Default arguments provided to very java script.
std::map< std::string, std::vector< Description > > fServiceDescriptionList
std::vector< std::string > GetServerList()
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
Commandline parsing, resource file parsing and database access.
Definition: Configuration.h:9
State GetServerState(const std::string &server)
std::set< Service > fServiceList
int HandleServerRemove(const std::string &server)
int StartScript(const EventImp &imp, const std::string &cmd)
std::string Line(const std::string &txt, char fill)
int ChangeState(int qos, const Time &time, int scriptdepth, std::string scriptfile, std::string user)
std::vector< Description > GetDescription(const std::string &service)
int HandleServerAdd(const std::string &server)
Class for a state machine implementation within a DIM network.
std::vector< State > GetStates(const std::string &server)
std::vector< DimDescriptions * > fDimDescriptionsList
std::vector< std::string > GetCommandList()
int StopScript(const EventImp &imp)
int InterruptScript(const EventImp &imp)
bool HasServer(const std::string &server)
std::set< std::string > fServerList