diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-31 11:31:14 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-31 11:31:14 (GMT) |
commit | eab5c12b2a1b9cfee94e8d0cbe41fb5d78594bb5 (patch) | |
tree | da32c5d07f126a6a0c8de42009f13c170198adaa /src | |
parent | 6bf9b12de158cb5fc6c94ab41b84c27968ea9340 (diff) | |
download | uscxml-eab5c12b2a1b9cfee94e8d0cbe41fb5d78594bb5.zip uscxml-eab5c12b2a1b9cfee94e8d0cbe41fb5d78594bb5.tar.gz uscxml-eab5c12b2a1b9cfee94e8d0cbe41fb5d78594bb5.tar.bz2 |
More adhoc extensions for interpreters
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/swig/uscxml_beautify.i | 4 | ||||
-rw-r--r-- | src/bindings/swig/uscxml_ignores.i | 1 | ||||
-rw-r--r-- | src/uscxml/Interpreter.cpp | 36 | ||||
-rw-r--r-- | src/uscxml/Interpreter.h | 15 | ||||
-rw-r--r-- | src/uscxml/plugins/EventHandler.h | 9 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 7 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 1 |
7 files changed, 59 insertions, 14 deletions
diff --git a/src/bindings/swig/uscxml_beautify.i b/src/bindings/swig/uscxml_beautify.i index 76f371e..4f3d246 100644 --- a/src/bindings/swig/uscxml_beautify.i +++ b/src/bindings/swig/uscxml_beautify.i @@ -67,6 +67,10 @@ void setDataModel(WrappedDataModel* dataModel) { self->setDataModel(boost::shared_ptr<DataModelImpl>(dataModel)); } + + void setInvoker(const std::string invokeId, uscxml::WrappedInvoker* invoker) { + self->setInvoker(invokeId, boost::shared_ptr<InvokerImpl>(invoker)); + } std::vector<std::string> getBasicConfiguration() { Arabica::XPath::NodeSet<std::string> nativeConfig = self->getBasicConfiguration(); diff --git a/src/bindings/swig/uscxml_ignores.i b/src/bindings/swig/uscxml_ignores.i index b6a0a3f..f7d3dad 100644 --- a/src/bindings/swig/uscxml_ignores.i +++ b/src/bindings/swig/uscxml_ignores.i @@ -47,6 +47,7 @@ %ignore uscxml::Interpreter::setCmdLineOptions(std::map<std::string, std::string>); %ignore uscxml::Interpreter::setDataModel(const DataModel& dataModel); %ignore uscxml::Interpreter::addIOProcessor(IOProcessor ioProc); +%ignore uscxml::Interpreter::setInvoker(const std::string& invokeId, Invoker invoker); %ignore uscxml::Interpreter::getDocument; %ignore uscxml::Interpreter::getImpl; %ignore uscxml::Interpreter::runOnMainThread; diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 5fcc3f7..b8e4bfe 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -1385,19 +1385,29 @@ void InterpreterImpl::invoke(const Arabica::DOM::Node<std::string>& element) { invokeReq.type = "http://www.w3.org/TR/scxml/"; Invoker invoker; - try { - invoker = _factory->createInvoker(invokeReq.type, this); - } catch (Event e) { - receiveInternal(e); - } - if (invoker) { - tthread::lock_guard<tthread::recursive_mutex> lock(_pluginMutex); + // is there such an invoker already? + if (_invokers.find(invokeReq.invokeid) != _invokers.end()) { + invoker = _invokers[invokeReq.invokeid]; + } else { try { + invoker = _factory->createInvoker(invokeReq.type, this); invoker.setInvokeId(invokeReq.invokeid); - invoker.setType(invokeReq.type); invoker.setInterpreter(this); - invoker.setElement(Element<std::string>(element)); _invokers[invokeReq.invokeid] = invoker; + } catch (Event e) { + receiveInternal(e); + } + } + if (invoker) { + tthread::lock_guard<tthread::recursive_mutex> lock(_pluginMutex); + try { + + if (!invoker.getElement()) + invoker.setElement(Element<std::string>(element)); + + if (invoker.getType().size() == 0) + invoker.setType(invokeReq.type); + try { USCXML_MONITOR_CALLBACK3(beforeInvoking, Arabica::DOM::Element<std::string>(element), invokeReq.invokeid); @@ -1453,7 +1463,13 @@ void InterpreterImpl::cancelInvoke(const Arabica::DOM::Node<std::string>& elemen USCXML_MONITOR_CALLBACK3(beforeUninvoking, Element<std::string>(element), invokeId) _invokers[invokeId].uninvoke(); - _invokers.erase(invokeId); + + /** + * This should not be necessary. Most invokers have their "clean-up" code in their + * destructor and not their uninvoke method - we need to refactor them all! + */ + if (_dontDestructOnUninvoke.find(invokeId) == _dontDestructOnUninvoke.end()) + _invokers.erase(invokeId); USCXML_MONITOR_CALLBACK3(beforeUninvoking, Element<std::string>(element), invokeId) diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 8a2b282..dc889e3 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -364,7 +364,7 @@ public: nameIter++; } } - + const std::map<std::string, IOProcessor>& getIOProcessors() { return _ioProcessors; } @@ -377,6 +377,13 @@ public: return _dataModel; } + void setInvoker(const std::string& invokeId, Invoker invoker) { + _dontDestructOnUninvoke.insert(invokeId); + _invokers[invokeId] = invoker; + _invokers[invokeId].setInterpreter(this); + _invokers[invokeId].setInvokeId(invokeId); + } + const std::map<std::string, Invoker>& getInvokers() { return _invokers; } @@ -466,7 +473,8 @@ protected: bool _isInitialized; bool _domIsSetup; bool _userSuppliedDataModel; - + std::set<std::string> _dontDestructOnUninvoke; + bool _isStarted; bool _isRunning; @@ -657,6 +665,9 @@ public: return _impl->getIOProcessors(); } + void setInvoker(const std::string& invokeId, Invoker invoker) { + _impl->setInvoker(invokeId, invoker); + } const std::map<std::string, Invoker>& getInvokers() { return _impl->getInvokers(); } diff --git a/src/uscxml/plugins/EventHandler.h b/src/uscxml/plugins/EventHandler.h index 7b38575..4078cfe 100644 --- a/src/uscxml/plugins/EventHandler.h +++ b/src/uscxml/plugins/EventHandler.h @@ -49,7 +49,10 @@ public: void setType(const std::string& type) { _type = type; } - + std::string getType() { + return _type; + } + void setElement(const Arabica::DOM::Element<std::string>& element) { _element = element; } @@ -101,9 +104,13 @@ public: void setInvokeId(const std::string& invokeId) { _impl->setInvokeId(invokeId); } + void setType(const std::string& type) { _impl->setType(type); } + std::string getType() { + return _impl->getType(); + } void setElement(const Arabica::DOM::Element<std::string>& element) { _impl->setElement(element); diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index f232e52..9506867 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -40,12 +40,16 @@ USCXMLInvoker::USCXMLInvoker() : _cancelled(false) { USCXMLInvoker::~USCXMLInvoker() { +}; + +void USCXMLInvoker::uninvoke() { _cancelled = true; Event event; event.name = "unblock.and.die"; if (_invokedInterpreter) _invokedInterpreter.receive(event); -}; + +} boost::shared_ptr<InvokerImpl> USCXMLInvoker::create(InterpreterImpl* interpreter) { boost::shared_ptr<USCXMLInvoker> invoker = boost::shared_ptr<USCXMLInvoker>(new USCXMLInvoker()); @@ -67,6 +71,7 @@ void USCXMLInvoker::cancel(const std::string sendId) { } void USCXMLInvoker::invoke(const InvokeRequest& req) { + _cancelled = false; if (req.src.length() > 0) { _invokedInterpreter = Interpreter::fromURI(req.src); } else if (req.dom) { diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index 7d10bf1..f6aa77a 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -60,6 +60,7 @@ public: virtual void send(const SendRequest& req); virtual void cancel(const std::string sendId); virtual void invoke(const InvokeRequest& req); + virtual void uninvoke(); protected: bool _cancelled; |