Ignore:
Timestamp:
04/07/11 12:35:43 (13 years ago)
Author:
tbretz
Message:
Added the automatic retrieval of the description strings as send by DimDescriptionService; added a GetServiceList() member function returning all service names.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/ServiceList.cc

    r10289 r10298  
    8787{
    8888    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    }
    9093}
    9194
     
    108111
    109112    if (fHandler)
     113    {
     114        fHandler->itsService = 0;
    110115        fHandler->infoHandler();
     116    }
    111117}
    112118
     
    121127//!    a pointer to the newly created DimInfo
    122128//!
    123 DimInfo *ServiceList::CreateDimInfo(const string &str) const
    124 {
    125     return new DimInfo((str+"/SERVICE_LIST").c_str(),
     129DimInfo *ServiceList::CreateDimInfo(const string &str, const string &svc) const
     130{
     131    return new DimInfo((str+"/"+svc).c_str(),
    126132                       const_cast<char*>(""),
    127133                       const_cast<ServiceList*>(this));
     
    150156        for (ServerMap::iterator i=fServerList.begin(); i!=fServerList.end(); i++)
    151157        {
    152             delete i->second;
     158            delete i->second.first;
     159            delete i->second.second;
    153160
    154161            ServiceMap::iterator x = fServiceList.find(i->first);
     
    156163            //wout << "Delete: " << i->first << endl;
    157164        }
     165
    158166        fServerList.clear();
    159167    }
     
    186194
    187195            // Remove the server from the server list
    188             delete v->second;
     196            delete v->second.first;
     197            delete v->second.second;
    189198            fServerList.erase(v);
    190199
     
    213222
    214223            // Add the new server to the server list
    215             fServerList[trunc] = CreateDimInfo(trunc);
     224            fServerList[trunc] = make_pair(CreateSL(trunc), CreateFMT(trunc));
    216225
    217226            wout << " -> " << Time().GetAsStr() << " - " << trunc << "/SERVICE_LIST: Connected." << endl;
     
    221230
    222231        // 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));
    224233        //wout << "Add  0: " << server << endl;
    225234    }
     
    251260    string buffer = info.getName();
    252261
    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        }
    285317    }
    286318}
     
    306338}
    307339
     340vector<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}
    308355
    309356// --------------------------------------------------------------------------
     
    320367string ServiceList::GetFormat(const string &service) const
    321368{
    322     FormatMap::const_iterator i = fFormatList.find(service);
     369    StringMap::const_iterator i = fFormatList.find(service);
    323370    return i==fFormatList.end() ? "" : i->second;
    324371}
     
    381428}
    382429
     430bool 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
    383439// --------------------------------------------------------------------------
    384440//
     
    440496    {
    441497        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;
    445502    }
    446503    out << endl;
     
    473530// --------------------------------------------------------------------------
    474531//
    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//
     538void 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
    476591//! servers in the list. Dumps the result to the given ostream.
    477592//!
Note: See TracChangeset for help on using the changeset viewer.