implements a XML parser that generates a state machine from a given spec. file; uses the tinyXML library
More...
#include <statemachine_reader.h>
|
| static const std::string | transition = std::string("transition") |
| |
| static const std::string | from = std::string("from") |
| |
| static const std::string | to = std::string("to") |
| |
| static const std::string | target = std::string("target") |
| |
| static const std::string | id = std::string("id") |
| |
| static const std::string | final = std::string("final") |
| |
| static const std::string | performative = std::string("performative") |
| |
| static const std::string | initial = std::string("initial") |
| |
| static const std::string | subprotocol = std::string("subprotocol") |
| |
| static const std::string | mapping = std::string("mapping") |
| |
| static const std::string | name = std::string("name") |
| |
| static const std::string | proxiedTo = std::string("proxied_to") |
| |
implements a XML parser that generates a state machine from a given spec. file; uses the tinyXML library
Definition at line 24 of file statemachine_reader.h.
| StateMachine fipa::acl::StateMachineReader::loadSpecification |
( |
const std::string & |
file | ) |
|
Load the specification and return the corresponding state machine for it
- Parameters
-
| file | name of the file containing the specification for the statemachine |
- Returns
- the statemachine build from spec
Definition at line 30 of file statemachine_reader.cpp.
33 FILE* file = fopen(protocolSpec.c_str(),
"r");
38 LOG_ERROR_S <<
"error loading the spec file: '" << protocolSpec <<
"'. File does not exist.";
39 throw std::runtime_error(
"Error loading the specification file: '" + protocolSpec +
"' -- file does not exist");
43 TiXmlDocument file = TiXmlDocument(protocolSpec.c_str());
47 LOG_ERROR_S <<
"error loading the spec file: '" << protocolSpec <<
"'. Please use setProtocolResourceDir(const std::string&) instead to specify the location of your protocol files";
48 throw std::runtime_error(
"Error loading the specification file: '" + protocolSpec +
"' -- tinyxml failed to load the file");
51 LOG_DEBUG_S <<
"loadSpecification: specification file 'protocolSpec'";
52 TiXmlElement* statemachineElement = file.RootElement();
56 boost::filesystem::path path(protocolSpec);
57 statemachine.setProtocol( path.filename().string());
59 statemachine.generateDefaultTransitions();
60 statemachine.generateDefaultStates();
61 statemachine.updateRoles();
62 statemachine.validate();
StateMachine parseStateMachineNode(TiXmlElement *statemachineElement)
| StateMachine fipa::acl::StateMachineReader::parseStateMachineNode |
( |
TiXmlElement * |
statemachineElement | ) |
|
Read the xml structure defining a statemachine
- Parameters
-
| statemachineElement | the element describing the stateMachine |
| protocolSpec | name of the file containing the specification for the statemachine |
- Returns
- the parsed state machine
Definition at line 67 of file statemachine_reader.cpp.
69 StateMachine statemachine;
71 const char *initialState;
76 statemachine.setInitialState(std::string(initialState));
78 throw std::runtime_error(
"Attribute of initial could not be retrieved");
80 LOG_DEBUG_S <<
"parseStateMachineNode: retrieved value of the \"initial\" state: " << std::string(initialState);
82 TiXmlHandle handleSm = TiXmlHandle(statemachineElement);
83 TiXmlElement* stateElement = handleSm.FirstChild(
"state" ).ToElement();
86 LOG_DEBUG_S <<
"parseStateMachineNode: found first state element";
88 LOG_WARN_S <<
"parseStateMachineNode: no state element found";
92 for (; stateElement != NULL; stateElement = stateElement->NextSiblingElement(
"state") )
95 LOG_DEBUG_S <<
"Adding state: " << state.toString();
96 statemachine.addState(state);
State parseStateNode(TiXmlElement *stateElement)
method that parses the <state> element of the spec. file
static const std::string initial
| State fipa::acl::StateMachineReader::parseStateNode |
( |
TiXmlElement * |
stateElement | ) |
|
method that parses the <state> element of the spec. file
- Parameters
-
- Returns
- the parsed state
Definition at line 102 of file statemachine_reader.cpp.
110 state.setId(std::string(stateId));
114 throw std::runtime_error(std::string(buffer));
117 const char*
final = NULL;
121 std::string isFinal(
final);
122 if (isFinal ==
"yes" || isFinal ==
"true" || isFinal ==
"1")
124 state.setFinal(
true);
125 }
else if (isFinal ==
"no" || isFinal ==
"false" || isFinal ==
"0")
127 state.setFinal(
false);
130 sprintf(buffer,
"Invalid value for attribute \"final\" of state node: %s",
final);
131 throw std::runtime_error(std::string(buffer));
136 TiXmlHandle handleState = TiXmlHandle(stateElement);
141 state.addTransition(t);
143 LOG_DEBUG_S <<
"parseStateNode: state: " << state.getId() <<
" -> transition added: from (Role) " << t.getSenderRole().getId()
144 <<
", to (Role) " << t.getReceiverRole().getId() <<
", target state: " << t.getTargetStateId() <<
", performative "
145 << t.getPerformativeRegExp();
155 EmbeddedStateMachine esm;
162 throw new std::runtime_error(
"StateMachineReader::parseStateNode subprotocol is missing 'name' attribute");
169 esm.fromRole = Role( std::string(from->c_str()));
171 throw new std::runtime_error(
"StateMachineReader::parseStateNode mapping is missing 'from' attribute");
175 if (proxiedTo != NULL)
178 esm.proxiedToRole = Role( std::string(proxiedTo->c_str()));
181 state.addEmbeddedStateMachine(esm);
182 LOG_DEBUG_S <<
"parseStateNode: state: " << state.getId() <<
" -> subprotocol added:\n" << esm.toString();
static const std::string id
static const std::string name
static const std::string transition
static const std::string subprotocol
static const std::string from
static const std::string proxiedTo
Transition parseTransitionNode(TiXmlElement *transitionElement)
method that parses <transition> element of the spec. file
static const std::string final
| Transition fipa::acl::StateMachineReader::parseTransitionNode |
( |
TiXmlElement * |
transitionElement | ) |
|
method that parses <transition> element of the spec. file
- Parameters
-
- Returns
- transition
Definition at line 188 of file statemachine_reader.cpp.
191 const char *
from = NULL;
195 transition.setSenderRole( Role( std::string(from) ));
197 throw new std::runtime_error(
"StateMachineReader::parseTransitionsNode Transitions is missing 'from' attribute");
200 const char*
to = NULL;
204 transition.setReceiverRole( Role( std::string(to) ) );
206 throw new std::runtime_error(
"StateMachineReader::parseTransitionsNode transition is missing 'to' attribute");
209 const char* targetState = NULL;
213 transition.setTargetState(std::string(targetState));
216 throw std::runtime_error(
"Could not retrieve attribute for target state");
223 transition.setPerformativeRegExp( performative );
225 throw new std::runtime_error(
"StateMachineReader::parseTransitionsNode transition is missing 'performative' attribute");
static const std::string target
static const std::string to
static const std::string transition
static const std::string performative
static const std::string from
| const std::string fipa::acl::StateMachineReader::final = std::string("final") |
|
static |
| const std::string fipa::acl::StateMachineReader::from = std::string("from") |
|
static |
| const std::string fipa::acl::StateMachineReader::id = std::string("id") |
|
static |
| const std::string fipa::acl::StateMachineReader::initial = std::string("initial") |
|
static |
| const std::string fipa::acl::StateMachineReader::mapping = std::string("mapping") |
|
static |
| const std::string fipa::acl::StateMachineReader::name = std::string("name") |
|
static |
| const std::string fipa::acl::StateMachineReader::performative = std::string("performative") |
|
static |
| const std::string fipa::acl::StateMachineReader::proxiedTo = std::string("proxied_to") |
|
static |
| const std::string fipa::acl::StateMachineReader::subprotocol = std::string("subprotocol") |
|
static |
| const std::string fipa::acl::StateMachineReader::target = std::string("target") |
|
static |
| const std::string fipa::acl::StateMachineReader::to = std::string("to") |
|
static |
| const std::string fipa::acl::StateMachineReader::transition = std::string("transition") |
|
static |
The documentation for this class was generated from the following files: