fipa_services
MessageTransport.hpp
Go to the documentation of this file.
1 #ifndef FIPA_SERVICE_MESSAGE_TRANSPORT_SERVICE_HPP
2 #define FIPA_SERVICE_MESSAGE_TRANSPORT_SERVICE_HPP
3 
4 #include <map>
5 #include <fipa_acl/fipa_acl.h>
6 #include <boost/function.hpp>
7 #include <stdexcept>
8 #include <fipa_services/transports/Transport.hpp>
9 #include <fipa_services/transports/Configuration.hpp>
10 #include <fipa_services/ServiceDirectory.hpp>
11 
12 namespace fipa {
13 namespace agent_management {
14  const std::string ONTOLOGY = "fipa-agent-management";
15  const std::string INTERNAL_ERROR = "internal-error";
16  const std::string INTERNAL_COMMUNICATION = "internal-communication";
17 }
18 
19 namespace services {
20 namespace message_transport {
21 
23 typedef boost::function2<bool, const std::string&, const fipa::acl::Letter&> MessageTransportHandler;
24 
25 typedef std::map<std::string, MessageTransportHandler> MessageTransportHandlerMap;
26 typedef std::vector<std::string> MessageTransportPriorityList;
27 
71 {
72 private:
73  fipa::acl::AgentID mAgentId;
74  ServiceDirectory::Ptr mpServiceDirectory;
75 
76  MessageTransportHandlerMap mMessageTransportHandlerMap;
77  MessageTransportPriorityList mMessageTransportPriorityList;
78 
79  mutable std::map<transports::Transport::Type, transports::Transport::Ptr> mActiveTransports;
80  std::vector<transports::Configuration> mTransportConfigurations;
81 
83  std::vector<fipa::services::ServiceLocation> mTransportEndpoints;
84 
85  // Representation which is used to exchange internal messages
86  // default is bitefficient
87  fipa::acl::representation::Type mRepresentation;
88 
92  std::string mServiceSignature;
93  std::set<std::string> mAcceptedServiceSignatures;
94 
99  void stamp(fipa::acl::Letter& msg) const;
100 
105  bool hasStamp(const fipa::acl::Letter& msg) const;
106 
110  fipa::acl::ACLMessage createInternalErrorMessage(const fipa::acl::ACLMessage& msg, const std::string& description) const;
111 
116  bool localForward(const std::string& receiverName, const fipa::acl::Letter& msg) const;
117 
121  fipa::acl::AgentIDList forward(const fipa::acl::Letter& letter) const;
122 
123  void forward(const std::string& receiverName, const ServiceLocation& location, const fipa::acl::Letter& letter) const;
124 
129  bool hasActiveTransport(const std::string& protocol) const;
130 
136  bool isLocal(const ServiceLocation& local) const;
137 
141  void handleData(const std::string& data);
142 
146  static void removeFromList(const fipa::acl::AgentID& receiver, fipa::acl::AgentIDList& receiversList);
147 
153  void cacheTransportEndpoints(fipa::services::transports::Transport::Ptr transport);
154 
155 public:
156 
162  MessageTransport(const fipa::acl::AgentID& id, ServiceDirectory::Ptr serviceDirectory);
163 
164  fipa::acl::AgentID getAgentID() const { return mAgentId; }
165 
166  void configure(const std::vector<transports::Configuration>& configurations) { mTransportConfigurations = configurations; }
167 
175  void activateTransports(const std::vector<std::string>& transports);
176 
185  void activateTransports(transports::Transport::Type flags);
186 
192  void activateTransport(transports::Transport::Type type);
193 
198  std::vector<fipa::services::ServiceLocation> getTransportEndpoints() const;
199 
205  void handle(fipa::acl::Letter& msg);
206 
211  void handleError(const fipa::acl::Letter& msg) const;
212 
218  void registerMessageTransport(const std::string& id, MessageTransportHandler handler);
219 
224  void deregisterMessageTransport(const std::string& id);
225 
230  void modifyMessageTransport(const std::string& id, MessageTransportHandler handler);
231 
239  bool handleInternalCommunication(const fipa::acl::Letter& letter);
240 
245  void setInternalMessageRepresentationType(const fipa::acl::representation::Type& representation) { mRepresentation = representation; }
246 
252 
257  void trigger();
258 
262  std::string getServiceSignature() const { return mServiceSignature; }
263 
272  void addAcceptedServiceSignature(const std::string& signature) { mAcceptedServiceSignatures.insert(signature); }
273 
278  ServiceDirectory::Ptr getServiceDirectory() { return mpServiceDirectory; }
279 
287  void registerClient(const std::string& clientName, const std::string& clientDescription);
288 
296  void deregisterClient(const std::string& clientName);
297 
302  std::string serializeLetter(const fipa::acl::Letter& letter, const std::string& signature) const;
303 
304 };
305 
306 } // end namespace message_transport
307 } // end namespace services
308 } // end namespace fipa
309 
310 #endif // FIPA_SERVICE_MESSAGE_TRANSPORT_SERVICE_HPP
boost::function2< bool, const std::string &, const fipa::acl::Letter & > MessageTransportHandler
MessageTransportHandler needs to return success of the delivery.
Definition: MessageTransport.hpp:23
ServiceDirectory::Ptr getServiceDirectory()
Definition: MessageTransport.hpp:278
Type
Builtin transport types that can be activated.
Definition: Transport.hpp:28
std::vector< std::string > MessageTransportPriorityList
Definition: MessageTransport.hpp:26
boost::shared_ptr< ServiceDirectory > Ptr
Definition: ServiceDirectory.hpp:29
const std::string INTERNAL_ERROR
Definition: MessageTransport.hpp:15
void setInternalMessageRepresentationType(const fipa::acl::representation::Type &representation)
Definition: MessageTransport.hpp:245
fipa::acl::representation::Type getInternalMessageRepresentationType() const
Definition: MessageTransport.hpp:251
const std::string ONTOLOGY
Definition: MessageTransport.hpp:14
const std::string INTERNAL_COMMUNICATION
Definition: MessageTransport.hpp:16
std::map< std::string, MessageTransportHandler > MessageTransportHandlerMap
Definition: MessageTransport.hpp:25
std::string getServiceSignature() const
Definition: MessageTransport.hpp:262
void addAcceptedServiceSignature(const std::string &signature)
Definition: MessageTransport.hpp:272
void configure(const std::vector< transports::Configuration > &configurations)
Definition: MessageTransport.hpp:166
std::string Type
Definition: ServiceDirectoryEntry.hpp:14
boost::shared_ptr< Transport > Ptr
Definition: Transport.hpp:46
Service responsible for handling FIPA message and managing the forwarding and relaying.
Definition: MessageTransport.hpp:70
Class to describe the location of a service.
Definition: ServiceLocator.hpp:14
Definition: DistributedServiceDirectory.cpp:5
fipa::acl::AgentID getAgentID() const
Definition: MessageTransport.hpp:164