fipa_acl  1.4
Public Member Functions | Friends | List of all members
fipa::acl::ACLEnvelope Class Reference

ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields, along with the actual payload data that is wrapped by this envelope. More...

#include <acl_envelope.h>

Public Member Functions

 ACLEnvelope ()
 
 ACLEnvelope (const ACLMessage &msg, const fipa::acl::representation::Type &format)
 
void insert (const ACLMessage &msg, const fipa::acl::representation::Type &format)
 
const ACLBaseEnvelopeListgetExtraEnvelopes () const
 
void addExtraEnvelope (const ACLBaseEnvelope &envelope)
 
void setExtraEnvelopes (const ACLBaseEnvelopeList &envelopes)
 
const ACLBaseEnvelopegetBaseEnvelope () const
 
void setBaseEnvelope (const ACLBaseEnvelope &envelope)
 
ACLBaseEnvelope flattened () const
 
AgentIDList getDeliveryPath () const
 
std::string getDeliveryPathString () const
 
void setPayload (const std::string &payload)
 
const std::string & getPayload () const
 
fipa::acl::ACLMessage getACLMessage () const
 
void stamp (const fipa::acl::AgentID &id)
 
bool hasStamp (fipa::acl::AgentID id) const
 
ACLEnvelope createDedicatedEnvelope (const AgentID &receiverId) const
 

Friends

class EnvelopeFormat
 

Detailed Description

ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields, along with the actual payload data that is wrapped by this envelope.

See also
fipa::acl::Letter
http://www.fipa.org/specs/fipa00067/SC00067F.html

Definition at line 349 of file acl_envelope.h.

Constructor & Destructor Documentation

fipa::acl::ACLEnvelope::ACLEnvelope ( )

Default envelope constructor

Definition at line 236 of file acl_envelope.cpp.

237 {}
fipa::acl::ACLEnvelope::ACLEnvelope ( const ACLMessage msg,
const fipa::acl::representation::Type format 
)

Creates an envelope for an acl message. Note the the acl message will be encoded according to the given representation format

Note, that the fields to, from, intended-receivers, acl-representation, payload-length, payload-encoding and date are set. All others have to be set explicitly (also see stamp). Intended-receivers is initially same as 'to' and should only be modified by a transport service to organize message delivery

Parameters
msgACLMessage will shall be wrapped by this envelope
formatThe message format this message will be encoded in for transport

Definition at line 239 of file acl_envelope.cpp.

240 {
241  insert(message,representation);
242 }
void insert(const ACLMessage &msg, const fipa::acl::representation::Type &format)

Member Function Documentation

void fipa::acl::ACLEnvelope::addExtraEnvelope ( const ACLBaseEnvelope envelope)
inline

Add an extra envelope to overwrite existing parameters Append the most recent extra envelope

Definition at line 417 of file acl_envelope.h.

417 { mExtraEnvelopes.push_back(envelope); }
ACLEnvelope fipa::acl::ACLEnvelope::createDedicatedEnvelope ( const AgentID receiverId) const

Create a dedicated letter, i.e. where the intended-receivers field contains only a single receiver

Returns
ACLEnvelope with an extra ACLBaseEnvelope witha single receiver

Definition at line 361 of file acl_envelope.cpp.

362 {
363  fipa::acl::Letter updatedLetter = *this;
364  fipa::acl::ACLBaseEnvelope extraEnvelope;
365  AgentIDList intendedReceivers;
366  intendedReceivers.push_back(receiverId);
367  extraEnvelope.setIntendedReceivers(intendedReceivers);
368  updatedLetter.addExtraEnvelope(extraEnvelope);
369 
370  return updatedLetter;
371 }
The ACLBaseEnvelope defines the layout for an envelope with which ACLMessage data can be wrapped...
Definition: acl_envelope.h:36
ACLMessage envelope (also typed as fipa::acl::Letter) includes the base envelope and updated fields...
Definition: acl_envelope.h:349
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
void setIntendedReceivers(const AgentIDList &receivers)
void addExtraEnvelope(const ACLBaseEnvelope &envelope)
Definition: acl_envelope.h:417
ACLBaseEnvelope fipa::acl::ACLEnvelope::flattened ( ) const
inline

Retrieve the fully merged envelope Starting with the base envelope each extra envelope is applied as an overlay

Returns
the envelope representing the most recent combination of information in base and extra envelopes

