#include <statemachine.h>
Definition at line 22 of file statemachine.h.
| void fipa::acl::StateMachine::addState |
( |
const State & |
state | ) |
|
|
protected |
Add a state to the state machine – the state might already contain transition definitions in order to check for properly defined transitions, validate needs to be called
Definition at line 67 of file statemachine.cpp.
69 std::map<StateId, State>::const_iterator it = mStates.find(state.getId());
70 if(it != mStates.end())
72 std::string msg =
"State '" + state.getId() +
"' already defined";
73 LOG_ERROR(
"%s", msg.c_str());
74 throw std::runtime_error(msg);
76 mStates[state.getId()] = state;
| bool fipa::acl::StateMachine::cancelled |
( |
| ) |
const |
Check whether the conversation has been successfully cancelled
- Returns
- true if the conversation was successfully cancelled
Definition at line 227 of file statemachine.cpp.
static const StateId CONVERSATION_CANCEL_SUCCESS
| void fipa::acl::StateMachine::consumeMessage |
( |
const ACLMessage & |
msg | ) |
|
Consume a message If this is the first message it will initialize the roles for the first state
- Parameters
-
| msg | Message which should be consumed |
- Exceptions
-
| std::runtime_error | if message could not be consumed |
Definition at line 187 of file statemachine.cpp.
189 LOG_DEBUG(
"StateMachine consumeMessage");
194 const Transition& transition = currentState.getTransition(msg, mMessageArchive, mRoleMapping);
199 mCurrentStateId = transition.getTargetStateId();
201 catch(
const std::exception& e)
203 LOG_DEBUG(
"StateMachine consumeMessage trying substatemachine proxied transition");
206 const Transition& transition = currentState.getSubstateMachineProxiedTransition(msg, mMessageArchive, mRoleMapping);
211 mCurrentStateId = transition.getTargetStateId();
void addMessage(const ACLMessage &msg)
void updateRoleMapping(const ACLMessage &msg, const Transition &transition)
State & getCurrentStateModifiably()
const State & getCurrentState() const
Consume a message meant for sub state machine. The given stateMachine is only used to be copied, if necessary.
- Parameters
-
| msg | Message which should be consumed |
- Exceptions
-
| std::runtime_error | if message could not be consumed |
Definition at line 179 of file statemachine.cpp.
181 LOG_DEBUG(
"StateMachine consumeSubStateMachineMessage");
184 currentState.consumeSubStateMachineMessage(msg, stateMachine, mRoleMapping, numberOfSubConversations);
State & getCurrentStateModifiably()
| const State & fipa::acl::StateMachine::getCurrentState |
( |
| ) |
const |
Get current state.
- Exceptions
-
| std::runtime_error | if statemachine has not been properly initialized |
Definition at line 148 of file statemachine.cpp.
150 if(mCurrentStateId.empty())
152 throw std::runtime_error(
"Statemachine has not been properly initialized: current state not set");
154 std::map<StateId, State>::const_iterator it = mStates.find(mCurrentStateId);
155 if(it == mStates.end())
157 throw std::runtime_error(
"Statemachine has not been properly initialized: current state not found");
| StateId fipa::acl::StateMachine::getCurrentStateId |
( |
| ) |
const |
|
inline |
Get the current state
- Returns
- state id
Definition at line 129 of file statemachine.h.
129 {
return mCurrentStateId; }
| State & fipa::acl::StateMachine::getCurrentStateModifiably |
( |
| ) |
|
Get current state. Non const!
- Exceptions
-
| std::runtime_error | if statemachine has not been properly initialized |
Definition at line 132 of file statemachine.cpp.
134 if(mCurrentStateId.empty())
136 throw std::runtime_error(
"Statemachine has not been properly initialized: current state not set");
138 std::map<StateId, State>::iterator it = mStates.find(mCurrentStateId);
139 if(it == mStates.end())
141 throw std::runtime_error(
"Statemachine has not been properly initialized: current state not found");
| StateId fipa::acl::StateMachine::getInitialStateId |
( |
| ) |
const |
|
inline |
Get the id initial state
- Returns
- id of the initial state
Definition at line 135 of file statemachine.h.
135 {
return mInitialStateId; }
Get protocol (which is set by the initiating message)
- Returns
- Protocol
Definition at line 146 of file statemachine.h.
146 {
return mProtocol; }
| const RoleMapping& fipa::acl::StateMachine::getRoleMapping |
( |
| ) |
const |
|
inline |
| std::map<StateId, State> fipa::acl::StateMachine::getStates |
( |
| ) |
const |
|
inline |
Get the states mapping
- Returns
- states container
Definition at line 104 of file statemachine.h.
| bool fipa::acl::StateMachine::inFailureState |
( |
| ) |
const |
Check if state machine is in a known failure state
- Returns
- true if the current state of the machine is in a (known) error state
Definition at line 222 of file statemachine.cpp.
static const StateId GENERAL_FAILURE_STATE
static const StateId CONVERSATION_CANCEL_FAILURE
| bool fipa::acl::StateMachine::inFinalState |
( |
| ) |
const |
Check if the state machine is in a final state, i.e. the conversation has ended
- Returns
- true if the current state of the state machine is final
Definition at line 215 of file statemachine.cpp.
219 return currentState.isFinished();
const State & getCurrentState() const
| void fipa::acl::StateMachine::reset |
( |
| ) |
|
|
protected |
Reset the current state to the initial state
Definition at line 62 of file statemachine.cpp.
64 mCurrentStateId = mInitialStateId;
| void fipa::acl::StateMachine::setCurrentStateId |
( |
const StateId & |
stateId | ) |
|
|
inline |
| void fipa::acl::StateMachine::setInitialState |
( |
const StateId & |
stateId | ) |
|
|
inlineprotected |
Set the initial state
- Parameters
-
| stateId | State to which the state machine should be set |
Definition at line 79 of file statemachine.h.
79 { mInitialStateId = stateId; }
Set the protocol for this conversation
Definition at line 140 of file statemachine.h.
140 { mProtocol = protocol; }
| void fipa::acl::StateMachine::setSelf |
( |
const AgentID & |
self | ) |
|
Set self agents id – can only be called once per state machine
Definition at line 163 of file statemachine.cpp.
void setSelf(const AgentID &id)
| std::string fipa::acl::StateMachine::toString |
( |
| ) |
const |
Convert statemachine to string
Definition at line 232 of file statemachine.cpp.
234 std::stringstream statemachine;
235 statemachine <<
"Statemachine: (" << mProtocol <<
")\n";
236 std::map<StateId, State>::const_iterator it = mStates.begin();
237 for(; it != mStates.end(); ++it)
239 statemachine << it->second.toString();
241 return statemachine.str();
| std::string fipa::acl::StateMachine::toXML |
( |
| ) |
const |
Definition at line 255 of file statemachine.cpp.
257 std::stringstream ss;
258 ss <<
"<scxml version=\"1.0\" initial=\"1\">" << std::endl;
259 std::map<StateId, State>::const_iterator it = mStates.begin();
260 for(; it != mStates.end(); ++it)
262 ss << it->second.toXML();
264 ss <<
"</scxml>" << std::endl;
| void fipa::acl::StateMachine::updateRoleMapping |
( |
const ACLMessage & |
msg, |
|
|
const Transition & |
transition |
|
) |
| |
|
protected |
Update the role mapping
- Parameters
-
Definition at line 168 of file statemachine.cpp.
172 AgentIDList::const_iterator it = receivers.begin();
173 for(; it != receivers.end(); ++it)
std::vector< AgentID > AgentIDList
void addExpectedAgent(const Role &role, const AgentID &agent)
| void fipa::acl::StateMachine::updateRoles |
( |
| ) |
|
|
protected |
Given all states update the roles
Definition at line 80 of file statemachine.cpp.
82 std::map<StateId, State>::iterator it = mStates.begin();
83 for(; it != mStates.end(); ++it)
85 std::vector<Transition> transitions = it->second.getTransitions();
86 std::vector<Transition>::const_iterator transitionIt = transitions.begin();
87 for(; transitionIt != transitions.end(); ++transitionIt)
89 mRoleMapping.
addRole(transitionIt->getSenderRole());
90 mRoleMapping.
addRole(transitionIt->getReceiverRole());
void addRole(const Role &role)
| void fipa::acl::StateMachine::validate |
( |
| ) |
const |
|
protected |
Check wether the state and transition in this state machine are valid
- Exceptions
-
| std::runtime_error | if the machine cannot be properly validated |
Definition at line 29 of file statemachine.cpp.
33 std::set<StateId> referencedStates;
34 std::map<StateId, State>::const_iterator statesIt = mStates.begin();
36 for(; statesIt != mStates.end(); ++statesIt)
38 const State& state = statesIt->second;
39 std::vector<Transition> transitions = state.getTransitions();
40 std::vector<Transition>::const_iterator transitionsIt = transitions.begin();
42 for(; transitionsIt != transitions.end(); ++transitionsIt)
44 referencedStates.insert(transitionsIt->getTargetStateId());
45 referencedStates.insert(transitionsIt->getSourceStateId());
49 std::set<StateId>::const_iterator referencedStatesIt = referencedStates.begin();
50 for(; referencedStatesIt != referencedStates.end(); ++referencedStatesIt)
52 statesIt = mStates.find(*referencedStatesIt);
53 if(statesIt == mStates.end())
55 std::string msg =
"Unknown state '" + *referencedStatesIt +
"' referred to in statemachine";
56 LOG_ERROR(
"%s", msg.c_str());
57 throw std::runtime_error(msg);
The documentation for this class was generated from the following files:
- /build/rock-master-18.09-multiagent-fipa-acl-0.20180914/src/conversation_monitor/statemachine.h
- /build/rock-master-18.09-multiagent-fipa-acl-0.20180914/src/conversation_monitor/statemachine.cpp