Changeset 10298
- Timestamp:
- 04/07/11 12:35:43 (14 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ServiceList.cc
r10289 r10298 87 87 { 88 88 for (ServerMap::iterator i=fServerList.begin(); i!=fServerList.end(); i++) 89 delete i->second; 89 { 90 delete i->second.first; 91 delete i->second.second; 92 } 90 93 } 91 94 … … 108 111 109 112 if (fHandler) 113 { 114 fHandler->itsService = 0; 110 115 fHandler->infoHandler(); 116 } 111 117 } 112 118 … … 121 127 //! a pointer to the newly created DimInfo 122 128 //! 123 DimInfo *ServiceList::CreateDimInfo(const string &str ) const124 { 125 return new DimInfo((str+"/ SERVICE_LIST").c_str(),129 DimInfo *ServiceList::CreateDimInfo(const string &str, const string &svc) const 130 { 131 return new DimInfo((str+"/"+svc).c_str(), 126 132 const_cast<char*>(""), 127 133 const_cast<ServiceList*>(this)); … … 150 156 for (ServerMap::iterator i=fServerList.begin(); i!=fServerList.end(); i++) 151 157 { 152 delete i->second; 158 delete i->second.first; 159 delete i->second.second; 153 160 154 161 ServiceMap::iterator x = fServiceList.find(i->first); … … 156 163 //wout << "Delete: " << i->first << endl; 157 164 } 165 158 166 fServerList.clear(); 159 167 } … … 186 194 187 195 // Remove the server from the server list 188 delete v->second; 196 delete v->second.first; 197 delete v->second.second; 189 198 fServerList.erase(v); 190 199 … … 213 222 214 223 // Add the new server to the server list 215 fServerList[trunc] = CreateDimInfo(trunc);224 fServerList[trunc] = make_pair(CreateSL(trunc), CreateFMT(trunc)); 216 225 217 226 wout << " -> " << Time().GetAsStr() << " - " << trunc << "/SERVICE_LIST: Connected." << endl; … … 221 230 222 231 // In any other case we just add the entry to the list 223 fServerList[server] = CreateDimInfo(server);232 fServerList[server] = make_pair(CreateSL(server), CreateFMT(server)); 224 233 //wout << "Add 0: " << server << endl; 225 234 } … … 251 260 string buffer = info.getName(); 252 261 253 // Get the server name from the service name 254 const string server = buffer.substr(0, buffer.find_first_of('/')); 255 256 // Initialize the entry with an empty list 257 if (str[0]!='+') 258 fServiceList[server] = vector<string>(); 259 260 // For easy and fast access get the corresponding reference 261 vector<string> &list = fServiceList[server]; 262 263 // Tokenize the stream into lines 264 stringstream stream(str); 265 while (getline(stream, buffer, '\n')) 266 { 267 if (buffer.empty()) 268 continue; 269 270 // Get the type and compare it with fType 271 const string type = buffer.substr(buffer.find_last_of('|')+1); 272 if (type!=fType) 273 continue; 274 275 // Get format, name and command name 276 const string fmt = buffer.substr(buffer.find_first_of('|')+1, buffer.find_last_of('|')-buffer.find_first_of('|')-1); 277 const string name = buffer.substr(buffer.find_first_of('/')+1, buffer.find_first_of('|')-buffer.find_first_of('/')-1); 278 const string cmd = buffer.substr(0, buffer.find_first_of('|')); 279 280 // Add name the the list 281 list.push_back(name); 282 283 // Add format to the list 284 fFormatList[cmd] = fmt; 262 if (buffer.find("SERVICE_DESC")!=buffer.length()-12) 263 { 264 // Get the server name from the service name 265 const string server = buffer.substr(0, buffer.find_first_of('/')); 266 267 // Initialize the entry with an empty list 268 if (str[0]!='+') 269 fServiceList[server] = vector<string>(); 270 271 // For easy and fast access get the corresponding reference 272 vector<string> &list = fServiceList[server]; 273 274 // Tokenize the stream into lines 275 stringstream stream(str); 276 while (getline(stream, buffer, '\n')) 277 { 278 if (buffer.empty()) 279 continue; 280 281 // Get the type and compare it with fType 282 const string type = buffer.substr(buffer.find_last_of('|')+1); 283 if (type!=fType) 284 continue; 285 286 // Get format, name and command name 287 const string fmt = buffer.substr(buffer.find_first_of('|')+1, buffer.find_last_of('|')-buffer.find_first_of('|')-1); 288 const string name = buffer.substr(buffer.find_first_of('/')+1, buffer.find_first_of('|')-buffer.find_first_of('/')-1); 289 const string cmd = buffer.substr(0, buffer.find_first_of('|')); 290 291 // Add name the the list 292 list.push_back(name); 293 294 // Add format to the list 295 fFormatList[cmd] = fmt; 296 } 297 } 298 else 299 { 300 fDescriptionMap.clear(); 301 302 wout << str << endl; 303 304 stringstream stream(str); 305 while (getline(stream, buffer, '\n')) 306 { 307 if (buffer.empty()) 308 continue; 309 310 const vector<Description> v = Description::SplitDescription(buffer); 311 312 const string svc = v[0].name; 313 314 fDescriptionMap[svc] = v[0].comment; 315 fDescriptionList[svc] = vector<Description>(v.begin()+1, v.end()); 316 } 285 317 } 286 318 } … … 306 338 } 307 339 340 vector<string> ServiceList::GetServiceList() const 341 { 342 vector<string> vec; 343 for (ServerMap::const_iterator i=fServerList.begin(); i!=fServerList.end(); i++) 344 { 345 const string server = i->first; 346 347 const vector<string> v = GetServiceList(server); 348 349 for (vector<string>::const_iterator s=v.begin(); s<v.end(); s++) 350 vec.push_back(server+"/"+*s); 351 } 352 353 return vec; 354 } 308 355 309 356 // -------------------------------------------------------------------------- … … 320 367 string ServiceList::GetFormat(const string &service) const 321 368 { 322 FormatMap::const_iterator i = fFormatList.find(service);369 StringMap::const_iterator i = fFormatList.find(service); 323 370 return i==fFormatList.end() ? "" : i->second; 324 371 } … … 381 428 } 382 429 430 bool ServiceList::HasService(const string &svc) const 431 { 432 const size_t p = svc.find_first_of('/'); 433 if (p==string::npos) 434 return false; 435 436 return HasService(svc.substr(0, p), svc.substr(p+1)); 437 } 438 383 439 // -------------------------------------------------------------------------- 384 440 // … … 440 496 { 441 497 const string &server = i->first; 442 DimInfo *ptr = i->second; 443 444 out << " " << server << " " << ptr->getName() << endl; 498 DimInfo *ptr1 = i->second.first; 499 DimInfo *ptr2 = i->second.second; 500 501 out << " " << server << " " << ptr1->getName() << "|" << ptr2->getName() << endl; 445 502 } 446 503 out << endl; … … 473 530 // -------------------------------------------------------------------------- 474 531 // 475 //! Request a SERVER_LIST from the name server and a SERVICE_LISZ from all 532 //! Print the full available documentation (description) of all available 533 //! services or comments to the the given stream. 534 //! 535 //! @param out 536 //! ostream to which the output is send. 537 // 538 void ServiceList::PrintDescription(std::ostream &out) const 539 { 540 for (ServiceMap::const_iterator i=fServiceList.begin(); i!=fServiceList.end(); i++) 541 { 542 const string &server = i->first; 543 const vector<string> &lst = i->second; 544 545 out << "" << kRed << "----- " << server << " -----" << endl; 546 547 for (vector<string>::const_iterator s=lst.begin(); s!=lst.end(); s++) 548 { 549 out << " " << *s; 550 551 const string fmt = GetFormat(server, *s); 552 if (!fmt.empty()) 553 out << "[" << fmt << "]"; 554 555 const string svc = server + "/" + *s; 556 557 const DescriptionMap::const_iterator v = fDescriptionList.find(svc); 558 if (v==fDescriptionList.end()) 559 { 560 out << endl; 561 continue; 562 } 563 564 for (vector<Description>::const_iterator j=v->second.begin(); 565 j!=v->second.end(); j++) 566 out << " <" << j->name << ">"; 567 out << endl; 568 569 const StringMap::const_iterator d = fDescriptionMap.find(svc); 570 if (d!=fDescriptionMap.end() && !d->second.empty()) 571 out << " " << d->second << endl; 572 573 for (vector<Description>::const_iterator j=v->second.begin(); 574 j!=v->second.end(); j++) 575 { 576 out << " " << kGreen << j->name; 577 if (!j->comment.empty()) 578 out << kReset << ": " << kBlue << j->comment; 579 if (!j->unit.empty()) 580 out << kYellow << " [" << j->unit << "]"; 581 out << endl; 582 } 583 } 584 out << endl; 585 } 586 } 587 588 // -------------------------------------------------------------------------- 589 // 590 //! Request a SERVER_LIST from the name server and a SERVICE_LIST from all 476 591 //! servers in the list. Dumps the result to the given ostream. 477 592 //! -
trunk/FACT++/src/ServiceList.h
r10183 r10298 10 10 #include "dis.hxx" 11 11 12 #include "Description.h" 13 12 14 class ServiceList : public DimClient 13 15 { 14 16 public: 15 typedef std::map<const std::string, DimInfo*> ServerMap; 16 typedef std::map<const std::string, std::vector<std::string>> ServiceMap; 17 typedef std::map<const std::string, std::string> FormatMap; 17 typedef std::map<const std::string, std::pair<DimInfo*, DimInfo*>> ServerMap; 18 typedef std::map<const std::string, std::vector<std::string>> ServiceMap; 19 typedef std::map<const std::string, std::string> StringMap; 20 typedef std::map<const std::string, std::vector<Description>> DescriptionMap; 18 21 19 22 private: … … 24 27 const std::string fType; /// A filter for the type of the services to be collected, e.g. CMD 25 28 26 ServerMap fServerList; /// A map storing server names and a DimInfo for their SERVICE_LIST 27 ServiceMap fServiceList; /// A map storing server names and vector with all their available commands 28 FormatMap fFormatList; /// A map storing all commands and their format strings 29 ServerMap fServerList; /// A map storing server names and a DimInfo for their SERVICE_LIST 30 ServiceMap fServiceList; /// A map storing server names and vector with all their available commands 31 StringMap fFormatList; /// A map storing all commands and their format strings 32 StringMap fDescriptionMap; /// A map storing all descriptions for commands and services 33 DescriptionMap fDescriptionList; /// A map storing all descriptions for arguments of command and services 29 34 30 35 DimInfoHandler *fHandler; /// A callback to signal updates 31 36 32 DimInfo *CreateDimInfo(const std::string &str) const; 37 DimInfo *CreateDimInfo(const std::string &str, const std::string &svc) const; 38 39 DimInfo *CreateSL(const std::string &str) const { return CreateDimInfo(str, "SERVICE_LIST"); } 40 DimInfo *CreateFMT(const std::string &str) const { return CreateDimInfo(str, "SERVICE_DESC"); } 33 41 34 42 void ProcessServerList(); … … 45 53 46 54 std::vector<std::string> GetServerList() const; 55 std::vector<std::string> GetServiceList() const; 47 56 std::vector<std::string> GetServiceList(const std::string &server) const; 48 57 49 58 bool HasServer(const std::string &name) const; 50 59 bool HasService(const std::string &server, const std::string &service) const; 60 bool HasService(const std::string &service) const; 51 61 52 62 ServiceMap::const_iterator begin() const { return fServiceList.begin(); } … … 61 71 void PrintServerList(std::ostream &out) const; 62 72 void PrintServiceList(std::ostream &out) const; 73 void PrintDescription(std::ostream &out) const; 63 74 void PrintServerList() const { PrintServerList(wout); } 64 75 void PrintServiceList() const { PrintServiceList(wout); } 76 void PrintDescription() const { PrintDescription(wout); } 65 77 66 78 static void DumpServiceList(std::ostream &out);
Note:
See TracChangeset
for help on using the changeset viewer.