61 wout(out), fDimServers(
"DIS_DNS/SERVER_LIST", const_cast<char*>(
""), this),
62 fType(type), fHandler(0)
77 wout(out),
fDimServers(
"DIS_DNS/SERVER_LIST", const_cast<char*>(
""), this),
90 delete i->second.first;
91 delete i->second.second;
134 return new DimInfo((str+
'/'+svc).c_str(),
135 const_cast<char*>(
""),
136 const_cast<ServiceList*>(
this));
155 if (str[0]!=
'-' && str[0]!=
'+')
161 delete i->second.first;
162 delete i->second.second;
173 stringstream stream(str);
177 while (getline(stream, buffer,
'|'))
180 const string server = buffer.substr(0, buffer.find_first_of(
'@'));
187 const string trunc = server.substr(1);
191 const ServerMap::iterator v =
fServerList.find(trunc);
194 wout <<
kRed <<
"Server '" << trunc <<
"' not in list as it ought to be." << endl;
199 delete v->second.first;
200 delete v->second.second;
207 wout <<
" -> " <<
Time().
GetAsStr() <<
" - " << trunc <<
"/SERVICE_LIST: Disconnected." << endl;
215 const string trunc = server.substr(1);
219 const ServerMap::iterator v =
fServerList.find(trunc);
222 wout <<
kRed <<
"Server '" << trunc <<
"' in list not as it ought to be." << endl;
229 wout <<
" -> " <<
Time().
GetAsStr() <<
" - " << trunc <<
"/SERVICE_LIST: Connected." << endl;
265 if (buffer.find(
"SERVICE_DESC")!=buffer.length()-12)
268 const string server = buffer.substr(0, buffer.find_first_of(
'/'));
278 stringstream stream(str);
279 while (getline(stream, buffer,
'\n'))
285 const string type = buffer.substr(buffer.find_last_of(
'|')+1);
290 const string fmt = buffer.substr(buffer.find_first_of(
'|')+1, buffer.find_last_of(
'|')-buffer.find_first_of(
'|')-1);
291 const string name = buffer.substr(buffer.find_first_of(
'/')+1, buffer.find_first_of(
'|')-buffer.find_first_of(
'/')-1);
292 const string cmd = buffer.substr(0, buffer.find_first_of(
'|'));
295 list.push_back(name);
305 stringstream stream(str);
306 while (getline(stream, buffer,
'\n'))
313 const string svc = v[0].name;
330 v.push_back(
i->first);
337 const ServiceMap::const_iterator m =
fServiceList.find(server);
338 return m==
end() ? vector<string>() : m->second;
346 const string server =
i->first;
350 for (vector<string>::const_iterator s=v.begin(); s<v.end(); s++)
351 vec.push_back(server+
"/"+*s);
370 const StringMap::const_iterator
i =
fFormatList.find(service);
493 ServiceMap::const_iterator v =
fServiceList.find(server);
497 const vector<string> &w = v->second;
498 return find(w.begin(), w.end(), service)!=w.end();
503 const size_t p = svc.find_first_of(
'/');
507 return HasService(svc.substr(0, p), svc.substr(p+1));
527 return vector<string>().
end();
529 return i->second.begin();
549 return vector<string>().
end();
551 return i->second.end();
564 out << endl <<
kBold <<
"ServerList:" << endl;
568 const string &server =
i->first;
572 out <<
" " << server <<
" " << ptr1->
getName() <<
"|" << ptr2->
getName() << endl;
586 out << endl <<
kBold <<
"ServiceList:" << endl;
590 const string &server =
i->first;
591 const vector<string> &lst =
i->second;
593 out <<
" " << server << endl;
595 for (vector<string>::const_iterator j=lst.begin(); j!=lst.end(); j++)
596 out <<
" " << *j <<
" [" <<
GetFormat(server, *j) <<
"]" << endl;
620 const string &server =
i->first;
622 if (!serv.empty() && server!=serv)
625 out <<
kRed <<
"----- " << server <<
" -----" << endl;
627 const vector<string> &lst =
i->second;
628 for (vector<string>::const_iterator s=lst.begin(); s!=lst.end(); s++)
630 if (!service.empty() && *s!=service)
637 const string fmt =
GetFormat(server, *s);
639 out <<
'[' << fmt <<
']';
641 const string svc = server +
'/' + *s;
650 for (vector<Description>::const_iterator j=v->second.begin();
651 j!=v->second.end(); j++)
652 out <<
" <" << j->name <<
">";
657 out <<
" " << d->second << endl;
659 for (vector<Description>::const_iterator j=v->second.begin();
660 j!=v->second.end(); j++)
662 out <<
" " <<
kGreen << j->name;
663 if (!j->comment.empty())
665 if (!j->unit.empty())
666 out <<
kYellow <<
" [" << j->unit <<
"]";
686 DimCurrentInfo info1(
"DIS_DNS/SERVER_LIST", const_cast<char*>(
""));
691 while (getline(stream, buffer,
'|'))
693 const string server = buffer.substr(0, buffer.find_first_of(
'@'));
697 out <<
kBold <<
" " << server << endl;
699 DimCurrentInfo info2((server+
"/SERVICE_LIST").c_str(), const_cast<char*>(
""));
704 while (getline(stream2, buffer2,
'\n'))
709 out <<
" " << buffer2 << endl;
735 size_t p0 = str.find_first_of(
' ');
736 if (p0==string::npos)
740 const string name = str.substr(0, p0);
743 const string cmd = server +
'/' + name;
747 lout <<
kRed <<
"Unkown command '" << cmd <<
"'" << endl;
759 lout <<
kRed <<
"Couldn't properly parse the format... ignored." << endl;
765 lout <<
kBlue << cmd;
766 const vector<char> v = conv.
GetVector(str.substr(p0));
771 lout <<
kGreen <<
"Command " << cmd <<
" emitted successfully to DimClient." << endl;
773 lout <<
kRed <<
"ERROR - Sending command " << cmd <<
" failed." << endl;
775 catch (
const std::runtime_error &e)
777 lout << endl <<
kRed << e.what() << endl;
static int sendCommand(const char *name, int data)
ServerMap fServerList
A filter for the type of the services to be collected, e.g. CMD.
virtual void infoHandler()=0
ServiceMap::const_iterator begin() const
Adds some functionality to boost::posix_time::ptime for our needs.
ServiceList(const char *type, std::ostream &out=std::cout)
bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const
StringMap fFormatList
A map storing server names and vector with all their available commands.
std::string GetComment(const std::string &server, const std::string &name) const
ServiceMap fServiceList
A map storing server names and a DimInfo for their SERVICE_LIST.
void PrintServiceList() const
DimInfo fDimServers
stream for redirection of the output
void ProcessServiceList(DimInfo &info)
std::vector< std::string > GetServiceList() const
bool HasService(const std::string &server, const std::string &service) const
ServiceMap::const_iterator end() const
DimInfo * CreateFMT(const std::string &str) const
DimInfo * CreateSL(const std::string &str) const
std::vector< std::string > GetServerList() const
bool HasServer(const std::string &name) const
int PrintDescription(std::ostream &out, const std::string &serv="", const std::string &svc="") const
std::string GetFormat(const std::string &server, const std::string &name) const
const std::string fType
A DimInfo to retrieve the SERVER_LIST from teh DNS server.
std::vector< Description > GetDescriptions(const std::string &server, const std::string &name) const
DescriptionMap fDescriptionList
A map storing all descriptions for commands and services.
DimInfo * CreateDimInfo(const std::string &str, const std::string &svc) const
A callback to signal updates.
static std::vector< Description > SplitDescription(const std::string &buffer)
void PrintServerList() const
~ServiceList()
Delete the allocated memory from fServerList.
DimInfoHandler * fHandler
A map storing all descriptions for arguments of command and services.
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
A compiler for the DIM data format string.
StringMap fDescriptionMap
A map storing all commands and their format strings.
void DumpServiceList() const
std::vector< char > GetVector(const void *d, size_t size) const