source: trunk/FACT++/src/ServiceList.h @ 10298

Last change on this file since 10298 was 10298, checked in by tbretz, 9 years ago
Added the automatic retrieval of the description strings as send by DimDescriptionService; added a GetServiceList() member function returning all service names.
File size: 3.5 KB
Line 
1#ifndef FACT_ServiceList
2#define FACT_ServiceList
3
4#include <map>
5#include <vector>
6#include <string>
7#include <iostream>
8
9#include "dic.hxx"
10#include "dis.hxx"
11
12#include "Description.h"
13
14class ServiceList : public DimClient
15{
16public:
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;
21
22private:
23    std::ostream &wout;        /// stream for redirection of the output
24
25    DimInfo fDimServers;       /// A DimInfo to retrieve the SERVER_LIST from teh DNS server
26
27    const std::string fType;   /// A filter for the type of the services to be collected, e.g. CMD
28
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
34
35    DimInfoHandler *fHandler;  /// A callback to signal updates
36
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"); }
41
42    void ProcessServerList();
43    void ProcessServiceList(DimInfo &info);
44
45    void infoHandler();
46
47public:
48    ServiceList(const char *type, std::ostream &out=std::cout);
49    ServiceList(std::ostream &out=std::cout);
50    ~ServiceList();
51
52    void SetHandler(DimInfoHandler *handler=0) { fHandler=handler; }
53
54    std::vector<std::string> GetServerList() const;
55    std::vector<std::string> GetServiceList() const;
56    std::vector<std::string> GetServiceList(const std::string &server) const;
57
58    bool HasServer(const std::string &name) const;
59    bool HasService(const std::string &server, const std::string &service) const;
60    bool HasService(const std::string &service) const;
61
62    ServiceMap::const_iterator begin() const { return fServiceList.begin(); }
63    ServiceMap::const_iterator end() const  { return fServiceList.end(); }
64
65    std::vector<std::string>::const_iterator begin(const std::string &server) const;
66    std::vector<std::string>::const_iterator end(const std::string &server) const;
67
68    std::string GetFormat(const std::string &server, const std::string &name) const;
69    std::string GetFormat(const std::string &service) const;
70
71    void PrintServerList(std::ostream &out) const;
72    void PrintServiceList(std::ostream &out) const;
73    void PrintDescription(std::ostream &out) const;
74    void PrintServerList() const { PrintServerList(wout); }
75    void PrintServiceList() const { PrintServiceList(wout); }
76    void PrintDescription() const { PrintDescription(wout); }
77
78    static void DumpServiceList(std::ostream &out);
79    void DumpServiceList() const { DumpServiceList(wout); }
80
81    bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const;
82    bool SendDimCommand(const std::string &server, const std::string &str) const
83    {
84        return SendDimCommand(std::cout, server, str);
85    }
86};
87
88#endif
Note: See TracBrowser for help on using the repository browser.