source: branches/FACT++_lidctrl_usb/src/DimServiceInfoList.h@ 18716

Last change on this file since 18716 was 13836, checked in by tbretz, 12 years ago
Added some workaround to make these classes not derive from DimInfoHandler - this clashes with the new StateMachineDim -- this must be fixed, it is still asnychronous with the event loop\!
File size: 8.1 KB
Line 
1#ifndef FACT_DimServiceInfoList
2#define FACT_DimServiceInfoList
3
4#include <map>
5#include <vector>
6#include <string>
7
8#include "State.h"
9#include "Description.h"
10#include "DimServerList.h"
11
12class DimInfo;
13class DimServiceInfoListImp;
14
15class DimServiceInfoList : public DimServerList
16{
17public:
18
19 typedef std::map<const std::string, std::vector<DimInfo*>> ServiceInfoList;
20
21 // Format IsCmd
22 typedef std::pair<std::string, bool> ServiceType;
23
24 // name of service Format/description
25 typedef std::map<const std::string, ServiceType> TypeList;
26
27 // ServiceName comment list of descriptions
28 typedef std::map<const std::string, std::pair<std::string, std::vector<Description>>> DescriptionList;
29
30 struct ServerInfo
31 {
32 TypeList first; /// Format and description of the service
33 DescriptionList second; /// Description of the arguments
34 std::vector<State> third; /// Available states of the server
35 };
36
37 // Server ServerInfo
38 typedef std::map<const std::string, ServerInfo> ServiceList;
39
40private:
41 DimServiceInfoListImp *fList;
42 ServiceInfoList fServiceInfoList; /// A map storing the service description to retrieve all informations
43 ServiceList fServiceList; /// A mal containing all the available informations
44
45 DimInfo *CreateDimInfo(const std::string &str, const std::string &svc) const;
46 DimInfo *CreateSL(const std::string &str) const { return CreateDimInfo(str, "SERVICE_LIST"); }
47 DimInfo *CreateFMT(const std::string &str) const { return CreateDimInfo(str, "SERVICE_DESC"); }
48 DimInfo *CreateDS(const std::string &str) const { return CreateDimInfo(str, "STATE_LIST"); }
49
50public:
51 void AddServer(const std::string &s);
52 void RemoveServer(std::string);
53 void RemoveAllServers();
54
55protected:
56 void infoHandler();
57
58public:
59 DimServiceInfoList(DimServiceInfoListImp *list);
60 ~DimServiceInfoList() { }
61
62 std::vector<std::string> GetServiceList(bool iscmd=false) const;
63 std::vector<std::string> GetServiceList(const std::string &server, bool iscmd=false) const;
64
65 std::vector<Description> GetDescription(const std::string &server, const std::string &service) const;
66 std::vector<State> GetStates(const std::string &server) const;
67 State GetState(const std::string &server, int state) const;
68
69 int IsCommand(const std::string &server, const std::string &service) const;
70
71 int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="") const;
72 int PrintStates(std::ostream &out, const std::string &serv="") const;
73
74 bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const;
75 void SendDimCommand(const std::string &server, std::string str, std::ostream &lout) const;
76 void SendDimCommand(const std::string &server, const std::string &str) const;
77};
78
79class DimServiceInfoListImp : public DimServerListImp
80{
81public:
82 DimServiceInfoList fInfo;
83
84protected:
85 virtual void AddServer(const std::string &s) { fInfo.AddServer(s); }
86 virtual void RemoveServer(std::string s) { fInfo.RemoveServer(s); }
87 virtual void RemoveAllServers() { fInfo.RemoveAllServers(); }
88
89public:
90 virtual void AddService(const std::string &, const std::string &, const std::string &, bool) { }
91 virtual void RemoveService(std::string, std::string, bool) { }
92 virtual void RemoveAllServices(const std::string &) { }
93 virtual void AddDescription(const std::string &, const std::string &, const std::vector<Description> &) { }
94 virtual void AddStates(const std::string &, const std::vector<State> &) { }
95
96public:
97 DimServiceInfoListImp() : fInfo(this) { }
98 ~DimServiceInfoListImp() { fInfo.RemoveAllServers(); }
99
100 std::vector<std::string> GetServiceList(bool iscmd=false) const
101 { return fInfo.GetServiceList(iscmd); }
102 std::vector<std::string> GetServiceList(const std::string &server, bool iscmd=false) const
103 { return fInfo.GetServiceList(server, iscmd); }
104
105 std::vector<std::string> GetCommandList() const { return GetServiceList(true); }
106 std::vector<std::string> GetCommandList(const std::string &server) const { return GetServiceList(server, true); }
107
108 std::vector<Description> GetDescription(const std::string &server, const std::string &service) const
109 { return fInfo.GetDescription(server, service); }
110 std::vector<State> GetStates(const std::string &server) const
111 { return fInfo.GetStates(server); }
112 State GetState(const std::string &server, int state) const
113 { return fInfo.GetState(server, state); }
114
115 int IsCommand(const std::string &server, const std::string &service) const
116 { return fInfo.IsCommand(server, service); }
117
118 int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="") const
119 { return fInfo.PrintDescription(out, iscmd, serv, service); }
120 int PrintStates(std::ostream &out, const std::string &serv="") const
121 { return fInfo.PrintStates(out, serv); }
122
123 bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const
124 { return fInfo.SendDimCommand(lout, server, str); }
125 void SendDimCommand(const std::string &server, std::string str, std::ostream &lout) const
126 { return fInfo.SendDimCommand(server, str, lout); }
127 void SendDimCommand(const std::string &server, const std::string &str) const
128 { return fInfo.SendDimCommand(server, str); }
129};
130
131
132
133// ***************************************************************************
134/** @fn DimServiceInfoList::AddService(const std::string &server, const std::string &service, const std::string &fmt, bool iscmd)
135
136This virtual function is called as a callback whenever a new service appears.
137The default is to do nothing.
138
139@param server
140 Server name of the server at which the new service appeared
141
142@param service
143 Service name which appeared
144
145@param fmt
146 Dim format string associated with the service
147
148@param iscmd
149 boolean which is true if it is a command, and false if it is a service
150
151
152**/
153// ***************************************************************************
154/** @fn DimServiceInfoList::RemoveService(const std::string &server, const std::string &service, bool iscmd)
155
156This virtual function is called as a callback whenever a service disappears.
157The default is to do nothing.
158
159@param server
160 Server name of the server at which the new service appeared
161
162@param service
163 Service name which appeared
164
165@param iscmd
166 boolean which is true if it is a command, and false if it is a service
167
168
169**/
170// ***************************************************************************
171/** @fn DimServiceInfoList::RemoveAllServices(const std::string &server)
172
173This virtual function is called as a callback whenever a server disappears,
174or the list must be cleared because a new list has been retrieved.
175The default is to do nothing.
176
177@param server
178 Server name of the server at which the new service appeared
179
180
181**/
182// ***************************************************************************
183/** @fn DimServiceInfoList::AddDescription(const std::string &server, const std::string &service, const std::vector<Description> &vec)
184
185This virtual function is called as a callback whenever a new description
186was received.
187The default is to do nothing.
188
189@param server
190 Server name of the server for which something was received
191
192@param service
193 Service name for which the description weer received
194
195@param vec
196 vector<Description> associated with this service. The first entry in the
197 list belongs to the service itself, each consecutive entry to its arguments
198
199
200**/
201// ***************************************************************************
202/** @fn DimServiceInfoList::AddStates(const std::string &server, const std::vector<State> &vec)
203
204This virtual function is called as a callback whenever a new list of states
205was received.
206The default is to do nothing.
207
208@param server
209 Server name for which the list was received
210
211@param vec
212 vector<State> associated with this server.
213
214**/
215// ***************************************************************************
216
217#endif
Note: See TracBrowser for help on using the repository browser.