FACT++  1.0
ServiceList.h
Go to the documentation of this file.
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 
14 class ServiceList : public DimClient
15 {
16 public:
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 
22 private:
23  std::ostream &wout;
24 
26 
27  const std::string fType;
28 
29  ServerMap fServerList;
30  ServiceMap fServiceList;
31  StringMap fFormatList;
32  StringMap fDescriptionMap;
33  DescriptionMap fDescriptionList;
34 
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 
47 public:
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  int PrintDescription(std::ostream &out, const std::string &serv="", const std::string &svc="") const;
80  void PrintServerList() const { PrintServerList(wout); }
81  void PrintServiceList() const { PrintServiceList(wout); }
82  int PrintDescription(const std::string &serv="", const std::string &svc="") const { return PrintDescription(wout, serv, svc); }
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
ServerMap fServerList
A filter for the type of the services to be collected, e.g. CMD.
Definition: ServiceList.h:29
void ProcessServerList()
Definition: ServiceList.cc:149
ServiceMap::const_iterator begin() const
Definition: ServiceList.h:62
char str[80]
Definition: test_client.c:7
ServiceList(const char *type, std::ostream &out=std::cout)
Definition: ServiceList.cc:60
std::map< const std::string, std::pair< DimInfo *, DimInfo * > > ServerMap
Definition: ServiceList.h:17
bool SendDimCommand(std::ostream &lout, const std::string &server, const std::string &str) const
Definition: ServiceList.cc:732
StringMap fFormatList
A map storing server names and vector with all their available commands.
Definition: ServiceList.h:31
std::string GetComment(const std::string &server, const std::string &name) const
Definition: ServiceList.cc:458
ServiceMap fServiceList
A map storing server names and a DimInfo for their SERVICE_LIST.
Definition: ServiceList.h:30
void PrintServiceList() const
Definition: ServiceList.h:81
DimInfo fDimServers
stream for redirection of the output
Definition: ServiceList.h:25
Definition: dic.hxx:31
void ProcessServiceList(DimInfo &info)
Definition: ServiceList.cc:256
std::vector< std::string > GetServiceList() const
Definition: ServiceList.cc:341
bool SendDimCommand(const std::string &server, const std::string &str) const
Definition: ServiceList.h:88
bool HasService(const std::string &server, const std::string &service) const
Definition: ServiceList.cc:491
ServiceMap::const_iterator end() const
Definition: ServiceList.h:63
DimInfo * CreateFMT(const std::string &str) const
Definition: ServiceList.h:40
std::ostream & wout
Definition: ServiceList.h:23
DimInfo * CreateSL(const std::string &str) const
Definition: ServiceList.h:39
std::vector< std::string > GetServerList() const
Definition: ServiceList.cc:326
bool HasServer(const std::string &name) const
Definition: ServiceList.cc:473
Definition: dis.c:69
int type
int PrintDescription(std::ostream &out, const std::string &serv="", const std::string &svc="") const
Definition: ServiceList.cc:615
std::string GetFormat(const std::string &server, const std::string &name) const
Definition: ServiceList.cc:388
const std::string fType
A DimInfo to retrieve the SERVER_LIST from teh DNS server.
Definition: ServiceList.h:27
std::vector< Description > GetDescriptions(const std::string &server, const std::string &name) const
Definition: ServiceList.cc:423
DescriptionMap fDescriptionList
A map storing all descriptions for commands and services.
Definition: ServiceList.h:33
DimInfo * CreateDimInfo(const std::string &str, const std::string &svc) const
A callback to signal updates.
Definition: ServiceList.cc:132
void infoHandler()
Definition: ServiceList.cc:105
void PrintServerList() const
Definition: ServiceList.h:80
int PrintDescription(const std::string &serv="", const std::string &svc="") const
Definition: ServiceList.h:82
Maintains a list of all servers and services available in the Dim nbetwork.
Definition: ServiceList.h:14
~ServiceList()
Delete the allocated memory from fServerList.
Definition: ServiceList.cc:86
static void handler(int conn_id, char *packet, int size, int status)
Definition: webServer.c:635
void SetHandler(DimInfoHandler *handler=0)
Definition: ServiceList.h:52
std::map< const std::string, std::string > StringMap
Definition: ServiceList.h:19
DimInfoHandler * fHandler
A map storing all descriptions for arguments of command and services.
Definition: ServiceList.h:35
StringMap fDescriptionMap
A map storing all commands and their format strings.
Definition: ServiceList.h:32
std::map< const std::string, std::vector< std::string > > ServiceMap
Definition: ServiceList.h:18
std::map< const std::string, std::vector< Description > > DescriptionMap
Definition: ServiceList.h:20
void DumpServiceList() const
Definition: ServiceList.h:85