summaryrefslogtreecommitdiffstats
path: root/src/uscxml/interpreter/InterpreterDraft7.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-30 16:08:37 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-03-30 16:08:37 (GMT)
commit28014abf13ca64031b8b84dcf585ec4569881ab0 (patch)
tree9680223cdbd3adde5bd80d18f1b29ea3a0990e4f /src/uscxml/interpreter/InterpreterDraft7.cpp
parent2317f2bf8beb03c60463a9482dbef23540f5c1e0 (diff)
downloaduscxml-28014abf13ca64031b8b84dcf585ec4569881ab0.zip
uscxml-28014abf13ca64031b8b84dcf585ec4569881ab0.tar.gz
uscxml-28014abf13ca64031b8b84dcf585ec4569881ab0.tar.bz2
Various bug fixes
- Removed scxml-test-framework related file - Array operator with V8NodeList - _event.data as DOM if content is XML
Diffstat (limited to 'src/uscxml/interpreter/InterpreterDraft7.cpp')
-rw-r--r--src/uscxml/interpreter/InterpreterDraft7.cpp100
1 files changed, 50 insertions, 50 deletions
diff --git a/src/uscxml/interpreter/InterpreterDraft7.cpp b/src/uscxml/interpreter/InterpreterDraft7.cpp
index 9542146..7af2d39 100644
--- a/src/uscxml/interpreter/InterpreterDraft7.cpp
+++ b/src/uscxml/interpreter/InterpreterDraft7.cpp
@@ -27,12 +27,12 @@ procedure interpret(doc):
void InterpreterDraft7::interpret() {
if (!_isInitialized)
init();
-
+
if (!_scxml)
return;
-
+
_sessionId = getUUID();
-
+
std::string datamodelName;
if (datamodelName.length() == 0 && HAS_ATTR(_scxml, "datamodel"))
datamodelName = ATTR(_scxml, "datamodel");
@@ -43,7 +43,7 @@ void InterpreterDraft7::interpret() {
if(datamodelName.length() > 0 && !_dataModel) {
LOG(ERROR) << "No datamodel for " << datamodelName << " registered";
}
-
+
if (_dataModel) {
_dataModel.assign("_x.args", _cmdLineOptions);
if (_httpServlet) {
@@ -52,14 +52,14 @@ void InterpreterDraft7::interpret() {
_dataModel.assign("_ioprocessors['http']", data);
}
}
-
+
setupIOProcessors();
-
+
_running = true;
_binding = (HAS_ATTR(_scxml, "binding") && boost::iequals(ATTR(_scxml, "binding"), "late") ? LATE : EARLY);
-
+
// @TODO: Reread http://www.w3.org/TR/scxml/#DataBinding
-
+
if (_dataModel && _binding == EARLY) {
// initialize all data elements
NodeSet<std::string> dataElems = _xpath.evaluate("//" + _xpathPrefix + "data", _document).asNodeSet();
@@ -73,14 +73,14 @@ void InterpreterDraft7::interpret() {
initializeData(topDataElems[i]);
}
}
-
+
// executeGlobalScriptElements
NodeSet<std::string> globalScriptElems = _xpath.evaluate("/" + _xpathPrefix + "scxml/" + _xpathPrefix + "script", _document).asNodeSet();
for (unsigned int i = 0; i < globalScriptElems.size(); i++) {
if (_dataModel)
executeContent(globalScriptElems[i]);
}
-
+
// initial transition might be implict
NodeSet<std::string> initialTransitions = _xpath.evaluate("/" + _xpathPrefix + "scxml/" + _xpathPrefix + "initial/" + _xpathPrefix + "transition", _document).asNodeSet();
if (initialTransitions.size() == 0) {
@@ -97,21 +97,21 @@ void InterpreterDraft7::interpret() {
}
}
enterStates(initialTransitions);
-
+
// assert(hasLegalConfiguration());
mainEventLoop();
-
+
if (_parentQueue) {
// send one final event to unblock eventual listeners
Event quit;
quit.name = "done.state.scxml";
_parentQueue->push(quit);
}
-
+
// set datamodel to null from this thread
if(_dataModel)
_dataModel = DataModel();
-
+
}
/**
@@ -127,7 +127,7 @@ void InterpreterDraft7::initializeData(const Arabica::DOM::Node<std::string>& da
LOG(ERROR) << "Data element has no id!";
return;
}
-
+
if (HAS_ATTR(data, "expr")) {
std::string value = ATTR(data, "expr");
_dataModel.assign(ATTR(data, "id"), value);
@@ -135,7 +135,7 @@ void InterpreterDraft7::initializeData(const Arabica::DOM::Node<std::string>& da
URL srcURL(ATTR(data, "src"));
if (!srcURL.isAbsolute())
toAbsoluteURI(srcURL);
-
+
std::stringstream ss;
if (_cachedURLs.find(srcURL.asString()) != _cachedURLs.end()) {
ss << _cachedURLs[srcURL.asString()];
@@ -144,7 +144,7 @@ void InterpreterDraft7::initializeData(const Arabica::DOM::Node<std::string>& da
_cachedURLs[srcURL.asString()] = srcURL;
}
_dataModel.assign(ATTR(data, "id"), ss.str());
-
+
} else if (data.hasChildNodes()) {
// search for the text node with the actual script
NodeList<std::string> dataChilds = data.getChildNodes();
@@ -156,7 +156,7 @@ void InterpreterDraft7::initializeData(const Arabica::DOM::Node<std::string>& da
}
}
}
-
+
} catch (Event e) {
LOG(ERROR) << "Syntax error in data element:" << std::endl << e << std::endl;
}
@@ -167,12 +167,12 @@ procedure mainEventLoop():
while running:
enabledTransitions = null
macrostepDone = false
- # Here we handle eventless transitions and transitions
+ # Here we handle eventless transitions and transitions
# triggered by internal events until macrostep is complete
while running and not macrostepDone:
enabledTransitions = selectEventlessTransitions()
if enabledTransitions.isEmpty():
- if internalQueue.isEmpty():
+ if internalQueue.isEmpty():
macrostepDone = true
else:
internalEvent = internalQueue.dequeue()
@@ -180,7 +180,7 @@ procedure mainEventLoop():
enabledTransitions = selectTransitions(internalEvent)
if not enabledTransitions.isEmpty():
microstep(enabledTransitions.toList())
- # either we're in a final state, and we break out of the loop
+ # either we're in a final state, and we break out of the loop
if not running:
break;
# or we've completed a macrostep, so we start a new macrostep by waiting for an external event
@@ -189,7 +189,7 @@ procedure mainEventLoop():
for inv in state.invoke:
invoke(inv)
statesToInvoke.clear()
- # Invoking may have raised internal error events and we iterate to handle them
+ # Invoking may have raised internal error events and we iterate to handle them
if not internalQueue.isEmpty():
continue
# A blocking wait for an external event. Alternatively, if we have been invoked
@@ -205,12 +205,12 @@ procedure mainEventLoop():
if inv.invokeid == externalEvent.invokeid:
applyFinalize(inv, externalEvent)
if inv.autoforward:
- send(inv.id, externalEvent)
+ send(inv.id, externalEvent)
enabledTransitions = selectTransitions(externalEvent)
if not enabledTransitions.isEmpty():
- microstep(enabledTransitions.toList())
- # End of outer while running loop. If we get here, we have reached a top-level final state or have been cancelled
- exitInterpreter()
+ microstep(enabledTransitions.toList())
+ # End of outer while running loop. If we get here, we have reached a top-level final state or have been cancelled
+ exitInterpreter()
*/
void InterpreterDraft7::mainEventLoop() {
}
@@ -224,7 +224,7 @@ procedure exitInterpreter():
for inv in s.invoke:
cancelInvoke(inv)
configuration.delete(s)
- if isFinalState(s) and isScxmlState(s.parent):
+ if isFinalState(s) and isScxmlState(s.parent):
returnDoneEvent(s.donedata)
*/
void InterpreterDraft7::exitInterpreter() {
@@ -246,7 +246,7 @@ function selectEventlessTransitions():
for state in atomicStates:
loop: for s in [state].append(getProperAncestors(state, null)):
for t in s.transition:
- if not t.event and conditionMatch(t):
+ if not t.event and conditionMatch(t):
enabledTransitions.add(t)
break loop
enabledTransitions = filterPreempted(enabledTransitions)
@@ -275,7 +275,7 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft7::selectTransitions(const
procedure enterStates(enabledTransitions):
statesToEnter = new OrderedSet()
statesForDefaultEntry = new OrderedSet()
- computeEntrySet(enabledTransitions, statesToEnter, statesForDefaultEntry)
+ computeEntrySet(enabledTransitions, statesToEnter, statesForDefaultEntry)
for s in statesToEnter.toList().sort(entryOrder):
configuration.add(s)
statesToInvoke.add(s)
@@ -302,14 +302,14 @@ void InterpreterDraft7::enterStates(const Arabica::XPath::NodeSet<std::string>&
/**
procedure exitStates(enabledTransitions):
- statesToExit = computeExitSet(enabledTransitions)
+ statesToExit = computeExitSet(enabledTransitions)
for s in statesToExit:
statesToInvoke.delete(s)
statesToExit = statesToExit.toList().sort(exitOrder)
for s in statesToExit:
for h in s.history:
if h.type == "deep":
- f = lambda s0: isAtomicState(s0) and isDescendant(s0,s)
+ f = lambda s0: isAtomicState(s0) and isDescendant(s0,s)
else:
f = lambda s0: s0.parent == s
historyValue[h.id] = configuration.toList().filter(f)
@@ -330,27 +330,27 @@ function computeExitSet(transitions)
domain = getTransitionDomain(t)
for s in configuration:
if isDescendant(s,domain):
- statesToExit.add(s)
- return statesToExit
+ statesToExit.add(s)
+ return statesToExit
*/
Arabica::XPath::NodeSet<std::string> InterpreterDraft7::computeExitSet(const Arabica::XPath::NodeSet<std::string>& enabledTransitions,
- const Arabica::XPath::NodeSet<std::string>& statesToExit) {
+ const Arabica::XPath::NodeSet<std::string>& statesToExit) {
}
/**
procedure computeEntrySet(transitions, statesToEnter, statesForDefaultEntry)
for t in transitions:
- statesToEnter.union(getTargetStates(t.target))
+ statesToEnter.union(getTargetStates(t.target))
for s in statesToEnter:
- addDescendentStatesToEnter(s,statesToEnter,statesForDefaultEntry)
- for t in transitions:
- ancestor = getTransitionDomain(t)
- for s in getTargetStates(t.target)):
+ addDescendentStatesToEnter(s,statesToEnter,statesForDefaultEntry)
+ for t in transitions:
+ ancestor = getTransitionDomain(t)
+ for s in getTargetStates(t.target)):
addAncestorStatesToEnter(s, ancestor, statesToEnter, statesForDefaultEntry)
*/
Arabica::XPath::NodeSet<std::string> InterpreterDraft7::computeEntrySet(const Arabica::XPath::NodeSet<std::string>& transitions,
- const Arabica::XPath::NodeSet<std::string>& statesToEnter,
- const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
+ const Arabica::XPath::NodeSet<std::string>& statesToEnter,
+ const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
}
/**
@@ -364,14 +364,14 @@ function removeConflictingTransitions(enabledTransitions):
if computeExitSet(t1).hasIntersection(computeExitSet(t2)):
if isDescendent(t1.source, t2.source):
transitionsToRemove.add(t2)
- else:
+ else:
t1Preempted = true
break
if not t1Preempted:
for t3 in transitionsToRemove.toList():
filteredTransitions.delete(t3)
filteredTransitions.add(t1)
-
+
return filteredTransitions
*/
Arabica::XPath::NodeSet<std::string> InterpreterDraft7::removeConflictingTransitions(const Arabica::XPath::NodeSet<std::string>& enabledTransitions) {
@@ -413,11 +413,11 @@ Arabica::DOM::Node<std::string> InterpreterDraft7::getTransitionDomain(const Ara
if isParallelState(state):
for child in getChildStates(state):
if not statesToEnter.some(lambda s: isDescendant(s,child)):
- addDescendentStatesToEnter(child,statesToEnter,statesForDefaultEntry)
+ addDescendentStatesToEnter(child,statesToEnter,statesForDefaultEntry)
*/
Arabica::XPath::NodeSet<std::string> InterpreterDraft7::addDescendentStatesToEnter(const Arabica::DOM::Node<std::string>& state,
- const Arabica::XPath::NodeSet<std::string>& statesToEnter,
- const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
+ const Arabica::XPath::NodeSet<std::string>& statesToEnter,
+ const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
}
/**
@@ -427,12 +427,12 @@ Arabica::XPath::NodeSet<std::string> InterpreterDraft7::addDescendentStatesToEnt
if isParallelState(anc):
for child in getChildStates(anc):
if not statesToEnter.some(lambda s: isDescendant(s,child)):
- addStatesToEnter(child,statesToEnter,statesForDefaultEntry)
+ addStatesToEnter(child,statesToEnter,statesForDefaultEntry)
*/
Arabica::XPath::NodeSet<std::string> InterpreterDraft7::addAncestorsStatesToEnter(const Arabica::DOM::Node<std::string>& state,
- const Arabica::DOM::Node<std::string>& ancestor,
- const Arabica::XPath::NodeSet<std::string>& statesToEnter,
- const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
+ const Arabica::DOM::Node<std::string>& ancestor,
+ const Arabica::XPath::NodeSet<std::string>& statesToEnter,
+ const Arabica::XPath::NodeSet<std::string>& statesForDefaultEntry) {
}