Definition at line 444 of file acl_envelope.h.

444 { return mBaseEnvelope.flatten(mExtraEnvelopes); }
ACLBaseEnvelope flatten(const ACLBaseEnvelopeList &extraEnvelopes) const
fipa::acl::ACLMessage fipa::acl::ACLEnvelope::getACLMessage ( ) const

Retrieve the contained message if possible.

Returns
decoded payload
Exceptions
std::runtime_errorif the acl message could not be extracted

Definition at line 305 of file acl_envelope.cpp.

306 {
307  using namespace fipa::acl;
308  ACLMessage msg;
309  MessageParser mp;
310  // Get the LATEST representation (from flattened), not from base envelope!
311  representation::Type aclRepresentation = flattened().getACLRepresentation();
312  LOG_DEBUG_S << "getACLMessage from payload: " << mPayload << " with representation: " << representation::TypeTxt[aclRepresentation];
313  if( !mp.parseData(mPayload, msg, aclRepresentation ))
314  {
315  // TODO This makes the process crash, only if someone decides to send us a malformed message. Not so good...
316  throw std::runtime_error("ACLEnvelope::getACLMessage failed for representation '" + std::string(representation::TypeTxt[aclRepresentation]));
317  }
318  return msg;
319 }
ACLBaseEnvelope flattened() const
Definition: acl_envelope.h:444
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
Definition: acl_envelope.h:203
Allows to parse a bytestream that conforms to the bitefficient representation of FIPA messages to a A...
const std::string TypeTxt[]
Definition: types.h:28
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
Agent Communication Language.
Definition: conversation.cpp:7
const ACLBaseEnvelope& fipa::acl::ACLEnvelope::getBaseEnvelope ( ) const
inline

Get the base envelope

Returns
base envelope

Definition at line 430 of file acl_envelope.h.

430 { return mBaseEnvelope; }
AgentIDList fipa::acl::ACLEnvelope::getDeliveryPath ( ) const

Retrieve the delivery path from the received object in base and extra envelopes, i.e. will not include the current hop (unless stamped)

Returns
List of agents id representing the delivery path, in time order, i.e. oldest first to this agent

Definition at line 267 of file acl_envelope.cpp.

268 {
269  AgentIDList deliveryPath;
270  if(mBaseEnvelope.contains(envelope::RECEIVED_OBJECT))
271  {
272  std::string hop = mBaseEnvelope.getReceivedObject().getBy();
273  deliveryPath.push_back(AgentID(hop));
274  }
275 
276  ACLBaseEnvelopeList::const_iterator cit = mExtraEnvelopes.begin();
277  for(; cit != mExtraEnvelopes.end();++cit)
278  {
279  if(cit->contains(envelope::RECEIVED_OBJECT))
280  {
281  std::string hop = cit->getReceivedObject().getBy();
282  deliveryPath.push_back(AgentID(hop));
283  }
284  }
285 
286  return deliveryPath;
287 }
const URL & getBy() const
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
bool contains(envelope::ParameterId id) const
Definition: acl_envelope.h:144
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Definition: agent_id.h:37
const ReceivedObject & getReceivedObject() const
Definition: acl_envelope.h:281
std::string fipa::acl::ACLEnvelope::getDeliveryPathString ( ) const

Retrieve the delivery path as a comma separated list of agent names in time order

Returns
String representiong the delivery path

Definition at line 289 of file acl_envelope.cpp.

290 {
291  std::string pathString;
292  AgentIDList deliveryPath = getDeliveryPath();
293  AgentIDList::const_iterator cit = deliveryPath.begin();
294  for(; cit != deliveryPath.end();)
295  {
296  pathString += cit->getName();
297  if(++cit != deliveryPath.end())
298  {
299  pathString += ",";
300  }
301  }
302  return pathString;
303 }
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
AgentIDList getDeliveryPath() const
const ACLBaseEnvelopeList& fipa::acl::ACLEnvelope::getExtraEnvelopes ( ) const
inline

Get all extra envelopes. Extra envelope represent an overlay to the base envelope, This overlay mechanism is used, since information must not be discarded.

Returns
extra envelopes

Definition at line 411 of file acl_envelope.h.

411 { return mExtraEnvelopes; }
const std::string& fipa::acl::ACLEnvelope::getPayload ( ) const
inline

Get the payload which is wrapped by this envelope

