fipa_acl  1.4
statemachine.h
Go to the documentation of this file.
1 
9 #ifndef _FIPAACL_CONVMONITOR_STATEMACHINE_H_
10 #define _FIPAACL_CONVMONITOR_STATEMACHINE_H_
11 
12 #include <fipa_acl/bitefficient_message.h>
13 #include <fipa_acl/conversation_monitor/state.h>
14 #include <fipa_acl/conversation_monitor/message_archive.h>
15 #include <vector>
16 
17 namespace fipa {
18 namespace acl {
19 
20 class MessageArchive;
21 
23 {
24  friend class StateMachineReader;
25 
26  // Initial state of the state machine, i.e. equals current state when starting
27  // the state machine
28  StateId mInitialStateId;
29 
30  // Current state of the statemachine
31  StateId mCurrentStateId;
32 
36  std::map<StateId, State> mStates;
37 
41  RoleMapping mRoleMapping;
42 
46  MessageArchive mMessageArchive;
47 
51  fipa::acl::Protocol mProtocol;
52 
56  void generateDefaultStates();
57 
61  void generateDefaultTransitions();
62 
63 protected:
68  void validate() const;
69 
73  void reset();
74 
79  void setInitialState(const StateId& stateId) { mInitialStateId = stateId; }
80 
85  void addState(const State& state);
86 
90  void updateRoles();
91 
97  void updateRoleMapping(const ACLMessage& msg, const Transition& transition);
98 
99 public:
104  std::map<StateId, State> getStates() const { return mStates; }
105 
109  const RoleMapping& getRoleMapping() const { return mRoleMapping; }
110 
115  const State& getCurrentState() const;
116 
122 
123  void setCurrentStateId(const StateId& stateId) { mCurrentStateId = stateId; }
124 
129  StateId getCurrentStateId() const { return mCurrentStateId; }
130 
135  StateId getInitialStateId() const { return mInitialStateId; }
136 
140  void setProtocol(const fipa::acl::Protocol& protocol) { mProtocol = protocol; }
141 
146  fipa::acl::Protocol getProtocol() const { return mProtocol; }
147 
151  void setSelf(const AgentID& self);
152 
159  void consumeMessage(const ACLMessage& msg);
160 
168  void consumeSubStateMachineMessage(const ACLMessage& msg, const fipa::acl::StateMachine& stateMachine, int numberOfSubConversations);
169 
174  bool inFinalState() const;
175 
180  bool inFailureState() const;
181 
186  bool cancelled() const;
187 
191  std::string toString() const;
192 
193  std::string toXML() const;
194 };
195 
201 {
202  // The initiator of the sub-protocol(s)
203  std::string from;
204  // and it's role.
206  // The name of teh sub-protocol
207  std::string name;
208  // To whom responses are forwarded back. Can be empty for propagate instead of proxy.
209  std::string proxiedTo;
210  // and it's role.
212 
213  // The following attributes is mutable, as modified after the initial instantiation.
214  // The conversation sets this to the actually used protocol, and the number of planned subconverstions.
215  // This enables all getter methods to still be const.
216  // XXX This is not the cleanest design solution!
217 
218  // This is set during runtime and refers to the actually used protocol. If name is a regular expression, this can be different.
219  mutable std::string actualProtocol;
220 
221  // The planned number of sub conversations
222  // -1 is the default value, which is not valid.
224 
225  // If this is true, a proxied reply has been received and the embedded state machine is finished.
227 
228  /* This state machine is constructed by statemachine_reader. It then has to be copied for each actually
229  * sub conversation started.
230  */
232 
234  : numberOfSubConversations(-1)
235  {}
236 
240  std::string toString() const;
241 
245  std::string toXML() const;
246 };
247 
248 } // end of acl
249 } // end of fipa
250 
251 #endif
fipa::acl::Protocol getProtocol() const
Definition: statemachine.h:146
void consumeMessage(const ACLMessage &msg)
std::string Protocol
Definition: acl_message.h:29
StateId getCurrentStateId() const
Definition: statemachine.h:129
void setProtocol(const fipa::acl::Protocol &protocol)
Definition: statemachine.h:140
implements a state of the StateMachine class
Definition: state.h:41
const State & getCurrentState() const
void setCurrentStateId(const StateId &stateId)
Definition: statemachine.h:123
std::string toXML() const
std::string StateId
Definition: state.h:35
std::map< StateId, State > getStates() const
Definition: statemachine.h:104
StateId getInitialStateId() const
Definition: statemachine.h:135
void setInitialState(const StateId &stateId)
Definition: statemachine.h:79
void setSelf(const AgentID &self)
implements a XML parser that generates a state machine from a given spec. file; uses the tinyXML libr...
std::string toString() const
Mapping between roles and actual agent ids.
Definition: role.h:98
An embedded state machine with mappings.
Definition: statemachine.h:200
const RoleMapping & getRoleMapping() const
Definition: statemachine.h:109
void updateRoleMapping(const ACLMessage &msg, const Transition &transition)
State & getCurrentStateModifiably()
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
void addState(const State &state)
void consumeSubStateMachineMessage(const ACLMessage &msg, const fipa::acl::StateMachine &stateMachine, int numberOfSubConversations)
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Definition: agent_id.h:37
Foundation of Physical Intelligent Agents.
Definition: conversation.cpp:6