73 return new DimInfo((str+
'/'+svc).c_str(),
74 const_cast<char*>(
""),
75 const_cast<DimServiceInfoList*>(
this));
94 const ServiceInfoList::iterator v = fServiceInfoList.find(s);
95 if (v!=fServiceInfoList.end())
98 err <<
"DimServiceInfoList: Server '" << s <<
"' in list not as it ought to be.";
99 throw runtime_error(err.str());
102 fServiceInfoList[s].push_back(CreateSL(s));
103 fServiceInfoList[s].push_back(CreateFMT(s));
104 fServiceInfoList[s].push_back(CreateDS(s));
123 fList->RemoveAllServices(s);
125 const ServiceInfoList::iterator v = fServiceInfoList.find(s);
126 if (v==fServiceInfoList.end())
140 fServiceInfoList.erase(v);
141 fServiceList.erase(s);
153 while (!fServiceInfoList.empty())
154 RemoveServer(fServiceInfoList.begin()->first);
173 const string svc = getInfo()->getName();
176 const string server = svc.substr(0, svc.find_first_of(
'/'));
177 const string service = svc.substr(svc.find_first_of(
'/')+1);
179 if (service==
"SERVICE_LIST")
182 TypeList &list = fServiceList[server].first;
184 const string str = getInfo()->getString();
191 if (str[0]!=
'+' && str[0]!=
'-')
193 fList->RemoveAllServices(server);
200 stringstream stream(str);
201 while (getline(stream, buffer,
'\n'))
207 const string type = buffer.substr(buffer.find_last_of(
'|')+1);
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);
222 const bool iscmd = type==
"CMD";
230 const TypeList::iterator v = list.find(name);
241 fList->RemoveService(server, name, iscmd);
252 const TypeList::iterator v = list.find(name);
256 err <<
"DimServiceInfoList: Service '" << server <<
"/" << name <<
"' already in list not as it ought to be.";
257 throw runtime_error(err.str());
260 list[name] = make_pair(fmt, iscmd);
261 fList->AddService(server, name, fmt, iscmd);
267 list[name] = make_pair(fmt, iscmd);
268 fList->AddService(server, name, fmt, iscmd);
274 if (service==
"SERVICE_DESC")
283 stringstream stream(getInfo()->getString());
284 while (getline(stream, buffer,
'\n'))
291 const string name = v[0].name.substr(v[0].name.find_first_of(
'/')+1);
292 const string comment = v[0].comment;
294 list[name] = make_pair(comment, vector<Description>(v.begin()+1, v.end()));
296 fList->AddDescription(server, name, v);
302 if (service==
"STATE_LIST")
304 vector<State> &vec = fServiceList[server].third;
306 fList->AddStates(server, vec);
330 const ServiceList::const_iterator m = fServiceList.find(server);
331 if (m==fServiceList.end())
332 return vector<string>();
334 const TypeList &list = m->second.first;
337 for (TypeList::const_iterator
i=list.begin();
i!=list.end();
i++)
338 if (
i->second.second==iscmd)
339 vec.push_back(server+
'/'+
i->first);
359 for (ServiceList::const_iterator m=fServiceList.begin(); m!=fServiceList.end(); m++)
361 const TypeList &list = m->second.first;
363 for (TypeList::const_iterator
i=list.begin();
i!=list.end();
i++)
364 if (
i->second.second==iscmd)
365 vec.push_back(m->first+
'/'+
i->first);
390 const ServiceList::const_iterator s = fServiceList.find(server);
391 if (s==fServiceList.end())
392 return vector<Description>();
396 const DescriptionList::const_iterator d = descs.find(service);
398 return vector<Description>();
400 vector<Description> vec;
401 vec.push_back(
Description(service, d->second.first));
402 vec.insert(vec.end(), d->second.second.begin(), d->second.second.end());
421 const ServiceList::const_iterator s = fServiceList.find(server);
422 if (s==fServiceList.end())
423 return vector<State>();
425 return s->second.third;
446 const ServiceList::const_iterator s = fServiceList.find(server);
447 if (s==fServiceList.end())
450 str <<
"DimServiceInfoList::GetState: Searching for state #" << state <<
" server " << server <<
" not found.";
451 return State(-3,
"Server not found", str.str());
454 const std::vector<State> &v = s->second.third;
456 for (vector<State>::const_iterator
i=v.begin();
i!=v.end();
i++)
461 str <<
"DimServiceInfoList::GetState: State #" << state <<
" not found on server " << server <<
".";
462 return State(-2,
"State not found", str.str());
482 const ServiceList::const_iterator s = fServiceList.find(server);
483 if (s==fServiceList.end())
486 const TypeList &list = s->second.first;
488 const TypeList::const_iterator
t = list.find(service);
492 return t->second.second;
519 for (ServiceList::const_iterator
i=fServiceList.begin();
i!=fServiceList.end();
i++)
521 const string &server =
i->first;
523 if (!serv.empty() && server!=serv)
526 out <<
kRed <<
"----- " << server <<
" -----" << endl;
531 for (TypeList::const_iterator
t=types.begin();
t!=types.end();
t++)
533 if (!service.empty() &&
t->first!=service)
536 if (
t->second.second!=iscmd)
541 out <<
" " <<
t->first;
544 const string fmt =
t->second.first;
546 out <<
'[' << fmt <<
']';
548 const DescriptionList::const_iterator d = descs.find(
t->first);
555 const string comment = d->second.first;
556 const vector<Description> &v = d->second.second;
558 for (vector<Description>::const_iterator j=v.begin(); j!=v.end(); j++)
559 out <<
" <" << j->name <<
">";
562 if (!comment.empty())
563 out <<
" " << comment << endl;
565 for (vector<Description>::const_iterator j=v.begin(); j!=v.end(); j++)
567 out <<
" " <<
kGreen << j->name;
568 if (!j->comment.empty())
570 if (!j->unit.empty())
571 out <<
kYellow <<
" [" << j->unit <<
"]";
597 for (ServiceList::const_iterator
i=fServiceList.begin();
i!=fServiceList.end();
i++)
599 const string &server =
i->first;
601 if (!serv.empty() && server!=serv)
604 out <<
kRed <<
"----- " << server <<
" -----" << endl;
606 const vector<State> &v =
i->second.third;
609 out <<
" <no states>" << endl;
613 for (vector<State>::const_iterator s=v.begin(); s!=v.end(); s++)
615 out <<
kBold << setw(5) << s->index <<
kReset <<
": ";
617 out <<
kBlue <<
" (" << s->comment <<
")" << endl;
650 size_t p0 = str.find_first_of(
' ');
651 if (p0==string::npos)
655 const string name = str.substr(0, p0);
658 const string cmd = server +
'/' + name;
660 const ServiceList::const_iterator m = fServiceList.find(server);
661 if (m==fServiceList.end())
662 throw runtime_error(
"Unkown server '"+server+
"'");
664 const TypeList &services = m->second.first;
666 const TypeList::const_iterator
t = services.find(name);
667 if (t==services.end())
668 throw runtime_error(
"Command '"+name+
"' not known on server '"+server+
"'");
670 if (!t->second.second)
671 throw runtime_error(
"'"+server+
"/"+name+
" not a command.");
674 const string fmt = t->second.first;
688 throw runtime_error(
"Couldn't properly parse the format... ignored.");
691 lout <<
kBlue << cmd;
693 const vector<char> v = conv.
GetVector(str.substr(p0));
695 lout <<
kBlue <<
" [" << v.size() <<
"]" << endl;
723 SendDimCommand(server, str, lout);
727 catch (
const runtime_error &e)
729 lout <<
kRed << e.what() << endl;
751 SendDimCommand(server, str, dummy);
void RemoveServer(std::string)
std::map< const std::string, ServiceType > TypeList
void AddServer(const std::string &s)
int PrintDescription(std::ostream &out, bool iscmd, const std::string &serv="", const std::string &service="") const
std::vector< State > GetStates(const std::string &server) const
std::map< const std::string, std::pair< std::string, std::vector< Description > > > DescriptionList
bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const
A struct which stores a name, a unit and a comment.
int IsCommand(const std::string &server, const std::string &service) const
DimServiceInfoList(DimServiceInfoListImp *list)
static void sendCommandNB(const char *name, int data)
std::vector< std::string > GetServiceList(bool iscmd=false) const
static std::vector< Description > SplitDescription(const std::string &buffer)
DimInfo * CreateDimInfo(const std::string &str, const std::string &svc) const
A mal containing all the available informations.
State GetState(const std::string &server, int state) const
int PrintStates(std::ostream &out, const std::string &serv="") const
A compiler for the DIM data format string.
static std::vector< State > SplitStates(const std::string &buffer)
Time of state change.
Maintains a list of all servers based on DIS_DNS/SERVER_LIST.
std::vector< char > GetVector(const void *d, size_t size) const
std::vector< Description > GetDescription(const std::string &server, const std::string &service) const