summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/invoker
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/plugins/invoker')
-rw-r--r--src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp41
-rw-r--r--src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h7
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