fipa_services
ServiceLocator.hpp
Go to the documentation of this file.
1 #ifndef FIPA_SERVICES_SERVICE_LOCATOR_HPP
2 #define FIPA_SERVICES_SERVICE_LOCATOR_HPP
3 
4 #include <vector>
5 #include <string>
6 
7 namespace fipa {
8 namespace services {
9 
15 {
17  std::string mServiceAddress;
20  std::string mSignatureType;
23  std::string mServiceSignature;
24 
25 public:
26  enum Field { SIGNATURE_TYPE = 0x01, SERVICE_SIGNATURE = 0x02, SERVICE_ADDRESS = 0x04 };
27 
32 
33  ServiceLocation(const std::string& serviceAddress, const std::string& signatureType = "", const std::string& serviceSignature = "")
34  : mServiceAddress(serviceAddress)
35  , mSignatureType(signatureType)
36  , mServiceSignature(serviceSignature)
37  {}
38 
44  std::string getFieldContent(ServiceLocation::Field field) const;
45 
50  std::string getSignatureType() const { return mSignatureType; }
51 
56  std::string getServiceSignature() const { return mServiceSignature; }
57 
62  std::string getServiceAddress() const { return mServiceAddress; }
63 
68  std::string toString() const;
69 
74  static ServiceLocation fromString(const std::string& locationString);
75 
80  bool operator==(const ServiceLocation& other) const;
81 
86  std::string getProtocol() const;
87 };
88 
89 typedef std::vector<ServiceLocation> ServiceLocations;
90 
97 {
99  ServiceLocations mLocations;
100 
101 public:
103 
104  ServiceLocator(const ServiceLocations& locations);
105 
106  ServiceLocations getLocations() const { return mLocations; }
107 
113  void addLocation(const ServiceLocation& location) { mLocations.push_back(location); }
114 
119  bool hasLocations() const { return mLocations.empty(); }
120 
125  ServiceLocation getFirstLocation() const { return mLocations.front(); }
126 
135  ServiceLocations search(const std::string& regex, ServiceLocation::Field field = ServiceLocation::SIGNATURE_TYPE);
136 
142  void updateFromString(const std::string& locations);
143 
150  static ServiceLocator fromString(const std::string& locations);
151 
157  std::string toString() const;
158 };
159 
160 } // end namespace services
161 } // end namespace fipa
162 #endif // FIPA_SERVICES_SERVICE_LOCATOR_HPP
ServiceLocation()
Definition: ServiceLocator.hpp:31
ServiceLocator()
Definition: ServiceLocator.hpp:102
std::vector< ServiceLocation > ServiceLocations
Definition: ServiceLocator.hpp:89
Definition: ServiceLocator.hpp:26
std::string getServiceSignature() const
Definition: ServiceLocator.hpp:56
bool operator==(const ServiceLocation &other) const
Definition: ServiceLocator.cpp:53
std::string toString() const
Definition: ServiceLocator.cpp:24
static ServiceLocation fromString(const std::string &locationString)
Definition: ServiceLocator.cpp:31
std::string getFieldContent(ServiceLocation::Field field) const
Definition: ServiceLocator.cpp:11
bool hasLocations() const
Definition: ServiceLocator.hpp:119
ServiceLocations getLocations() const
Definition: ServiceLocator.hpp:106
std::string getSignatureType() const
Definition: ServiceLocator.hpp:50
Field
Definition: ServiceLocator.hpp:26
Definition: ServiceLocator.hpp:26
std::string getProtocol() const
Definition: ServiceLocator.cpp:58
A ServiceLocator is a container for ServiceLocations.
Definition: ServiceLocator.hpp:96
std::string getServiceAddress() const
Definition: ServiceLocator.hpp:62
Class to describe the location of a service.
Definition: ServiceLocator.hpp:14
Definition: DistributedServiceDirectory.cpp:5
ServiceLocation getFirstLocation() const
Definition: ServiceLocator.hpp:125
ServiceLocation(const std::string &serviceAddress, const std::string &signatureType="", const std::string &serviceSignature="")
Definition: ServiceLocator.hpp:33
void addLocation(const ServiceLocation &location)
Definition: ServiceLocator.hpp:113