FACT++  1.0
void ServiceList::ProcessServerList ( )
private

This function processes the update of the DIS_DNS/SERVER_LIST update. After this function the server list should be up-to-date again.

For each new server a SERVER/SERVICE_LIST service subscription is created and stored in the fServerList. For each removed server the corresponding object are deleted, as well as the corresponding entries from the fServiceList.

Definition at line 149 of file ServiceList.cc.

References buffer, CreateFMT(), CreateSL(), fDimServers, fServerList, fServiceList, Time::GetAsStr(), DimInfo::getString(), i, kRed, str, and wout.

Referenced by CreateFMT(), and infoHandler().

150 {
151  // Get the received string from the handler
152  const string str = fDimServers.getString();
153 
154  // Check if it starts with + or -
155  if (str[0]!='-' && str[0]!='+')
156  {
157  // If it doesn't start with + or - remove all existing servers
158  // we have received a full server list
159  for (ServerMap::iterator i=fServerList.begin(); i!=fServerList.end(); i++)
160  {
161  delete i->second.first;
162  delete i->second.second;
163 
164  ServiceMap::iterator x = fServiceList.find(i->first);
165  fServiceList.erase(x);
166  //wout << "Delete: " << i->first << endl;
167  }
168 
169  fServerList.clear();
170  }
171 
172  // Create a stringstream to tokenize the received string
173  stringstream stream(str);
174 
175  // Loop over the seperating tokens
176  string buffer;
177  while (getline(stream, buffer, '|'))
178  {
179  // The first part before the first @ is the server name
180  const string server = buffer.substr(0, buffer.find_first_of('@'));
181  if (server.empty())
182  continue;
183 
184  // If it starts with a - we have to remove an entry
185  if (server[0]=='-')
186  {
187  const string trunc = server.substr(1);
188 
189  // Check if this server is not found in the list.
190  // This should never happen if Dim works reliable
191  const ServerMap::iterator v = fServerList.find(trunc);
192  if (v==fServerList.end())
193  {
194  wout << kRed << "Server '" << trunc << "' not in list as it ought to be." << endl;
195  continue;
196  }
197 
198  // Remove the server from the server list
199  delete v->second.first;
200  delete v->second.second;
201  fServerList.erase(v);
202 
203  // Remove the server from the command list
204  ServiceMap::iterator w = fServiceList.find(trunc);
205  fServiceList.erase(w);
206 
207  wout << " -> " << Time().GetAsStr() << " - " << trunc << "/SERVICE_LIST: Disconnected." << endl;
208  //wout << "Remove: " << server << endl;
209  continue;
210  }
211 
212  // If it starts with a + we have to add an entry
213  if (server[0]=='+')
214  {
215  const string trunc = server.substr(1);
216 
217  // Check if this server is already in the list.
218  // This should never happen if Dim works reliable
219  const ServerMap::iterator v = fServerList.find(trunc);
220  if (v!=fServerList.end())
221  {
222  wout << kRed << "Server '" << trunc << "' in list not as it ought to be." << endl;
223  continue;
224  }
225 
226  // Add the new server to the server list
227  fServerList[trunc] = make_pair(CreateSL(trunc), CreateFMT(trunc));
228 
229  wout << " -> " << Time().GetAsStr() << " - " << trunc << "/SERVICE_LIST: Connected." << endl;
230  //wout << "Add : " << server << endl;
231  continue;
232  }
233 
234  // In any other case we just add the entry to the list
235  fServerList[server] = make_pair(CreateSL(server), CreateFMT(server));
236  //wout << "Add 0: " << server << endl;
237  }
238 }
char * getString()
Definition: dic.hxx:108
ServerMap fServerList
A filter for the type of the services to be collected, e.g. CMD.
Definition: ServiceList.h:29
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
Set color Red.
Definition: WindowLog.h:17
ServiceMap fServiceList
A map storing server names and a DimInfo for their SERVICE_LIST.
Definition: ServiceList.h:30
DimInfo fDimServers
stream for redirection of the output
Definition: ServiceList.h:25
DimInfo * CreateFMT(const std::string &str) const
Definition: ServiceList.h:40
std::ostream & wout
Definition: ServiceList.h:23
DimInfo * CreateSL(const std::string &str) const
Definition: ServiceList.h:39
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240

+ Here is the call graph for this function:

+ Here is the caller graph for this function: