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

Last change on this file since 10306 was 10306, checked in by tbretz, 9 years ago
Implemented GetComment and GetDescription member functions.
File size: 3.8 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    std::string GetComment(const std::string &server, const std::string &name) const;
72    std::string GetComment(const std::string &service) const;
73
74    std::vector<Description> GetDescriptions(const std::string &server, const std::string &name) const;
75    std::vector<Description> GetDescriptions(const std::string &service) const;
76
77    void PrintServerList(std::ostream &out) const;
78    void PrintServiceList(std::ostream &out) const;
79    void PrintDescription(std::ostream &out) const;
80    void PrintServerList() const { PrintServerList(wout); }
81    void PrintServiceList() const { PrintServiceList(wout); }
82    void PrintDescription() const { PrintDescription(wout); }
83
84    static void DumpServiceList(std::ostream &out);
85    void DumpServiceList() const { DumpServiceList(wout); }
86
87    bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const;
88    bool SendDimCommand(const std::string &server, const std::string &str) const
89    {
90        return SendDimCommand(std::cout, server, str);
91    }
92};
93
94#endif
Note: See TracBrowser for help on using the repository browser.