implements a state of the StateMachine class
More...
#include <state.h>
Inherited by fipa::acl::default_state::ConversationCancelling, fipa::acl::FinalState, and fipa::acl::UndefinedState.
|
| | State () |
| | empty constructor initializes default fields More...
|
| |
| | State (const StateId &id) |
| | constructor taking the unique name(id) of the state as arguement More...
|
| |
| Transition | addTransition (const Transition &t) |
| |
| const Transition & | getTransition (const ACLMessage &msg, const MessageArchive &archive, const RoleMapping &roleMapping) const |
| | Check whether the received message triggers a transition. More...
|
| |
| void | consumeSubStateMachineMessage (const ACLMessage &msg, const fipa::acl::StateMachine &stateMachine, const fipa::acl::RoleMapping &roleMapping, int numberOfSubConversations) |
| |
| const Transition & | getSubstateMachineProxiedTransition (const ACLMessage &msg, const MessageArchive &archive, const RoleMapping &roleMapping) |
| | Check whether the received message triggers a substatemachine proxied transition. This method is not const, as the generated transitions will be added when they trigger successfully. More...
|
| |
| void | generateDefaultTransitions () |
| | method that generates implicit generic transitions applicable to all states, that may or may not be speciffied in the configuration file such as not-understood transition (if it is specified it is not doubled); this method is to be called after all states specified in the configuration have been added to the state machine, preferably after all generic transition have been added as well More...
|
| |
| bool | isFinal () const |
| |
| bool | isFinished () const |
| | method that returns whether the state is a finished state or not. In the case of a state with embedded state machines, this is a bit more coplex, see the implementation More...
|
| |
| bool | isDefaultState () const |
| | Test if state belongs to the default state or not. More...
|
| |
| void | setId (const StateId &id) |
| | setter method for the uid field of the state NOTE: maybe should be taken out and name only be allowed to be set on More...
|
| |
| std::string | getId () const |
| | getter method for the uid field of the class More...
|
| |
| const std::vector< Transition > & | getTransitions () const |
| |
| const std::vector< EmbeddedStateMachine > & | getEmbeddedStatemachines () const |
| |
| void | addEmbeddedStateMachine (fipa::acl::EmbeddedStateMachine embeddedStateMachine) |
| |
| std::string | toString () const |
| |
| std::string | toXML () const |
| |
|
| void | setFinal (bool final) |
| | setter method for the final field of the class When changing the final state flag make sure you either remove existing transitions or create the default transition if needed More...
|
| |
implements a state of the StateMachine class
Definition at line 41 of file state.h.
◆ State() [1/2]
| fipa::acl::State::State |
( |
| ) |
|
empty constructor initializes default fields
Definition at line 33 of file state.cpp.
static const StateId UNDEFINED_ID
◆ State() [2/2]
| fipa::acl::State::State |
( |
const StateId & |
id | ) |
|
constructor taking the unique name(id) of the state as arguement
- Parameters
-
| id | intended id for the state |
Definition at line 39 of file state.cpp.
◆ addEmbeddedStateMachine()
Add an embedded state machine.
Definition at line 357 of file state.cpp.
359 mEmbeddedStateMachines.push_back(embeddedStateMachine);
◆ addTransition()
Add a state transition
- Returns
- Transition with update source state field
Definition at line 45 of file state.cpp.
47 std::vector<Transition>::const_iterator it;
48 it = std::find(mTransitions.begin(), mTransitions.end(), t);
49 if( it == mTransitions.end())
52 transition.setSourceState(mId);
53 mTransitions.push_back(transition);
◆ consumeSubStateMachineMessage()
Tries to consume a message meant for a sub state machine.
- Exceptions
-
| runtime_error | if this does not work |
Definition at line 147 of file state.cpp.
149 LOG_INFO(
"State consumeSubStateMachineMessage");
152 for(std::vector<StateMachine>::iterator it0 = mSubStateMachines.begin(); it0 != mSubStateMachines.end(); it0++)
154 if(it0->inFinalState() || it0->inFailureState())
164 LOG_DEBUG(
"Trying an existing sub state machine");
165 it0->consumeMessage(msg);
168 }
catch(
const std::runtime_error& e)
170 LOG_DEBUG(
"Sub state machine incorrect: ", e.what());
176 LOG_DEBUG(
"Trying to search for a fitting a embedded state machine");
178 EmbeddedStateMachine* embeddedStateMachinePtr = NULL;
180 std::string protocol = msg.getProtocol();
183 std::vector<EmbeddedStateMachine>::iterator it;
184 for(it = mEmbeddedStateMachines.begin(); it != mEmbeddedStateMachines.end(); it++)
187 boost::regex peformativeRegex(it->name);
188 if(regex_match(protocol, peformativeRegex))
193 AgentIDList::const_iterator lit = std::find(l.begin(), l.end(), msg.getSender());
201 if(mSubStateMachines.size() >= numberOfSubConversations)
207 embeddedStateMachinePtr = &(*it);
212 if(!embeddedStateMachinePtr)
215 LOG_ERROR(
"State consumeSubStateMachineMessage: No fitting sub state machine found");
216 throw std::runtime_error(
"State consumeSubStateMachineMessage: No fitting sub state machine found");
219 LOG_DEBUG(
"Found a fitting embedded state machine and will try to create a sub state machine now");
222 if(!protocol.empty())
226 subStateMachine.
setSelf(msg.getSender());
230 LOG_DEBUG(
"Substate machine initialized, trying to consume message");
231 subStateMachine.consumeMessage(msg);
232 }
catch(
const std::runtime_error& e)
235 std::string errorMsg =
"Substatemachine creation failed: ";
236 errorMsg +=
" -- " + std::string(e.what());
237 throw std::runtime_error(errorMsg);
241 LOG_DEBUG(
"New sub state machine consumed message");
242 mSubStateMachines.push_back(subStateMachine);
243 embeddedStateMachinePtr->actualProtocol = protocol;
244 embeddedStateMachinePtr->numberOfSubConversations = numberOfSubConversations;
246 LOG_ERROR(
"Protocol not set");
247 throw std::runtime_error(
"Protocol not set");
250 LOG_DEBUG(
"State consumeSubStateMachineMessage successfully created new sub state machine");
const std::map< Role, AgentIDList > & getMapping() const
std::vector< AgentID > AgentIDList
void setSelf(const AgentID &self)
friend class StateMachine
◆ generateDefaultTransitions()
| void fipa::acl::State::generateDefaultTransitions |
( |
| ) |
|
method that generates implicit generic transitions applicable to all states, that may or may not be speciffied in the configuration file such as not-understood transition (if it is specified it is not doubled); this method is to be called after all states specified in the configuration have been added to the state machine, preferably after all generic transition have been added as well
Definition at line 60 of file state.cpp.
65 if(mEmbeddedStateMachines.empty())
70 else if(mTransitions.empty())
72 throw std::runtime_error(
"Invalid state: non final state without transition defined");
75 std::vector<Transition> transitions(mTransitions);
77 std::vector<Transition>::const_iterator it = transitions.begin();
78 for (; it != transitions.end();++it)
81 boost::regex peformativeRegex(it->getPerformativeRegExp());
91 addTransition(*dynamic_cast<Transition*>(&transitionReceiver));
100 addTransition(*dynamic_cast<Transition*>(&transitionSender));
103 addTransition(*dynamic_cast<Transition*>(&transitionReceiver));
112 addTransition(*dynamic_cast<Transition*>(&transitionReceiver));
117 std::vector<EmbeddedStateMachine>::const_iterator it0 = mEmbeddedStateMachines.begin();
118 for (; it0 != mEmbeddedStateMachines.end();++it0)
120 if(!it0->proxiedTo.empty())
124 addTransition(*dynamic_cast<Transition*>(&transitionSender0));
126 addTransition(*dynamic_cast<Transition*>(&transitionReceiver0));
130 addTransition(*dynamic_cast<Transition*>(&transitionSender1));
132 addTransition(*dynamic_cast<Transition*>(&transitionReceiver1));
136 addTransition(*dynamic_cast<Transition*>(&transitionReceiver2));
friend class default_transition::GeneralFailure
friend class default_transition::NotUnderstood
std::map< ACLMessage::Performative, std::string > PerformativeTxt
friend class default_transition::ConversationCancelling
Transition addTransition(const Transition &t)
◆ getEmbeddedStatemachines()
Retrieve embedded statemachine.
- Returns
- list of embedded statemachines
Definition at line 193 of file state.h.
193 {
return mEmbeddedStateMachines; }
◆ getId()
| std::string fipa::acl::State::getId |
( |
| ) |
const |
|
inline |
getter method for the uid field of the class
Definition at line 181 of file state.h.
◆ getSubstateMachineProxiedTransition()
Check whether the received message triggers a substatemachine proxied transition. This method is not const, as the generated transitions will be added when they trigger successfully.
- Returns
- the transition
- Exceptions
-
| runtime_error | if the msg is invalid in the current state |
Definition at line 280 of file state.cpp.
282 if(archive.hasMessages())
284 const ACLMessage& initiatingMsg = archive.getInitiatingMessage();
287 std::vector<EmbeddedStateMachine>::iterator it0 = mEmbeddedStateMachines.begin();
288 for (; it0 != mEmbeddedStateMachines.end(); ++it0)
290 LOG_DEBUG(
"Checking if a transition needs to be generated");
292 if(!it0->proxiedTo.empty() && it0->actualProtocol !=
"inform" && !it0->receivedProxiedReply )
294 LOG_DEBUG(
"Generating a transition");
298 if (transition.triggers(msg, initiatingMsg, roleMapping))
301 it0->receivedProxiedReply =
true;
302 mSubstateMachineProxiedTransitions.push_back(transition);
303 LOG_DEBUG(
"Transition triggered");
305 return mSubstateMachineProxiedTransitions.back();
311 throw std::runtime_error(
"Message does not trigger any (incl. proxied) transitions in this state");
std::string getId() const
getter method for the uid field of the class
◆ getTransition()
Check whether the received message triggers a transition.
- Returns
- the transition
- Exceptions
-
| runtime_error | if the msg is invalid in the current state |
Definition at line 253 of file state.cpp.
255 std::vector<Transition>::const_iterator it = mTransitions.begin();
256 for (; it != mTransitions.end(); ++it)
260 if(!archive.hasMessages())
263 boost::regex peformativeRegex(it->getPerformativeRegExp());
264 if(regex_match(msg.getPerformative(), peformativeRegex))
269 const ACLMessage& initiatingMsg = archive.getInitiatingMessage();
270 if (it->triggers(msg, initiatingMsg, roleMapping))
277 throw std::runtime_error(
"Message does not trigger any transition in this state");
◆ getTransitions()
| const std::vector<Transition>& fipa::acl::State::getTransitions |
( |
| ) |
const |
|
inline |
Retrieve transitions associated with this state
- Returns
- list of transitions
Definition at line 187 of file state.h.
187 {
return mTransitions; }
◆ isDefaultState()
| bool fipa::acl::State::isDefaultState |
( |
| ) |
const |
Test if state belongs to the default state or not.
- Returns
- true if state is default, false otherwise
Definition at line 141 of file state.cpp.
143 std::vector<StateId>::const_iterator cit = std::find(msDefaultStates.begin(), msDefaultStates.end(), mId);
144 return cit != msDefaultStates.end();
◆ isFinal()
| bool fipa::acl::State::isFinal |
( |
| ) |
const |
|
inline |
◆ isFinished()
| bool fipa::acl::State::isFinished |
( |
| ) |
const |
method that returns whether the state is a finished state or not. In the case of a state with embedded state machines, this is a bit more coplex, see the implementation
- Returns
- true if state is finished, false otherwise
Definition at line 314 of file state.cpp.
322 std::vector<StateMachine>::const_iterator it;
323 for(it = mSubStateMachines.begin(); it != mSubStateMachines.end(); it++)
325 if(!it->inFinalState() && !it->inFailureState())
327 LOG_DEBUG(
"State not finished (subconversation still running)");
334 std::vector<EmbeddedStateMachine>::const_iterator it0 = mEmbeddedStateMachines.begin();
335 for (; it0 != mEmbeddedStateMachines.end(); ++it0)
339 if(it0->numberOfSubConversations != mSubStateMachines.size())
341 LOG_DEBUG(
"State not finished (subconversation still running)");
346 if(!it0->proxiedTo.empty() && it0->actualProtocol !=
"inform" && !it0->receivedProxiedReply )
348 LOG_DEBUG(
"State not finished (proxied response missing)");
◆ setFinal()
| void fipa::acl::State::setFinal |
( |
bool |
final | ) |
|
|
inlineprotected |
setter method for the final field of the class When changing the final state flag make sure you either remove existing transitions or create the default transition if needed
- Parameters
-
| final | Change status of state |
Definition at line 97 of file state.h.
◆ setId()
| void fipa::acl::State::setId |
( |
const StateId & |
id | ) |
|
|
inline |
setter method for the uid field of the state NOTE: maybe should be taken out and name only be allowed to be set on
construction, as if we rename the state later on the state machine might crash(surely will actually)
- Parameters
-
| id | to set as id for the state |
Definition at line 176 of file state.h.
◆ toString()
| std::string fipa::acl::State::toString |
( |
| ) |
const |
Convert state to string representation
Definition at line 362 of file state.cpp.
364 std::stringstream state;
365 state <<
"state id: '" << mId <<
"', final: '" << mIsFinal <<
"'\n";
366 for(std::vector<Transition>::const_iterator it = mTransitions.begin(); it != mTransitions.end(); ++it)
368 state <<
"\t" << it->toString() <<
"\n";
371 for(std::vector<EmbeddedStateMachine>::const_iterator it = mEmbeddedStateMachines.begin(); it != mEmbeddedStateMachines.end(); ++it)
373 state <<
"\t" << it->toString() <<
"\n";
◆ toXML()
| std::string fipa::acl::State::toXML |
( |
| ) |
const |
Convert state to XML representation
Definition at line 379 of file state.cpp.
381 std::stringstream ss;;
382 ss <<
"<state id=\"" << mId <<
"\"";
385 ss <<
" final=\"yes\" /";
387 ss <<
">" << std::endl;
389 for(std::vector<Transition>::const_iterator it = mTransitions.begin(); it != mTransitions.end(); ++it)
391 ss <<
"\t" << it->toXML() <<
"\n";
394 for(std::vector<EmbeddedStateMachine>::const_iterator it = mEmbeddedStateMachines.begin(); it != mEmbeddedStateMachines.end(); ++it)
396 ss <<
"\t" << it->toXML() <<
"\n";
◆ default_transition::ConversationCancelFailure
◆ default_transition::ConversationCancelling
◆ default_transition::ConversationCancelSuccess
◆ default_transition::GeneralFailure
◆ default_transition::NotUnderstood
◆ StateMachine
◆ StateMachineReader
◆ Transition
◆ CONVERSATION_CANCEL_FAILURE
| const StateId fipa::acl::State::CONVERSATION_CANCEL_FAILURE = "__internal_state:conversation_cancel_failure__" |
|
static |
◆ CONVERSATION_CANCEL_SUCCESS
| const StateId fipa::acl::State::CONVERSATION_CANCEL_SUCCESS = "__internal_state:conversation_cancel_success__" |
|
static |
◆ CONVERSATION_CANCELLING
| const StateId fipa::acl::State::CONVERSATION_CANCELLING = "__internal_state:conversation_cancelling__" |
|
static |
◆ GENERAL_FAILURE_STATE
| const StateId fipa::acl::State::GENERAL_FAILURE_STATE = "__internal_state:general_failure__" |
|
static |
◆ NOT_UNDERSTOOD
| const StateId fipa::acl::State::NOT_UNDERSTOOD = "__internal_state:not_understood__" |
|
static |
◆ UNDEFINED_ID
| const StateId fipa::acl::State::UNDEFINED_ID = "__undefined__" |
|
static |
Default states
Definition at line 103 of file state.h.
The documentation for this class was generated from the following files:
- /build/rock-master-18.09-multiagent-fipa-acl-0.20180914/src/conversation_monitor/state.h
- /build/rock-master-18.09-multiagent-fipa-acl-0.20180914/src/conversation_monitor/state.cpp