Returns
string as byte container

Definition at line 473 of file acl_envelope.h.

473 { return mPayload; }
bool fipa::acl::ACLEnvelope::hasStamp ( fipa::acl::AgentID  id) const

Check whether the letter has already been stamped Iterates over all received objects for testing

Returns
True, if the agent id is set in one of the received objects, false otherwise

Definition at line 337 of file acl_envelope.cpp.

338 {
339  ReceivedObject receivedObject;
340  receivedObject.setBy(id.getName());
341 
342  ACLBaseEnvelopeList::const_iterator cit = mExtraEnvelopes.begin();
343  for(; cit != mExtraEnvelopes.end(); ++cit)
344  {
345  if(cit->hasStamp(receivedObject))
346  {
347  return true;
348  }
349  }
350  return false;
351 }
void setBy(const URL &by)
void fipa::acl::ACLEnvelope::insert ( const ACLMessage msg,
const fipa::acl::representation::Type format 
)

Insert a message to this envelope using a specific representation Existing settings will be overwritten

Parameters
msgMessage to be set
formatFormat to be applied to the message

Definition at line 244 of file acl_envelope.cpp.

245 {
246  using namespace fipa::acl;
247  mPayload = MessageGenerator::create(message, representation);
248 
249  // infer fields from message
250  mBaseEnvelope.setTo(message.getAllReceivers());
251  // By default set the intended receivers
252  // Can be overriden by the user when creating the base envelope,
253  // however that should be avoided and only done by the transport service
254  mBaseEnvelope.setIntendedReceivers(mBaseEnvelope.getTo());
255  mBaseEnvelope.setFrom(message.getSender());
256  // comments have to be set explicitly, so not done here
257  mBaseEnvelope.setACLRepresentation(representation);
258  mBaseEnvelope.setPayloadLength(mPayload.size());
259  mBaseEnvelope.setPayloadEncoding(message.getEncoding());
260  mBaseEnvelope.setDate(base::Time::now());
261 
262  // intended receivers, received object and transport behaviour
263  // will not be set here but have to be either explicitly
264  // or by stamping the message
265 }
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
Agent Communication Language.
Definition: conversation.cpp:7
void fipa::acl::ACLEnvelope::setBaseEnvelope ( const ACLBaseEnvelope envelope)
inline

Set the base envelope

Parameters
envelopeBase envelope to set

Definition at line 436 of file acl_envelope.h.

436 { mBaseEnvelope = envelope; }
void fipa::acl::ACLEnvelope::setExtraEnvelopes ( const ACLBaseEnvelopeList envelopes)
inline

Set all extra envelopes Overwrites the existing set of extra envelopes

Parameters
envelopesList of base envelopes

Definition at line 424 of file acl_envelope.h.

424 { mExtraEnvelopes = envelopes; }
void fipa::acl::ACLEnvelope::setPayload ( const std::string &  payload)
inline

Set the payload which is wrapped by this envelope as byte get If you are using this function, make sure to set the corresponding encoding of the payload

Parameters
payloadrepresenting an acl message

Definition at line 467 of file acl_envelope.h.

467 { mPayload = payload; }
void fipa::acl::ACLEnvelope::stamp ( const fipa::acl::AgentID id)

Stamp a letter with a given agent id This creates a new received object and attaches it to an extra envelope

The mandatory fields 'by' and 'date' are set. The optional field 'id' is set.

Definition at line 321 of file acl_envelope.cpp.

322 {
323  ReceivedObject receivedObject;
324 
325  // Mandatory fields
326  receivedObject.setBy(id.getName());
327  receivedObject.setDate(base::Time::now());
328 
329  receivedObject.setId(createLocalId());
330 
331  ACLBaseEnvelope extraEnvelope;
332  extraEnvelope.stamp(receivedObject);
333 
334  mExtraEnvelopes.push_back(extraEnvelope);
335 }
The ACLBaseEnvelope defines the layout for an envelope with which ACLMessage data can be wrapped...
Definition: acl_envelope.h:36
void setId(const ID &id)
void stamp(const ReceivedObject &receivedObject)
Definition: acl_envelope.h:330
void setBy(const URL &by)
void setDate(const base::Time &date)

Friends And Related Function Documentation

friend class EnvelopeFormat
friend

Definition at line 351 of file acl_envelope.h.


The documentation for this class was generated from the following files: