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

#include <transition.h>

Inherited by fipa::acl::default_transition::ConversationCancelFailure, fipa::acl::default_transition::ConversationCancelling, fipa::acl::default_transition::ConversationCancelSuccess, fipa::acl::default_transition::GeneralFailure, and fipa::acl::default_transition::NotUnderstood.

Public Member Functions

 Transition ()
 empty constructor for the transition class; initializes fields More...
 
 Transition (const Role &senderRole, const Role &receiverRole, const fipa::acl::ACLMessage::Performative &performative, const fipa::acl::StateId &sourceState, const fipa::acl::StateId &targetState)
 
 Transition (const Role &senderRole, const Role &receiverRole, const std::string &performativeRegExp, const StateId &sourceState, const StateId &targetState)
 
bool triggers (const ACLMessage &msg, const ACLMessage &initiatingMsg, const RoleMapping &roleMapping) const
 check whether a certain message trigger the execution of the transition More...
 
bool validateMessage (const ACLMessage &msg, const ACLMessage &validatorMsg, const RoleMapping &roleMapping, validation::Flags flags=validation::ALL) const
 method that validates all parameters of a message More...
 
void setPerformativeRegExp (const std::string &performativeRegExp)
 setter methods for various fields of the class More...
 
void setPerformative (const fipa::acl::ACLMessage::Performative &performative)
 setter methods for various fields of the class More...
 
void setSourceState (const StateId &stateId)
 
void setTargetState (const StateId &stateId)
 
void setSenderRole (const Role &role)
 
void setReceiverRole (const Role &role)
 
Role getSenderRole () const
 
Role getReceiverRole () const
 
std::string getPerformativeRegExp () const
 getter methods for various fields of the class More...
 
StateId getSourceStateId () const
 
StateId getTargetStateId () const
 
std::string toString () const
 
std::string toXML () const
 
bool operator== (const Transition &t) const
 

Detailed Description

A transition that can be associated with a state object

Definition at line 26 of file transition.h.

Constructor & Destructor Documentation

◆ Transition() [1/3]

fipa::acl::Transition::Transition ( )

empty constructor for the transition class; initializes fields

Definition at line 14 of file transition.cpp.

15  : mSenderRole()
16  , mReceiverRole()
17  , mPerformativeRegExp()
18  , mSourceStateId()
19  , mTargetStateId()
20 {
21 }

◆ Transition() [2/3]

fipa::acl::Transition::Transition ( const Role senderRole,
const Role receiverRole,
const fipa::acl::ACLMessage::Performative performative,
const fipa::acl::StateId sourceState,
const fipa::acl::StateId targetState 
)

Transition constructor using an explicit Performative instead of a regular expression

Definition at line 23 of file transition.cpp.

24  : mSenderRole(senderRole)
25  , mReceiverRole(receiverRole)
26  , mPerformativeRegExp(PerformativeTxt[performative])
27  , mSourceStateId(sourceState)
28  , mTargetStateId(targetState)
29 {
30 }
std::map< ACLMessage::Performative, std::string > PerformativeTxt
Definition: acl_message.cpp:15

◆ Transition() [3/3]

fipa::acl::Transition::Transition ( const Role senderRole,
const Role receiverRole,
const std::string &  performativeRegExp,
const StateId sourceState,
const StateId targetState 
)

Transition constructor

Definition at line 33 of file transition.cpp.

34  : mSenderRole(senderRole)
35  , mReceiverRole(receiverRole)
36  , mPerformativeRegExp(performativeRegExp)
37  , mSourceStateId(sourceState)
38  , mTargetStateId(targetState)
39 {
40 }

Member Function Documentation

◆ getPerformativeRegExp()

std::string fipa::acl::Transition::getPerformativeRegExp ( ) const
inline

getter methods for various fields of the class

Definition at line 128 of file transition.h.

128 { return mPerformativeRegExp; }

◆ getReceiverRole()

Role fipa::acl::Transition::getReceiverRole ( ) const
inline

Get the receiver role

Definition at line 121 of file transition.h.

121 { return mReceiverRole; }

◆ getSenderRole()

Role fipa::acl::Transition::getSenderRole ( ) const
inline

Get the sender role

Definition at line 116 of file transition.h.

116 { return mSenderRole; }

◆ getSourceStateId()

StateId fipa::acl::Transition::getSourceStateId ( ) const
inline

Get the state id of the source state

Definition at line 133 of file transition.h.

133 { return mSourceStateId; }

◆ getTargetStateId()

StateId fipa::acl::Transition::getTargetStateId ( ) const
inline

Get the state id of the target state

Definition at line 138 of file transition.h.

138 { return mTargetStateId; }

◆ operator==()

bool fipa::acl::Transition::operator== ( const Transition t) const

Equals operator

Definition at line 198 of file transition.cpp.

199 {
200  if(mSourceStateId != other.mSourceStateId)
201  {
202  return false;
203  } else if (mTargetStateId != other.mTargetStateId)
204  {
205  return false;
206  } else if (mSenderRole != other.mSenderRole)
207  {
208  return false;
209  } else if (mReceiverRole != other.mReceiverRole)
210  {
211  return false;
212  } else if (mPerformativeRegExp != other.mPerformativeRegExp)
213  {
214  return false;
215  }
216 
217  return true;
218 }

◆ setPerformative()

void fipa::acl::Transition::setPerformative ( const fipa::acl::ACLMessage::Performative performative)
inline

setter methods for various fields of the class

Definition at line 91 of file transition.h.

91 { mPerformativeRegExp = fipa::acl::PerformativeTxt[performative]; }
std::map< ACLMessage::Performative, std::string > PerformativeTxt
Definition: acl_message.cpp:15

◆ setPerformativeRegExp()

void fipa::acl::Transition::setPerformativeRegExp ( const std::string &  performativeRegExp)
inline

setter methods for various fields of the class

Definition at line 85 of file transition.h.

85 { mPerformativeRegExp = performativeRegExp; }

◆ setReceiverRole()

void fipa::acl::Transition::setReceiverRole ( const Role role)
inline

Set the receiver role

Definition at line 111 of file transition.h.

111 { mReceiverRole = role; }

◆ setSenderRole()

void fipa::acl::Transition::setSenderRole ( const Role role)
inline

Set the sender role

Definition at line 106 of file transition.h.

106 { mSenderRole = role; }

◆ setSourceState()

void fipa::acl::Transition::setSourceState ( const StateId stateId)
inline

Set the source state of this transition

Definition at line 96 of file transition.h.

96 { mSourceStateId = stateId; }

◆ setTargetState()

void fipa::acl::Transition::setTargetState ( const StateId stateId)
inline

Set the target state of this transition

Definition at line 101 of file transition.h.

101 { mTargetStateId = stateId; }

◆ toString()

std::string fipa::acl::Transition::toString ( ) const

Convert transition to string

Definition at line 150 of file transition.cpp.

151 {
152  std::stringstream transition;
153  transition << "transition: sender role: '" << mSenderRole.getId() << "', ";
154  transition << "receiver role: '" << mReceiverRole.getId() << "', ";
155  transition << "performative: '" << mPerformativeRegExp << "', ";
156  transition << "source state: '" << mSourceStateId << "', ";
157  transition << "target state: '" << mTargetStateId << "'";
158 
159  return transition.str();
160 }
RoleId getId() const
Definition: role.h:52

◆ toXML()

std::string fipa::acl::Transition::toXML ( ) const

Convert transition to XML

Definition at line 162 of file transition.cpp.

163 {
164  std::stringstream transition;
165  transition << "<transition ";
166  transition << "performative=\"" << mPerformativeRegExp << "\" ";
167  transition << "from=\"" << mSenderRole.getId() << "\" ";
168  transition << "to=\"" << mReceiverRole.getId() << "\" ";
169  transition << "target=\"" << mTargetStateId << "\" ";
170  transition << "/>";
171 
172  return transition.str();
173 }
RoleId getId() const
Definition: role.h:52

◆ triggers()

bool fipa::acl::Transition::triggers ( const ACLMessage msg,
const ACLMessage initiatingMsg,
const RoleMapping roleMapping 
) const

check whether a certain message trigger the execution of the transition

Parameters
msgmessage to process
initiatingMsgmessage that initiated the conversation or represents the direct predecessor of the current one
roleMappingCurrent role mapping
Returns
true if message triggers this transition, false otherwise

Definition at line 42 of file transition.cpp.

43 {
44  // Set the standard validation flags
46  if( validateMessage(msg, initiatingMsg, roleMapping, flags) )
47  {
48  return true;
49  } else {
50  LOG_DEBUG("Message validation failed: message does not apply to transition");
51  }
52  return false;
53 }
bool validateMessage(const ACLMessage &msg, const ACLMessage &validatorMsg, const RoleMapping &roleMapping, validation::Flags flags=validation::ALL) const
method that validates all parameters of a message
Definition: transition.cpp:55

◆ validateMessage()

bool fipa::acl::Transition::validateMessage ( const ACLMessage msg,
const ACLMessage validatorMsg,
const RoleMapping roleMapping,
validation::Flags  flags = validation::ALL 
) const

method that validates all parameters of a message

Parameters
msgmessage passed as parameter to be checked
validatorMsgTo validate conversation id, protocol, encoding, language, ontology and in_reply_to the validatorMsg is referred to
roleMappingCurrent role mapping
flagsFlag which shall be considered during validation
Returns
true if message is valid false otherwise

Definition at line 55 of file transition.cpp.

56 {
57  if( flags == validation::NONE)
58  {
59  return true;
60  }
61 
62  // Test performative against transition performative
63  // not the validator message one
64  if (validation::PERFORMATIVE & flags)
65  {
66  boost::regex performativeRegex(mPerformativeRegExp);
67  if(!regex_match(msg.getPerformative(), performativeRegex))
68  {
69  LOG_DEBUG("Performative validation failed: was '%s' but expected: '%s'", msg.getPerformative().c_str(), mPerformativeRegExp.c_str());
70  return false;
71  }
72  }
73 
74  if( validation::SENDER & flags)
75  {
76  AgentID senderAgent = msg.getSender();
77  if(!roleMapping.isExpected(mSenderRole, senderAgent))
78  {
79  LOG_DEBUG("Sender validation failed: '%s' unexpected for role '%s'", senderAgent.getName().c_str(), mSenderRole.getId().c_str());
80  return false;
81  }
82  }
83 
84  if(validation::RECEIVERS & flags)
85  {
86  if(!validateReceivers(msg, roleMapping))
87  {
88  LOG_DEBUG("Receivers validation failed");
89  return false;
90  }
91  }
92 
93  if(validation::CONVERSATION_ID & flags)
94  {
95  if (msg.getConversationID() != validatorMsg.getConversationID())
96  {
97  LOG_DEBUG("ConversationID validation failed: was '%s' but expected: '%s'", msg.getConversationID().c_str(), validatorMsg.getConversationID().c_str());
98  return false;
99  }
100  }
101 
102  if(validation::PROTOCOL & flags)
103  {
104  if (msg.getProtocol() != validatorMsg.getProtocol())
105  {
106  LOG_DEBUG("Protocol validation failed: was '%s' but expected: '%s'", msg.getProtocol().c_str(), validatorMsg.getProtocol().c_str());
107  return false;
108  }
109  }
110 
111  if(validation::ENCODING & flags)
112  {
113  if (msg.getEncoding() != validatorMsg.getEncoding())
114  {
115  LOG_DEBUG("Encoding validation failed: was '%s' but expected: '%s'", msg.getEncoding().c_str(), validatorMsg.getEncoding().c_str());
116  return false;
117  }
118  }
119 
120  if(validation::LANGUAGE & flags)
121  {
122  if (msg.getLanguage() != validatorMsg.getLanguage())
123  {
124  LOG_DEBUG("Language validation failed: was '%s' but expected: '%s'", msg.getLanguage().c_str(), validatorMsg.getLanguage().c_str());
125  return false;
126  }
127  }
128 
129  if(validation::ONTOLOGY & flags)
130  {
131  if (msg.getOntology() != validatorMsg.getOntology())
132  {
133  LOG_DEBUG("Ontology validation failed: was '%s' but expected: '%s'", msg.getOntology().c_str(), validatorMsg.getOntology().c_str());
134  return false;
135  }
136  }
137 
138  if(validation::IN_REPLY_TO & flags)
139  {
140  if (msg.getInReplyTo() != validatorMsg.getInReplyTo())
141  {
142  LOG_DEBUG("InReplyTo validation failed: was '%s' but expected: '%s'", msg.getInReplyTo().c_str(), validatorMsg.getInReplyTo().c_str());
143  return false;
144  }
145  }
146 
147  return true;
148 }
RoleId getId() const
Definition: role.h:52

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