FACT++  1.0
void DimServiceInfoList::infoHandler ( )
protectedvirtual

This function processes the update of the SERVICE_LIST, SERVICE_DESC, and STATE_LIST updates.

Whenever a service is added or removed or all services of a server are removed (the list is newly sent completely) the virtual functions AddService(), RemoveService() and RemoveAllServices() aee called.

If a new description or a new state is added, the virtual functions AddDescription() and AddStates() respectively are called.

Reimplemented from DimServerList.

Definition at line 170 of file DimServiceInfoList.cc.

References buffer, Description::SplitDescription(), State::SplitStates(), str, and type.

Referenced by CreateDS().

171 {
172  // Get the name of the service
173  const string svc = getInfo()->getName();
174 
175  // Get the server name from the service name
176  const string server = svc.substr(0, svc.find_first_of('/'));
177  const string service = svc.substr(svc.find_first_of('/')+1);
178 
179  if (service=="SERVICE_LIST")
180  {
181  // For easy and fast access get the corresponding reference
182  TypeList &list = fServiceList[server].first;
183 
184  const string str = getInfo()->getString();
185 
186  // WHAT's THIS???
187  if (str.length()==0)
188  return;
189 
190  // Initialize the entry with an empty list
191  if (str[0]!='+' && str[0]!='-')
192  {
193  fList->RemoveAllServices(server);
194  list.clear();
195  }
196 
197  string buffer;
198 
199  // Tokenize the stream into lines
200  stringstream stream(str);
201  while (getline(stream, buffer, '\n'))
202  {
203  if (buffer.empty())
204  continue;
205 
206  // Get the type and compare it with fType
207  const string type = buffer.substr(buffer.find_last_of('|')+1);
208  if (type=="RPC")
209  continue;
210 
211  /*
212  const bool iscmd = type=="CMD";
213  if (type!=fType && fType!="*")
214  continue;
215  */
216 
217  // Get format, name and command name
218  const string fmt = buffer.substr(buffer.find_first_of('|')+1, buffer.find_last_of('|')-buffer.find_first_of('|')-1);
219  const string name = buffer.substr(buffer.find_first_of('/')+1, buffer.find_first_of('|')-buffer.find_first_of('/')-1);
220  //const string cmd = buffer.substr(0, buffer.find_first_of('|'));
221 
222  const bool iscmd = type=="CMD";
223 
224  // FIXME: Do we need to check that the buffer starts with SERVER ?
225 
226  if (buffer[0]=='-')
227  {
228  // Check if this server is not found in the list.
229  // This should never happen if Dim works reliable
230  const TypeList::iterator v = list.find(name);
231  /*
232  if (v==list.end())
233  {
234  stringstream err;
235  err << "DimServiceInfoList: Service '" << server << "/" << name << "' not in list as it ought to be.";
236  // Seems to happen why more than one client is subscribed
237  // and e.g. the datalogger is immediately quit
238  throw runtime_error(err.str());
239  }*/
240 
241  fList->RemoveService(server, name, iscmd);
242  if (v!=list.end())
243  list.erase(v);
244 
245  continue;
246  }
247 
248  if (buffer[0]=='+')
249  {
250  // Check if this server is not found in the list.
251  // This should never happen if Dim works reliable
252  const TypeList::iterator v = list.find(name);
253  if (v!=list.end())
254  {
255  stringstream err;
256  err << "DimServiceInfoList: Service '" << server << "/" << name << "' already in list not as it ought to be.";
257  throw runtime_error(err.str());
258  }
259 
260  list[name] = make_pair(fmt, iscmd);
261  fList->AddService(server, name, fmt, iscmd);
262 
263  continue;
264  }
265 
266  // Add name the the list
267  list[name] = make_pair(fmt, iscmd);
268  fList->AddService(server, name, fmt, iscmd);
269  }
270 
271  return;
272  }
273 
274  if (service=="SERVICE_DESC")
275  {
276  // For easy and fast access get the corresponding reference
277  DescriptionList &list = fServiceList[server].second;
278 
279  list.clear();
280 
281  string buffer;
282 
283  stringstream stream(getInfo()->getString());
284  while (getline(stream, buffer, '\n'))
285  {
286  if (buffer.empty())
287  continue;
288 
289  const vector<Description> v = Description::SplitDescription(buffer);
290 
291  const string name = v[0].name.substr(v[0].name.find_first_of('/')+1);
292  const string comment = v[0].comment;
293 
294  list[name] = make_pair(comment, vector<Description>(v.begin()+1, v.end()));
295 
296  fList->AddDescription(server, name, v);
297  }
298 
299  return;
300  }
301 
302  if (service=="STATE_LIST")
303  {
304  vector<State> &vec = fServiceList[server].third;
305  vec = State::SplitStates(getInfo()->getString());
306  fList->AddStates(server, vec);
307 
308  return;
309  }
310 }
char * getString()
Definition: dic.hxx:108
virtual void AddDescription(const std::string &, const std::string &, const std::vector< Description > &)
std::map< const std::string, ServiceType > TypeList
ServiceList fServiceList
A map storing the service description to retrieve all informations.
char str[80]
Definition: test_client.c:7
std::map< const std::string, std::pair< std::string, std::vector< Description > > > DescriptionList
virtual void RemoveAllServices(const std::string &)
DimServiceInfoListImp * fList
int type
virtual void RemoveService(std::string, std::string, bool)
static std::vector< Description > SplitDescription(const std::string &buffer)
Definition: Description.cc:82
virtual void AddStates(const std::string &, const std::vector< State > &)
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
virtual void AddService(const std::string &, const std::string &, const std::string &, bool)
DimInfo * getInfo()
Definition: dic.hxx:26
static std::vector< State > SplitStates(const std::string &buffer)
Time of state change.
Definition: State.cc:58
char * getName()
Definition: dic.hxx:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function: