diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-01-13 16:47:44 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-01-13 16:47:44 (GMT) |
commit | 4f6cbe9e7aec2b4a6c8f286f9097abfb011a6235 (patch) | |
tree | 8c023473bb342780ddf51a893d18369f1319bb5c /src/uscxml/plugins/invoker/scxml | |
parent | 0aa0fe08dc308c94379c47d0bf9745e341cb4c81 (diff) | |
download | uscxml-4f6cbe9e7aec2b4a6c8f286f9097abfb011a6235.zip uscxml-4f6cbe9e7aec2b4a6c8f286f9097abfb011a6235.tar.gz uscxml-4f6cbe9e7aec2b4a6c8f286f9097abfb011a6235.tar.bz2 |
First support for serialization and some bug fixes for DOM per data.src
Diffstat (limited to 'src/uscxml/plugins/invoker/scxml')
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 41 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 7 |
2 files changed, 38 insertions, 10 deletions
diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index 868fee7..0f7cc24 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -75,6 +75,29 @@ void USCXMLInvoker::stop() { } } +void USCXMLInvoker::deserialize(const Data& encodedState) { + _invokedInterpreter.deserialize(encodedState["intepreter"]); +} + +Data USCXMLInvoker::serialize() { + Data encodedState; + + std::lock_guard<std::recursive_mutex> lock(_mutex); + + InterpreterState state = USCXML_UNDEF; + while((state = _invokedInterpreter.getState())) { + if (state != USCXML_IDLE && state != USCXML_MACROSTEPPED && state != USCXML_FINISHED) { + _cond.wait(_mutex); + } else { + break; + } + } + + encodedState["intepreter"] = Data(_invokedInterpreter.serialize()); + + return encodedState; +} + void USCXMLInvoker::uninvoke() { _isActive = false; stop(); @@ -100,13 +123,9 @@ void USCXMLInvoker::run(void* instance) { InterpreterState state = USCXML_UNDEF; while(state != USCXML_FINISHED) { - state = INSTANCE->_invokedInterpreter.step(); - -// if (!INSTANCE->_isStarted) { -// // we have been cancelled -// INSTANCE->_isActive = false; -// return; -// } + std::lock_guard<std::recursive_mutex> lock(INSTANCE->_mutex); + state = INSTANCE->_invokedInterpreter.step(200); + INSTANCE->_cond.notify_all(); } if (INSTANCE->_isActive) { @@ -143,10 +162,11 @@ void USCXMLInvoker::invoke(const std::string& source, const Event& invokeEvent) XERCESC_NS::DOMNode* newNode = document->importNode(invokeEvent.data.node, true); document->appendChild(newNode); -// std::cout << *document << std::endl; - // TODO: where do we get the namespace from? _invokedInterpreter = Interpreter::fromDocument(document, _interpreter->getBaseURL(), false); + } else if (invokeEvent.data.atom.size() > 0) { + // test530 when deserializing + _invokedInterpreter = Interpreter::fromXML(invokeEvent.data.atom, _interpreter->getBaseURL()); } else { _isActive = false; @@ -191,7 +211,8 @@ void USCXMLInvoker::invoke(const std::string& source, const Event& invokeEvent) start(); } else { - /// test 530 + // test 530 + // TODO: Is this the correct thing/place to do? Event e("done.invoke." + invokeEvent.invokeid, Event::PLATFORM); eventToSCXML(e, USCXML_INVOKER_SCXML_TYPE, _invokeId); _isActive = false; diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index 9509de3..78e7057 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -67,6 +67,9 @@ public: virtual void invoke(const std::string& source, const Event& invokeEvent); virtual void uninvoke(); + virtual void deserialize(const Data& encodedState); + virtual Data serialize(); + protected: void start(); @@ -78,6 +81,10 @@ protected: std::thread* _thread; EventQueue _parentQueue; Interpreter _invokedInterpreter; + + std::recursive_mutex _mutex; + std::condition_variable_any _cond; + }; #ifdef BUILD_AS_PLUGINS |