diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-05 12:24:46 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-05 12:24:46 (GMT) |
commit | 48009e6bafca54d117bee81ea2a8b41f2aae1d70 (patch) | |
tree | e791f120ce5de86484c8fb3c3d5bc2163e8773d0 /src | |
parent | 5a7c8fd646d77139f216755085e1252a1dee334d (diff) | |
download | uscxml-48009e6bafca54d117bee81ea2a8b41f2aae1d70.zip uscxml-48009e6bafca54d117bee81ea2a8b41f2aae1d70.tar.gz uscxml-48009e6bafca54d117bee81ea2a8b41f2aae1d70.tar.bz2 |
Redownloaded tests and fixed some more w3c issues
Diffstat (limited to 'src')
-rw-r--r-- | src/uscxml/Factory.h | 5 | ||||
-rw-r--r-- | src/uscxml/Interpreter.cpp | 27 | ||||
-rw-r--r-- | src/uscxml/Message.h | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterDraft6.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp | 38 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h | 3 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp | 2 |
7 files changed, 64 insertions, 17 deletions
diff --git a/src/uscxml/Factory.h b/src/uscxml/Factory.h index 65dc5fd..990b035 100644 --- a/src/uscxml/Factory.h +++ b/src/uscxml/Factory.h @@ -243,6 +243,7 @@ public: virtual void eval(const std::string& expr) = 0; virtual std::string evalAsString(const std::string& expr) = 0; virtual bool evalAsBool(const std::string& expr) = 0; + virtual void assign(const std::string& location, const Arabica::DOM::Document<std::string>& doc) = 0; virtual void assign(const std::string& location, const std::string& expr) = 0; virtual void assign(const std::string& location, const Data& data) = 0; virtual bool isDeclared(const std::string& expr) = 0; @@ -305,6 +306,10 @@ public: return _impl->evalAsBool(expr); } + virtual void assign(const std::string& location, const Arabica::DOM::Document<std::string>& doc) { + return _impl->assign(location, doc); + } + virtual void assign(const std::string& location, const std::string& expr) { return _impl->assign(location, expr); } diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 5f54cc7..86f40c1 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -289,9 +289,12 @@ void Interpreter::init() { } else { LOG(ERROR) << "Cannot find SCXML element" << std::endl; + _done = true; + return; } } else { LOG(ERROR) << "Interpreter has no DOM at all!" << std::endl; + _done = true; } _isInitialized = true; } @@ -353,12 +356,27 @@ void Interpreter::initializeData(const Node<std::string>& data) { _cachedURLs[srcURL.asString()] = srcURL; } contentToProcess = ss.str(); + + // try to parse as XML + std::stringstream* xmlStr = new std::stringstream(); + (*xmlStr) << contentToProcess; + std::auto_ptr<std::istream> ssPtr(xmlStr); + Arabica::SAX::InputSource<std::string> inputSource; + inputSource.setByteStream(ssPtr); + Arabica::SAX2DOM::Parser<std::string> parser; + if(parser.parse(inputSource) && parser.getDocument()) { + _dataModel.assign(ATTR(data, "id"), parser.getDocument()); + return; + } } else if (data.hasChildNodes()) { bool presentAsDom = false; Node<std::string> contentChild = data.getFirstChild(); while(contentChild) { if (contentChild.getNodeType() == Node_base::TEXT_NODE) { - break; + std::string trimmed = contentChild.getNodeValue(); + boost::trim(trimmed); + if (trimmed.length() > 0) + break; } if (contentChild.getNodeType() == Node_base::ELEMENT_NODE) { presentAsDom = true; @@ -368,7 +386,12 @@ void Interpreter::initializeData(const Node<std::string>& data) { } if (contentChild && presentAsDom) { - LOG(ERROR) << "Passing DOM in data is TODO."; + Arabica::DOM::DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation(); + Document<std::string> dom = domFactory.createDocument(contentChild.getNamespaceURI(), "", 0); + Node<std::string> newNode = dom.importNode(contentChild, true); + dom.appendChild(newNode); + _dataModel.assign(ATTR(data, "id"), dom); + return; } else if (contentChild) { // get first child and process below contentToProcess = contentChild.getNodeValue(); diff --git a/src/uscxml/Message.h b/src/uscxml/Message.h index 19adf99..ae88225 100644 --- a/src/uscxml/Message.h +++ b/src/uscxml/Message.h @@ -28,7 +28,7 @@ public: Data() {} Data(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {} - Data(const Arabica::DOM::Node<std::string>& dom); + explicit Data(const Arabica::DOM::Node<std::string>& dom); virtual ~Data() {} static Data fromJSON(const std::string& jsonString); diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index 453e64f..2f05be9 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -13,8 +13,10 @@ void InterpreterDraft6::interpret() { if (!_isInitialized) init(); - if (!_scxml) + if (!_scxml) { + _mutex.unlock(); return; + } // dump(); if (_sessionId.length() == 0) diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index e86472b..1d01e12 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -99,6 +99,7 @@ v8::Handle<v8::Value> V8DataModel::getIOProcessors(v8::Local<v8::String> propert std::map<std::string, IOProcessor> ioProcessors = dataModel->_interpreter->getIOProcessors(); std::map<std::string, IOProcessor>::const_iterator ioProcIter = ioProcessors.begin(); while(ioProcIter != ioProcessors.end()) { + std::cout << ioProcIter->first << std::endl; dataModel->_ioProcessors->Set(v8::String::New(ioProcIter->first.c_str()), dataModel->getDataAsValue(ioProcIter->second.getDataModelVariables())); ioProcIter++; @@ -143,18 +144,7 @@ void V8DataModel::setEvent(const Event& event) { eventObj->SetInternalField(0, Arabica::DOM::V8DOM::toExternal(privData)); eventObj.MakeWeak(0, Arabica::DOM::V8SCXMLEvent::jsDestructor); if (event.dom) { - // _event.data is a DOM document - v8::Handle<v8::Function> retCtor = Arabica::DOM::V8Document::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct Arabica::DOM::V8Document::V8DocumentPrivate* retPrivData = new Arabica::DOM::V8Document::V8DocumentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = (Arabica::DOM::Document<std::string>*)&event.dom; - - retObj->SetInternalField(0, Arabica::DOM::V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, Arabica::DOM::V8Document::jsDestructor); - - eventObj->Set(v8::String::New("data"), retObj); + eventObj->Set(v8::String::New("data"), getDocumentAsValue(event.dom)); } else if (event.content.length() > 0) { // _event.data is a string eventObj->Set(v8::String::New("data"), v8::String::New(event.content.c_str())); @@ -253,6 +243,20 @@ Data V8DataModel::getValueAsData(const v8::Handle<v8::Value>& value) { return data; } +v8::Handle<v8::Value> V8DataModel::getDocumentAsValue(const Arabica::DOM::Document<std::string>& doc) { + v8::Handle<v8::Function> retCtor = Arabica::DOM::V8Document::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct Arabica::DOM::V8Document::V8DocumentPrivate* retPrivData = new Arabica::DOM::V8Document::V8DocumentPrivate(); + retPrivData->dom = _dom; + retPrivData->nativeObj = new Arabica::DOM::Document<std::string>(doc); + + retObj->SetInternalField(0, Arabica::DOM::V8DOM::toExternal(retPrivData)); + retObj.MakeWeak(0, Arabica::DOM::V8Document::jsDestructor); + + return retObj; +} + v8::Handle<v8::Value> V8DataModel::getDataAsValue(const Data& data) { if (data.compound.size() > 0) { v8::Handle<v8::Object> value = v8::Object::New(); @@ -385,6 +389,16 @@ double V8DataModel::evalAsNumber(const std::string& expr) { return 0; } +void V8DataModel::assign(const std::string& location, const Arabica::DOM::Document<std::string>& doc) { + v8::Locker locker; + v8::HandleScope handleScope; + v8::Context::Scope contextScope(_contexts.front()); + v8::Handle<v8::Object> global = _contexts.front()->Global(); + + global->Set(v8::String::New(location.c_str()), getDocumentAsValue(doc)); + +} + void V8DataModel::assign(const std::string& location, const Data& data) { v8::Locker locker; v8::HandleScope handleScope; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 6348cbc..e67e4ca 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -40,11 +40,13 @@ public: virtual void popContext(); virtual void eval(const std::string& expr); + virtual void assign(const std::string& location, const Arabica::DOM::Document<std::string>& doc); virtual void assign(const std::string& location, const std::string& expr); virtual void assign(const std::string& location, const Data& data); virtual Data getStringAsData(const std::string& content); virtual Data getValueAsData(const v8::Handle<v8::Value>& value); + virtual bool isDeclared(const std::string& expr); virtual std::string evalAsString(const std::string& expr); @@ -66,6 +68,7 @@ protected: v8::Handle<v8::Value> evalAsValue(const std::string& expr); v8::Handle<v8::Value> getDataAsValue(const Data& data); + v8::Handle<v8::Value> getDocumentAsValue(const Arabica::DOM::Document<std::string>& doc); void throwExceptionEvent(const v8::TryCatch& tryCatch); }; diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp index bbd2538..a142231 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.cpp @@ -49,7 +49,7 @@ void USCXMLInvoker::invoke(const InvokeRequest& req) { } else if (req.dom) { _invokedInterpreter = Interpreter::fromDOM(req.dom); } else if (req.content.size() > 0) { - LOG(ERROR) << "Instantiating nested SCXML interpreter by content not supported yet"; + LOG(ERROR) << "Instantiating nested SCXML interpreter by content or expr not supported yet"; } else { LOG(ERROR) << "Cannot invoke nested SCXML interpreter, neither src attribute nor DOM is given"; } |