5 #include <boost/spirit/include/phoenix_core.hpp> 6 #include <boost/spirit/include/phoenix_operator.hpp> 7 #include <base-logging/Logging.hpp> 9 #include <fipa_acl/message_parser/message_parser.h> 10 #include <fipa_acl/message_generator/message_generator.h> 20 uint32_t ACLEnvelope::mStampCounter = 0;
22 ACLBaseEnvelope::ACLBaseEnvelope()
24 , mACLRepresentation(representation::
UNKNOWN)
25 , mPayloadEncoding(
"US-ASCII")
31 AgentIDList::const_iterator it = find_if(mTo.begin(), mTo.end(), arg1 == agentId );
34 mTo.push_back(agentId);
46 AgentIDList::iterator it = find_if(mTo.begin(), mTo.end(), arg1 == agentId);
72 mACLRepresentation = representation;
86 std::string msg =
"Trying to set unknown representation '" + representation +
"'";
88 throw std::runtime_error(msg);
94 mPayloadLength = length;
100 mPayloadEncoding = encoding;
112 mIntendedReceivers = receivers;
117 AgentIDList::const_iterator it = find_if(mIntendedReceivers.begin(), mIntendedReceivers.end(), arg1 == agentId);
118 if(it == mIntendedReceivers.end())
120 mIntendedReceivers.push_back(agentId);
126 AgentIDList::iterator it = find_if(mIntendedReceivers.begin(), mIntendedReceivers.end(), arg1 == agentId);
127 if(it != mIntendedReceivers.end())
129 mIntendedReceivers.erase(it);
138 mReceivedObject = receivedObject;
145 return receivedObject.
getBy() == mReceivedObject.
getBy();
154 mTransportBehaviour = transportBehaviour;
160 mUserdefinedParameters = parameters;
227 ACLBaseEnvelopeList::const_iterator cit = extraEnvelopes.begin();
228 for(; cit != extraEnvelopes.end(); ++cit)
230 envelope = envelope.
merge(*cit);
241 insert(message,representation);
254 mBaseEnvelope.setIntendedReceivers(mBaseEnvelope.getTo());
255 mBaseEnvelope.setFrom(message.
getSender());
257 mBaseEnvelope.setACLRepresentation(representation);
258 mBaseEnvelope.setPayloadLength(mPayload.size());
259 mBaseEnvelope.setPayloadEncoding(message.
getEncoding());
260 mBaseEnvelope.setDate(base::Time::now());
272 std::string hop = mBaseEnvelope.getReceivedObject().getBy();
273 deliveryPath.push_back(
AgentID(hop));
276 ACLBaseEnvelopeList::const_iterator cit = mExtraEnvelopes.begin();
277 for(; cit != mExtraEnvelopes.end();++cit)
281 std::string hop = cit->getReceivedObject().getBy();
282 deliveryPath.push_back(
AgentID(hop));
291 std::string pathString;
293 AgentIDList::const_iterator cit = deliveryPath.begin();
294 for(; cit != deliveryPath.end();)
296 pathString += cit->getName();
297 if(++cit != deliveryPath.end())
312 LOG_DEBUG_S <<
"getACLMessage from payload: " << mPayload <<
" with representation: " <<
representation::TypeTxt[aclRepresentation];
313 if( !mp.
parseData(mPayload, msg, aclRepresentation ))
316 throw std::runtime_error(
"ACLEnvelope::getACLMessage failed for representation '" + std::string(representation::TypeTxt[aclRepresentation]));
326 receivedObject.
setBy(
id.getName());
327 receivedObject.
setDate(base::Time::now());
329 receivedObject.
setId(createLocalId());
332 extraEnvelope.
stamp(receivedObject);
334 mExtraEnvelopes.push_back(extraEnvelope);
340 receivedObject.
setBy(
id.getName());
342 ACLBaseEnvelopeList::const_iterator cit = mExtraEnvelopes.begin();
343 for(; cit != mExtraEnvelopes.end(); ++cit)
345 if(cit->hasStamp(receivedObject))
353 ID ACLEnvelope::createLocalId()
355 std::stringstream ss;
356 ss << ++mStampCounter;
357 ss <<
":" << base::Time::now().toString();
366 intendedReceivers.push_back(receiverId);
370 return updatedLetter;
std::string TransportBehaviour
std::string getEncoding() const
void setDate(const base::Time &date)
void stamp(const fipa::acl::AgentID &id)
The ACLBaseEnvelope defines the layout for an envelope with which ACLMessage data can be wrapped...
static bool parseData(const std::string &storage, ACLMessage &msg, fipa::acl::representation::Type representation=fipa::acl::representation::BITEFFICIENT)
parses a correctly encoded message according to grammar_bitefficient.h and creates a Message object f...
const representation::Type & getACLRepresentation() const
ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields...
const PayloadLength & getPayloadLength() const
void setComments(const Comments &comments)
const PayloadEncoding & getPayloadEncoding() const
bool hasStamp(fipa::acl::AgentID id) const
const TransportBehaviour & getTransportBehaviour() const
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
std::vector< UserdefParam > UserdefinedParameterList
bool removeTo(const AgentID &agentId)
ACLBaseEnvelope merge(const ACLBaseEnvelope &other) const
const URL & getBy() const
std::vector< AgentID > AgentIDList
bool contains(envelope::ParameterId id) const
const base::Time & getDate() const
const Comments & getComments() const
const std::string TypeTxt[]
void insert(const ACLMessage &msg, const fipa::acl::representation::Type &format)
void setIntendedReceivers(const AgentIDList &receivers)
std::vector< ACLBaseEnvelope > ACLBaseEnvelopeList
const AgentID & getFrom() const
bool removeIntendedReceiver(const AgentID &agent)
void setTo(const AgentIDList &receivers)
AgentIDList getDeliveryPath() const
AgentID getSender() const
void stamp(const ReceivedObject &receivedObject)
void addIntendedReceiver(const AgentID &agent)
This class provides a representation of a message conforming to the FIPA specification SC00061...
void setUserdefinedParameters(const UserdefinedParameterList ¶meters)
void setFrom(const AgentID &from)
fipa::acl::ACLMessage getACLMessage() const
void setACLRepresentation(representation::Type representation)
void addExtraEnvelope(const ACLBaseEnvelope &envelope)
void setReceivedObject(const ReceivedObject &receivedObject)
void addTo(const AgentID &agent)
std::string PayloadEncoding
void setPayloadEncoding(const PayloadEncoding &encoding)
ACLEnvelope createDedicatedEnvelope(const AgentID &receiverId) const
void setPayloadLength(const PayloadLength &length)
bool hasReceivedObject(const ReceivedObject &receivedObject) const
void setBy(const URL &by)
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Foundation of Physical Intelligent Agents.
AgentIDList getAllReceivers() const
const ReceivedObject & getReceivedObject() const
ACLBaseEnvelope flatten(const ACLBaseEnvelopeList &extraEnvelopes) const
void setDate(const base::Time &date)
void setTransportBehaviour(const TransportBehaviour &transportBehaviour)
Agent Communication Language.
const AgentIDList & getIntendedReceivers() const
const AgentIDList & getTo() const
std::string getDeliveryPathString() const
const UserdefinedParameterList & getUserdefinedParameters() const