summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Interpreter.cpp
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-07-05 11:35:04 (GMT)
committerGitHub <noreply@github.com>2017-07-05 11:35:04 (GMT)
commitcb2f533085542a753fc45d17fdb09396c46fbadc (patch)
tree66d378d1df7cb82834e944a1f37865809abf75ae /src/uscxml/Interpreter.cpp
parent3f10e11d6ad2b97fee4aee6e09bc959ba9b8e0e5 (diff)
parenta0f96c5dd050c524223ac644ba8798bc7cc80bfd (diff)
downloaduscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.zip
uscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.tar.gz
uscxml-cb2f533085542a753fc45d17fdb09396c46fbadc.tar.bz2
Merge pull request #155 from tklab-tud/sradomski
More performant monitors with slight API break
Diffstat (limited to 'src/uscxml/Interpreter.cpp')
-rw-r--r--src/uscxml/Interpreter.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp
index b20013f..c4025ba 100644
--- a/src/uscxml/Interpreter.cpp
+++ b/src/uscxml/Interpreter.cpp
@@ -82,7 +82,7 @@ Interpreter Interpreter::fromXML(const std::string& xml, const std::string& base
interpreterImpl->_document = parser->adoptDocument();
interpreterImpl->_baseURL = absUrl;
- interpreterImpl->_md5 = md5(xml);
+ interpreterImpl->_md5 = md5(xml);
InterpreterImpl::addInstance(interpreterImpl);
} catch (const XERCESC_NS::SAXParseException& toCatch) {
@@ -151,7 +151,7 @@ Interpreter Interpreter::fromURL(const std::string& url) {
#if 1
// Xercesc is hard to build with SSL on windows, whereas curl uses winssl
- return fromXML(absUrl.getInContent(), absUrl);
+ return fromXML(absUrl.getInContent(), absUrl);
#else
std::shared_ptr<InterpreterImpl> interpreterImpl(new InterpreterImpl());
@@ -191,6 +191,15 @@ Interpreter Interpreter::fromURL(const std::string& url) {
}
+Interpreter Interpreter::fromSessionId(const std::string& sessionId) {
+ std::lock_guard<std::recursive_mutex> lock(InterpreterImpl::_instanceMutex);
+ std::map<std::string, std::weak_ptr<InterpreterImpl> > instances = InterpreterImpl::getInstances();
+ if (instances.find(sessionId) != instances.end()) {
+ return Interpreter(instances[sessionId].lock());
+ }
+ return Interpreter();
+}
+
void Interpreter::reset() {
return _impl->reset();
}
@@ -274,19 +283,20 @@ static void printNodeSet(Logger& logger, const std::list<XERCESC_NS::DOMElement*
std::recursive_mutex StateTransitionMonitor::_mutex;
-void StateTransitionMonitor::beforeTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition) {
+void StateTransitionMonitor::beforeTakingTransition(const std::string& sessionId, const XERCESC_NS::DOMElement* transition) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
LOG(_logger, USCXML_VERBATIM) << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl;
}
-void StateTransitionMonitor::onStableConfiguration(Interpreter& interpreter) {
+void StateTransitionMonitor::onStableConfiguration(const std::string& sessionId) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
+ Interpreter interpreter = Interpreter::fromSessionId(sessionId);
LOG(_logger, USCXML_VERBATIM) << "Stable Config: { ";
printNodeSet(_logger, interpreter.getConfiguration());
LOG(_logger, USCXML_VERBATIM) << " }" << std::endl;
}
-void StateTransitionMonitor::beforeProcessingEvent(Interpreter& interpreter, const uscxml::Event& event) {
+void StateTransitionMonitor::beforeProcessingEvent(const std::string& sessionId, const uscxml::Event& event) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
switch (event.eventType) {
case uscxml::Event::INTERNAL:
@@ -301,24 +311,29 @@ void StateTransitionMonitor::beforeProcessingEvent(Interpreter& interpreter, con
}
}
-void StateTransitionMonitor::beforeExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* element) {
+void StateTransitionMonitor::beforeExecutingContent(const std::string& sessionId, const XERCESC_NS::DOMElement* element) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
LOG(_logger, USCXML_VERBATIM) << "Executable Content: " << DOMUtils::xPathForNode(element) << std::endl;
}
-void StateTransitionMonitor::beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {
+void StateTransitionMonitor::beforeExitingState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
LOG(_logger, USCXML_VERBATIM) << "Exiting: " << (HAS_ATTR(state, kXMLCharId) ? ATTR(state, kXMLCharId) : DOMUtils::xPathForNode(state)) << std::endl;
}
-void StateTransitionMonitor::beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) {
+void StateTransitionMonitor::beforeEnteringState(const std::string& sessionId,
+ const std::string& stateName,
+ const XERCESC_NS::DOMElement* state) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
LOG(_logger, USCXML_VERBATIM) << "Entering: " << (HAS_ATTR(state, kXMLCharId) ? ATTR(state, kXMLCharId) : DOMUtils::xPathForNode(state)) << std::endl;
}
-void StateTransitionMonitor::beforeMicroStep(Interpreter& interpreter) {
+void StateTransitionMonitor::beforeMicroStep(const std::string& sessionId) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
+ Interpreter interpreter = Interpreter::fromSessionId(sessionId);
LOG(_logger, USCXML_VERBATIM) << "Microstep in config: {";
printNodeSet(_logger, interpreter.getConfiguration());
LOG(_logger, USCXML_VERBATIM) << "}" << std::endl;