diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-15 10:08:41 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-15 10:08:41 (GMT) |
commit | 9149b28c87c7a037dfd244aa5d4c1409b6593dca (patch) | |
tree | 939c00d28864910a0ca8a67e70fadae9b6f05cc7 /src/uscxml | |
parent | 322e868668a1e5b9595a21737aabe8d0d8b8d275 (diff) | |
download | uscxml-9149b28c87c7a037dfd244aa5d4c1409b6593dca.zip uscxml-9149b28c87c7a037dfd244aa5d4c1409b6593dca.tar.gz uscxml-9149b28c87c7a037dfd244aa5d4c1409b6593dca.tar.bz2 |
More JVoiceXML integration
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/URL.cpp | 8 | ||||
-rw-r--r-- | src/uscxml/messages/Event.cpp | 23 | ||||
-rw-r--r-- | src/uscxml/messages/Event.h | 2 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.cpp | 267 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.h | 342 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/CMakeLists.txt | 24 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.cpp | 227 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.h | 105 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp | 52 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h | 3 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp | 12 |
11 files changed, 730 insertions, 335 deletions
diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index f5ba85c..b245149 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -565,6 +565,12 @@ void URLFetcher::fetchURL(URL& url) { // (curlError = curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1)) == CURLE_OK || // LOG(ERROR) << "Cannot set curl to ignore signals: " << curl_easy_strerror(curlError); +// (curlError = curl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1)) == CURLE_OK || +// LOG(ERROR) << "Cannot force noreuse: " << curl_easy_strerror(curlError); + + (curlError = curl_easy_setopt(handle, CURLOPT_VERBOSE, 1)) == CURLE_OK || + LOG(ERROR) << "Cannot set verbose: " << curl_easy_strerror(curlError); + (curlError = curl_easy_setopt(handle, CURLOPT_WRITEDATA, url._impl.get())) == CURLE_OK || LOG(ERROR) << "Cannot register this as write userdata: " << curl_easy_strerror(curlError); @@ -580,7 +586,7 @@ void URLFetcher::fetchURL(URL& url) { (curlError = curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, false)) == CURLE_OK || LOG(ERROR) << "Cannot forfeit peer verification: " << curl_easy_strerror(curlError); - (curlError = curl_easy_setopt(handle, CURLOPT_USERAGENT, "curl/7.31.0")) == CURLE_OK || + (curlError = curl_easy_setopt(handle, CURLOPT_USERAGENT, "uscxml/0.3.3")) == CURLE_OK || LOG(ERROR) << "Cannot set our user agent string: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, true)) == CURLE_OK || diff --git a/src/uscxml/messages/Event.cpp b/src/uscxml/messages/Event.cpp index 43c6600..fda24dd 100644 --- a/src/uscxml/messages/Event.cpp +++ b/src/uscxml/messages/Event.cpp @@ -72,29 +72,6 @@ Arabica::DOM::Document<std::string> Event::toDocument() { return document; } -void Event::initContent(const std::string& content) { - // try to parse as JSON - Data json = Data::fromJSON(content); - if (!json.empty()) { - data = json; - return; - } - - // try to parse as XML - Arabica::SAX2DOM::Parser<std::string> parser; - Arabica::SAX::CatchErrorHandler<std::string> errorHandler; - parser.setErrorHandler(errorHandler); - - std::istringstream is(content); - Arabica::SAX::InputSource<std::string> inputSource; - inputSource.setByteStream(is); - if (parser.parse(inputSource)) { - dom = parser.getDocument(); - return; - } - - this->content = content; -} Event Event::fromXML(const std::string& xmlString) { Arabica::SAX2DOM::Parser<std::string> eventParser; diff --git a/src/uscxml/messages/Event.h b/src/uscxml/messages/Event.h index a63c55f..d282fc2 100644 --- a/src/uscxml/messages/Event.h +++ b/src/uscxml/messages/Event.h @@ -182,8 +182,6 @@ public: this->data = data; } - void initContent(const std::string& content); - static Event fromXML(const std::string& xmlString); Arabica::DOM::Document<std::string> toDocument(); std::string toXMLString(); diff --git a/src/uscxml/messages/MMIMessages.cpp b/src/uscxml/messages/MMIMessages.cpp index 01705ed..dffda5b 100644 --- a/src/uscxml/messages/MMIMessages.cpp +++ b/src/uscxml/messages/MMIMessages.cpp @@ -28,6 +28,30 @@ #include <boost/algorithm/string.hpp> +#define TO_EVENT_OPERATOR(type, name, base)\ +type::operator Event() const { \ + Event ev = base::operator Event();\ + ev.setName(name);\ + if (representation == MMI_AS_XML) \ + ev.setDOM(toXML());\ + return ev;\ +} + +#define FIND_MSG_ELEM(elem, doc) \ +Element<std::string> elem; \ +if (encapsulateInMMI) { \ + elem = Element<std::string>(doc.getDocumentElement().getFirstChild()); \ +} else { \ + elem = Element<std::string>(doc.getDocumentElement()); \ +} + +#define FROM_XML(clazz, enumType, base) \ +clazz clazz::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { \ + clazz event = base::fromXML(node, interpreter); \ + event.type = enumType; \ + return event; \ +} + #define STRING_ATTR_OR_EXPR(element, name)\ (element.hasAttributeNS(nameSpace, "name##Expr") && interpreter ? \ interpreter->getDataModel().evalAsString(element.getAttributeNS(nameSpace, "name##Expr")) : \ @@ -35,6 +59,8 @@ ) #define FIND_EVENT_NODE(node)\ +if (node.getNodeType() == Node_base::DOCUMENT_NODE) \ + node = node.getFirstChild(); \ while (node) {\ if (node.getNodeType() == Node_base::ELEMENT_NODE) {\ if (boost::iequals(node.getLocalName(), "MMI")) {\ @@ -117,16 +143,16 @@ Arabica::DOM::Document<std::string> MMIEvent::toXML(bool encapsulateInMMI) const msgElem.setAttributeNS(nameSpace, "Target", target); msgElem.setAttributeNS(nameSpace, "RequestID", requestId); - if (data.size() > 0) { - Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data"); - Text<std::string> textElem = doc.createTextNode(data); - dataElem.appendChild(textElem); - msgElem.appendChild(dataElem); - } else if (dataDOM) { + if (dataDOM) { Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data"); Node<std::string> importNode = doc.importNode(dataDOM, true); dataElem.appendChild(importNode); msgElem.appendChild(dataElem); + } else if (data.size() > 0) { + Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data"); + Text<std::string> textElem = doc.createTextNode(data); + dataElem.appendChild(textElem); + msgElem.appendChild(dataElem); } if (encapsulateInMMI) { @@ -139,16 +165,9 @@ Arabica::DOM::Document<std::string> MMIEvent::toXML(bool encapsulateInMMI) const return doc; } -Arabica::DOM::Document<std::string> ContextualizedRequest::toXML(bool encapsulateInMMI) const { - Document<std::string> doc = MMIEvent::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); - msgElem.setAttributeNS(nameSpace, "Context", context); - return doc; -} - Arabica::DOM::Document<std::string> ContentRequest::toXML(bool encapsulateInMMI) const { Document<std::string> doc = ContextualizedRequest::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); + FIND_MSG_ELEM(msgElem, doc); if (contentURL.href.size() > 0) { Element<std::string> contentURLElem = doc.createElementNS(nameSpace, "ContentURL"); @@ -170,16 +189,23 @@ Arabica::DOM::Document<std::string> ContentRequest::toXML(bool encapsulateInMMI) return doc; } +Arabica::DOM::Document<std::string> ContextualizedRequest::toXML(bool encapsulateInMMI) const { + Document<std::string> doc = MMIEvent::toXML(encapsulateInMMI); + FIND_MSG_ELEM(msgElem, doc); + msgElem.setAttributeNS(nameSpace, "Context", context); + return doc; +} + Arabica::DOM::Document<std::string> ExtensionNotification::toXML(bool encapsulateInMMI) const { Document<std::string> doc = ContextualizedRequest::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); + FIND_MSG_ELEM(msgElem, doc); msgElem.setAttributeNS(nameSpace, "Name", name); return doc; } Arabica::DOM::Document<std::string> StatusResponse::toXML(bool encapsulateInMMI) const { Document<std::string> doc = ContextualizedRequest::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); + FIND_MSG_ELEM(msgElem, doc); if (status == ALIVE) { msgElem.setAttributeNS(nameSpace, "Status", "alive"); } else if(status == DEAD) { @@ -194,7 +220,7 @@ Arabica::DOM::Document<std::string> StatusResponse::toXML(bool encapsulateInMMI) Arabica::DOM::Document<std::string> StatusInfoResponse::toXML(bool encapsulateInMMI) const { Document<std::string> doc = StatusResponse::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); + FIND_MSG_ELEM(msgElem, doc); Element<std::string> statusInfoElem = doc.createElementNS(nameSpace, "StatusInfo"); Text<std::string> statusInfoText = doc.createTextNode(statusInfo); @@ -206,7 +232,7 @@ Arabica::DOM::Document<std::string> StatusInfoResponse::toXML(bool encapsulateIn Arabica::DOM::Document<std::string> StatusRequest::toXML(bool encapsulateInMMI) const { Document<std::string> doc = ContextualizedRequest::toXML(encapsulateInMMI); - Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); + FIND_MSG_ELEM(msgElem, doc); if (automaticUpdate) { msgElem.setAttributeNS(nameSpace, "RequestAutomaticUpdate", "true"); @@ -217,18 +243,22 @@ Arabica::DOM::Document<std::string> StatusRequest::toXML(bool encapsulateInMMI) return doc; } + + MMIEvent MMIEvent::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { MMIEvent msg; + FIND_EVENT_NODE(node); Element<std::string> msgElem(node); msg.source = STRING_ATTR_OR_EXPR(msgElem, Source); msg.target = STRING_ATTR_OR_EXPR(msgElem, Target); -// msg.data = STRING_ATTR_OR_EXPR(msgElem, Data); msg.requestId = STRING_ATTR_OR_EXPR(msgElem, RequestID); msg.tagName = msgElem.getLocalName(); Element<std::string> dataElem; + + // search for data element node = msgElem.getFirstChild(); while (node) { if (node.getNodeType() == Node_base::ELEMENT_NODE) @@ -239,47 +269,60 @@ MMIEvent MMIEvent::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl } if (dataElem && boost::iequals(dataElem.getLocalName(), "data") && dataElem.getFirstChild()) { - node = dataElem.getFirstChild(); - if (node.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { - msg.dataDOM = node; - } else { - std::stringstream ss; - ss << node; - msg.data = ss.str(); + Arabica::DOM::Node<std::string> dataChild = dataElem.getFirstChild(); + std::stringstream ss; + + while (dataChild) { + if (dataChild.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) + msg.dataDOM = dataChild; + ss << dataChild; + dataChild = dataChild.getNextSibling(); } + msg.data = ss.str(); } return msg; } -MMIEvent::operator Event() const { - Event ev; - ev.setOriginType("mmi.event"); - ev.setOrigin(source); - ev.setRaw(data); - ev.setSendId(requestId); - if (data.length() > 0) { - ev.initContent(data); - } - return ev; -} +FROM_XML(NewContextRequest, NEWCONTEXTREQUEST, MMIEvent) + +FROM_XML(PauseRequest, PAUSEREQUEST, ContextualizedRequest) +FROM_XML(ResumeRequest, RESUMEREQUEST, ContextualizedRequest) +FROM_XML(ClearContextRequest, CLEARCONTEXTREQUEST, ContextualizedRequest) +FROM_XML(CancelRequest, CANCELREQUEST, ContextualizedRequest) + +FROM_XML(PrepareRequest, PREPAREREQUEST, ContentRequest) +FROM_XML(StartRequest, STARTREQUEST, ContentRequest) + +FROM_XML(PrepareResponse, PREPARERESPONSE, StatusInfoResponse) +FROM_XML(StartResponse, STARTRESPONSE, StatusInfoResponse) +FROM_XML(CancelResponse, CANCELRESPONSE, StatusInfoResponse) +FROM_XML(PauseResponse, PAUSERESPONSE, StatusInfoResponse) +FROM_XML(ResumeResponse, RESUMERESPONSE, StatusInfoResponse) +FROM_XML(ClearContextResponse, CLEARCONTEXTRESPONSE, StatusInfoResponse) +FROM_XML(NewContextResponse, NEWCONTEXTRESPONSE, StatusInfoResponse) +FROM_XML(DoneNotification, DONENOTIFICATION, StatusInfoResponse) + ContextualizedRequest ContextualizedRequest::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { ContextualizedRequest msg(MMIEvent::fromXML(node, interpreter)); FIND_EVENT_NODE(node); - + Element<std::string> msgElem(node); msg.context = STRING_ATTR_OR_EXPR(msgElem, Context); return msg; } -ContextualizedRequest::operator Event() const { - Event ev = MMIEvent::operator Event(); - // do we want to represent the context? It's the interpreters name already - return ev; +ExtensionNotification ExtensionNotification::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { + ExtensionNotification msg(ContextualizedRequest::fromXML(node, interpreter)); + FIND_EVENT_NODE(node); + + Element<std::string> msgElem(node); + msg.name = STRING_ATTR_OR_EXPR(msgElem, Name); + msg.type = EXTENSIONNOTIFICATION; + return msg; } - ContentRequest ContentRequest::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { ContentRequest msg(ContextualizedRequest::fromXML(node, interpreter)); FIND_EVENT_NODE(node); @@ -300,16 +343,17 @@ ContentRequest ContentRequest::fromXML(Arabica::DOM::Node<std::string> node, Int if (contentElem) { if(boost::iequals(contentElem.getLocalName(), "content")) { + Arabica::DOM::Node<std::string> contentChild = contentElem.getFirstChild(); std::stringstream ss; - node = contentElem.getFirstChild(); - while (node) { - if (node.getNodeType() == Node_base::ELEMENT_NODE) { - ss << node; - break; - } - node = node.getNextSibling(); + + while (contentChild) { + if (contentChild.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) + msg.contentDOM = contentChild; + ss << contentChild; + contentChild = contentChild.getNextSibling(); } msg.content = ss.str(); + } else if(boost::iequals(contentElem.getLocalName(), "contentURL")) { msg.contentURL.href = STRING_ATTR_OR_EXPR(contentElem, href); msg.contentURL.maxAge = STRING_ATTR_OR_EXPR(contentElem, max-age); @@ -321,26 +365,6 @@ ContentRequest ContentRequest::fromXML(Arabica::DOM::Node<std::string> node, Int return msg; } -ExtensionNotification ExtensionNotification::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { - ExtensionNotification msg(ContextualizedRequest::fromXML(node, interpreter)); - FIND_EVENT_NODE(node); - - Element<std::string> msgElem(node); - msg.name = STRING_ATTR_OR_EXPR(msgElem, Name); - msg.type = EXTENSIONNOTIFICATION; - return msg; -} - -ExtensionNotification::operator Event() const { - Event ev = ContextualizedRequest::operator Event(); - if (name.length() > 0) { - ev.setName("mmi.extensionnotification." + name); - } else { - ev.setName("mmi.extensionnotification"); - } - return ev; -} - StatusResponse StatusResponse::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) { StatusResponse msg(ContextualizedRequest::fromXML(node, interpreter)); FIND_EVENT_NODE(node); @@ -416,5 +440,108 @@ StatusRequest StatusRequest::fromXML(Arabica::DOM::Node<std::string> node, Inter return msg; } + + +#ifdef MMI_WITH_OPERATOR_EVENT + + TO_EVENT_OPERATOR(NewContextRequest, "mmi.request.newcontext", MMIEvent); + TO_EVENT_OPERATOR(PauseRequest, "mmi.request.pause", ContextualizedRequest); + TO_EVENT_OPERATOR(ResumeRequest, "mmi.request.resume", ContextualizedRequest); + TO_EVENT_OPERATOR(CancelRequest, "mmi.request.cancel", ContextualizedRequest); + TO_EVENT_OPERATOR(ClearContextRequest, "mmi.request.clearcontext", ContextualizedRequest); + TO_EVENT_OPERATOR(StatusRequest, "mmi.request.status", ContextualizedRequest); + + TO_EVENT_OPERATOR(PrepareRequest, "mmi.request.prepare", ContentRequest); + TO_EVENT_OPERATOR(StartRequest, "mmi.request.start", ContentRequest); + + TO_EVENT_OPERATOR(PrepareResponse, "mmi.response.prepare", StatusInfoResponse); + TO_EVENT_OPERATOR(StartResponse, "mmi.response.start", StatusInfoResponse); + TO_EVENT_OPERATOR(CancelResponse, "mmi.response.cancel", StatusInfoResponse); + TO_EVENT_OPERATOR(PauseResponse, "mmi.response.pause", StatusInfoResponse); + TO_EVENT_OPERATOR(ResumeResponse, "mmi.response.resume", StatusInfoResponse); + TO_EVENT_OPERATOR(ClearContextResponse, "mmi.response.clearcontext", StatusInfoResponse); + TO_EVENT_OPERATOR(NewContextResponse, "mmi.response.newcontext", StatusInfoResponse); + TO_EVENT_OPERATOR(DoneNotification, "mmi.notification.done", StatusInfoResponse); + + + MMIEvent::operator Event() const { + Event ev; + ev.setOriginType("mmi.event"); + ev.setOrigin(source); + + if (representation == MMI_AS_DATA) { + if (dataDOM) { + ev.data.node = dataDOM; + } else { + ev.data = Data::fromJSON(data); + if (ev.data.empty()) { + ev.content = data; + } + } + } + return ev; + } + + ContextualizedRequest::operator Event() const { + Event ev = MMIEvent::operator Event(); + // do we want to represent the context? It's the interpreters name already + return ev; + } + + ExtensionNotification::operator Event() const { + Event ev = ContextualizedRequest::operator Event(); + if (name.length() > 0) { + ev.setName(name); + } else { + ev.setName("mmi.notification.extension"); + } + return ev; + } + + ContentRequest::operator Event() const { + Event ev = ContextualizedRequest::operator Event(); + if (representation == MMI_AS_DATA) { + if (content.length() > 0) + ev.data.compound["content"] = Data(content, Data::VERBATIM); + if (contentURL.fetchTimeout.length() > 0) + ev.data.compound["contentURL"].compound["fetchTimeout"] = Data(contentURL.fetchTimeout, Data::VERBATIM); + if (contentURL.href.length() > 0) + ev.data.compound["contentURL"].compound["href"] = Data(contentURL.href, Data::VERBATIM); + if (contentURL.maxAge.length() > 0) + ev.data.compound["contentURL"].compound["maxAge"] = Data(contentURL.maxAge, Data::VERBATIM); + } + return ev; + } + + StatusResponse::operator Event() const { + Event ev = ContextualizedRequest::operator Event(); + ev.setName("mmi.response.status"); + + if (representation == MMI_AS_DATA) { + switch (status) { + case ALIVE: + ev.data.compound["status"] = Data("alive", Data::VERBATIM); + break; + case DEAD: + ev.data.compound["status"] = Data("dead", Data::VERBATIM); + break; + case SUCCESS: + ev.data.compound["status"] = Data("success", Data::VERBATIM); + break; + case FAILURE: + ev.data.compound["status"] = Data("failure", Data::VERBATIM); + break; + default: + ev.data.compound["status"] = Data("invalid", Data::VERBATIM); + } + } else { + ev.dom = toXML(); + } + + return ev; + } + +#endif + }
\ No newline at end of file diff --git a/src/uscxml/messages/MMIMessages.h b/src/uscxml/messages/MMIMessages.h index c6a2fce..2cffa0f 100644 --- a/src/uscxml/messages/MMIMessages.h +++ b/src/uscxml/messages/MMIMessages.h @@ -20,6 +20,8 @@ #ifndef MMIEVENT_H_OS0SE7H5 #define MMIEVENT_H_OS0SE7H5 +#define MMI_WITH_OPERATOR_EVENT 1 + #include <DOM/Node.hpp> #include <DOM/Document.hpp> #include <uscxml/Interpreter.h> @@ -50,37 +52,34 @@ public: INVALID }; + enum RepresentationType { + MMI_AS_DATA, + MMI_AS_XML + }; static Type getType(Arabica::DOM::Node<std::string> node); - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static MMIEvent fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static MMIEvent fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); +#ifdef MMI_WITH_OPERATOR_EVENT // conversion operator operator Event() const; - +#endif + std::string source; std::string target; std::string data; Arabica::DOM::Node<std::string> dataDOM; std::string requestId; + std::string tagName; Type type; - + RepresentationType representation; + static std::string nameSpace; protected: - MMIEvent() {} -}; - -class MMIEventReceiver { -public: - virtual void received(const MMIEvent& mmiEvent) = 0; -}; - -class MMIEventSender { -public: - virtual void send(const MMIEvent& mmiEvent) = 0; + MMIEvent() : representation(MMI_AS_DATA) {} }; class NewContextRequest : public MMIEvent { @@ -90,27 +89,24 @@ public: type = NEWCONTEXTREQUEST; } NewContextRequest(const MMIEvent& father) : MMIEvent(father) {} - static NewContextRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - MMIEvent event = MMIEvent::fromXML(node, interpreter); - event.type = NEWCONTEXTREQUEST; - return event; - } - operator Event() const { - Event ev = MMIEvent::operator Event(); - ev.setName("mmi.newcontextrequest"); - ev.setDOM(toXML()); - return ev; - } + static NewContextRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + std::string token; ///< special token for server-less modality components }; class ContextualizedRequest : public MMIEvent { public: - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static ContextualizedRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static ContextualizedRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT operator Event() const; +#endif + std::string context; protected: ContextualizedRequest() {} @@ -124,19 +120,12 @@ public: type = PAUSEREQUEST; } PauseRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} - static PauseRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - PauseRequest event = ContextualizedRequest::fromXML(node, interpreter); - event.type = PAUSEREQUEST; - return event; - } - operator Event() const { - Event ev = ContextualizedRequest::operator Event(); - ev.setName("mmi.pauserequest"); - ev.setDOM(toXML()); - return ev; - } - + static PauseRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + }; class ResumeRequest : public ContextualizedRequest { public: @@ -145,19 +134,12 @@ public: type = RESUMEREQUEST; } ResumeRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} - static ResumeRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - ResumeRequest event = ContextualizedRequest::fromXML(node, interpreter); - event.type = RESUMEREQUEST; - return event; - } - operator Event() const { - Event ev = ContextualizedRequest::operator Event(); - ev.setDOM(toXML()); - ev.setName("mmi.resumerequest"); - return ev; - } - + static ResumeRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + }; class CancelRequest : public ContextualizedRequest { public: @@ -166,18 +148,11 @@ public: type = CANCELREQUEST; } CancelRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} - static CancelRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - CancelRequest event = ContextualizedRequest::fromXML(node, interpreter); - event.type = CANCELREQUEST; - return event; - } - operator Event() const { - Event ev = ContextualizedRequest::operator Event(); - ev.setName("mmi.cancelrequest"); - ev.setDOM(toXML()); - return ev; - } + static CancelRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class ClearContextRequest : public ContextualizedRequest { @@ -187,19 +162,12 @@ public: type = CLEARCONTEXTREQUEST; } ClearContextRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} - static ClearContextRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - ClearContextRequest event = ContextualizedRequest::fromXML(node, interpreter); - event.type = CLEARCONTEXTREQUEST; - return event; - } - operator Event() const { - Event ev = ContextualizedRequest::operator Event(); - ev.setName("mmi.clearcontextrequest"); - ev.setDOM(toXML()); - return ev; - } + static ClearContextRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + }; class StatusRequest : public ContextualizedRequest { public: @@ -207,10 +175,13 @@ public: tagName = "StatusRequest"; type = STARTREQUEST; } - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static StatusRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static StatusRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT operator Event() const; +#endif + bool automaticUpdate; protected: StatusRequest(const ContextualizedRequest& father) : ContextualizedRequest(father) {} @@ -224,10 +195,13 @@ public: std::string fetchTimeout; }; - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static ContentRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static ContentRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT operator Event() const; +#endif + std::string content; Arabica::DOM::Node<std::string> contentDOM; ContentURL contentURL; @@ -243,18 +217,11 @@ public: type = PREPAREREQUEST; } PrepareRequest(const ContentRequest& father) : ContentRequest(father) {} - static PrepareRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - PrepareRequest event = ContentRequest::fromXML(node, interpreter); - event.type = PREPAREREQUEST; - return event; - } - operator Event() const { - Event ev = ContentRequest::operator Event(); - ev.setName("mmi.preparerequest"); - ev.setDOM(toXML()); - return ev; - } + static PrepareRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class StartRequest : public ContentRequest { @@ -264,18 +231,11 @@ public: type = STARTREQUEST; } StartRequest(const ContentRequest& father) : ContentRequest(father) {} - static StartRequest fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - StartRequest event = ContentRequest::fromXML(node, interpreter); - event.type = STARTREQUEST; - return event; - } - operator Event() const { - Event ev = ContentRequest::operator Event(); - ev.setName("mmi.startrequest"); - ev.setDOM(toXML()); - return ev; - } + static StartRequest fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; @@ -285,10 +245,13 @@ public: tagName = "ExtensionNotification"; type = EXTENSIONNOTIFICATION; } - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static ExtensionNotification fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static ExtensionNotification fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT operator Event() const; +#endif + std::string name; protected: ExtensionNotification(const ContextualizedRequest& father) : ContextualizedRequest(father) {} @@ -310,9 +273,13 @@ public: type = STATUSRESPONSE; status = INVALID; } - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; - static StatusResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; + static StatusResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + Status status; protected: StatusResponse(const ContextualizedRequest& father) : ContextualizedRequest(father) {} @@ -320,10 +287,9 @@ protected: class StatusInfoResponse : public StatusResponse { public: - virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; + virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = true) const; StatusInfoResponse(const StatusResponse& father) : StatusResponse(father) {} - static StatusInfoResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL); + static StatusInfoResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); std::string statusInfo; protected: StatusInfoResponse() {} @@ -336,18 +302,12 @@ public: type = PREPARERESPONSE; } PrepareResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static PrepareResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - PrepareResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = PREPARERESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.prepareresponse"); - ev.setDOM(toXML()); - return ev; - } + static PrepareResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif + }; class StartResponse : public StatusInfoResponse { @@ -357,18 +317,11 @@ public: type = STARTRESPONSE; } StartResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static StartResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - StartResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = STARTRESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.startresponse"); - ev.setDOM(toXML()); - return ev; - } + static StartResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class CancelResponse : public StatusInfoResponse { @@ -378,18 +331,11 @@ public: type = CANCELRESPONSE; } CancelResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static CancelResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - CancelResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = CANCELRESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.cancelresponse"); - ev.setDOM(toXML()); - return ev; - } + static CancelResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class PauseResponse : public StatusInfoResponse { @@ -399,18 +345,11 @@ public: type = PAUSERESPONSE; } PauseResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static PauseResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - PauseResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = PAUSERESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.pauseresponse"); - ev.setDOM(toXML()); - return ev; - } + static PauseResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class ResumeResponse : public StatusInfoResponse { @@ -420,18 +359,11 @@ public: type = RESUMERESPONSE; } ResumeResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static ResumeResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - ResumeResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = RESUMERESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.resumeresponse"); - ev.setDOM(toXML()); - return ev; - } + static ResumeResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class ClearContextResponse : public StatusInfoResponse { @@ -441,18 +373,11 @@ public: type = CLEARCONTEXTRESPONSE; } ClearContextResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static ClearContextResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - ClearContextResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = CLEARCONTEXTRESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.clearcontextresponse"); - ev.setDOM(toXML()); - return ev; - } + static ClearContextResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class NewContextResponse : public StatusInfoResponse { @@ -462,19 +387,11 @@ public: type = NEWCONTEXTRESPONSE; } NewContextResponse(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static NewContextResponse fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - NewContextResponse event = StatusInfoResponse::fromXML(node, interpreter); - event.type = NEWCONTEXTRESPONSE; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.newcontextresponse"); - ev.setDOM(toXML()); - return ev; - } + static NewContextResponse fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; class DoneNotification : public StatusInfoResponse { @@ -484,18 +401,11 @@ public: type = DONENOTIFICATION; } DoneNotification(const StatusInfoResponse& father) : StatusInfoResponse(father) {} - static DoneNotification fromXML(Arabica::DOM::Node<std::string> node, - InterpreterImpl* interpreter = NULL) { - DoneNotification event = StatusInfoResponse::fromXML(node, interpreter); - event.type = DONENOTIFICATION; - return event; - } - operator Event() const { - Event ev = StatusInfoResponse::operator Event(); - ev.setName("mmi.donenotification"); - ev.setDOM(toXML()); - return ev; - } + static DoneNotification fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter = NULL); + +#ifdef MMI_WITH_OPERATOR_EVENT + operator Event() const; +#endif }; } diff --git a/src/uscxml/plugins/datamodel/CMakeLists.txt b/src/uscxml/plugins/datamodel/CMakeLists.txt index 76f928b..2570dda 100644 --- a/src/uscxml/plugins/datamodel/CMakeLists.txt +++ b/src/uscxml/plugins/datamodel/CMakeLists.txt @@ -66,6 +66,30 @@ if (BUILD_DM_ECMA) list (APPEND USCXML_FILES ${V8_DOM}) endif() endif() + elseif(SPIDERMONKEY_FOUND) + set(USCXML_DATAMODELS "ecmascript(SpiderMonkey) ${USCXML_DATAMODELS}") + # set(ENV{V8_SRC} ${CMAKE_SOURCE_DIR}/../v8) + file(GLOB SPIDERMONKEY_DATAMODEL + ecmascript/SpiderMonkey/*.cpp + ecmascript/SpiderMonkey/*.h + ecmascript/*.cpp + ecmascript/*.h + ) + + if (BUILD_AS_PLUGINS) + source_group("SpiderMonkey" FILES ${SPIDERMONKEY_DATAMODEL}) + + add_library( + datamodel_spidermonkey SHARED + ${SPIDERMONKEY_DATAMODEL} + "../Plugins.cpp") + target_link_libraries(datamodel_spidermonkey uscxml ${SPIDERMONKEY_LIBRARY}) + set_target_properties(datamodel_spidermonkey PROPERTIES FOLDER "Plugin DataModel") + set_target_properties(datamodel_spidermonkey PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(datamodel_spidermonkey PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib") + else() + list (APPEND USCXML_FILES ${SPIDERMONKEY_DATAMODEL}) + endif() endif() endif() diff --git a/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.cpp new file mode 100644 index 0000000..1bce2c3 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.cpp @@ -0,0 +1,227 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#include "uscxml/Common.h" +#include "uscxml/config.h" +#include "SpiderMonkeyDataModel.h" + +#include "uscxml/Message.h" +#include "uscxml/DOMUtils.h" +#include <glog/logging.h> + +#ifdef BUILD_AS_PLUGINS +#include <Pluma/Connector.hpp> +#endif + +namespace uscxml { + +using namespace Arabica::XPath; +using namespace Arabica::DOM; + +#ifdef BUILD_AS_PLUGINS +PLUMA_CONNECTOR +bool pluginConnect(pluma::Host& host) { + host.add( new SpiderMonkeyDataModelProvider() ); + return true; +} +#endif + +static JSClass global_class = { "global", + JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS, + JS_PropertyStub, + JS_PropertyStub, + JS_PropertyStub, + JS_PropertyStub, + JS_EnumerateStub, + JS_ResolveStub, + JS_ConvertStub, + nullptr, + JSCLASS_NO_OPTIONAL_MEMBERS +}; + + +JSRuntime* SpiderMonkeyDataModel::_jsRuntime = NULL; + +SpiderMonkeyDataModel::SpiderMonkeyDataModel() { + _jsCtx = NULL; +} + +SpiderMonkeyDataModel::~SpiderMonkeyDataModel() { + if (_jsCtx) + JS_DestroyContext(_jsCtx); +} + +void SpiderMonkeyDataModel::reportError(JSContext *cx, const char *message, JSErrorReport *report) { +#if 0 + struct JSErrorReport { + const char *filename; /* source file name, URL, etc., or null */ + uintN lineno; /* source line number */ + const char *linebuf; /* offending source line without final \n */ + const char *tokenptr; /* pointer to error token in linebuf */ + const jschar *uclinebuf; /* unicode (original) line buffer */ + const jschar *uctokenptr; /* unicode (original) token pointer */ + uintN flags; /* error/warning, etc. */ + uintN errorNumber; /* the error number, e.g. see js.msg */ + const jschar *ucmessage; /* the (default) error message */ + const jschar **messageArgs; /* arguments for the error message */ +}; +exceptionEvent.data.compound["stacktrace"] = Data(stackTrace, Data::VERBATIM); +#endif + + Event exceptionEvent; + exceptionEvent.name = "error.execution"; + exceptionEvent.eventType = Event::PLATFORM; + + exceptionEvent.data.compound["cause"] = Data(message, Data::VERBATIM);; + exceptionEvent.data.compound["filename"] = Data(report->filename, Data::VERBATIM); + exceptionEvent.data.compound["sourceline"] = Data(report->linebuf, Data::VERBATIM); + exceptionEvent.data.compound["linenumber"] = Data(report->lineno, Data::INTERPRETED); + + std::stringstream ssUnderline; + for (int i = 0; i < (report->tokenptr - report->linebuf); i++) + ssUnderline << " "; + ssUnderline << "^"; + + exceptionEvent.data.compound["sourcemark"] = Data(ssUnderline.str(), Data::VERBATIM); + throw exceptionEvent; +} + +boost::shared_ptr<DataModelImpl> SpiderMonkeyDataModel::create(InterpreterImpl* interpreter) { + if (_jsRuntime == NULL) { + JSRuntime *rt = JS_NewRuntime(8L * 1024L * 1024L); + if (!rt) { + throw std::bad_alloc(); + } + } + + boost::shared_ptr<SpiderMonkeyDataModel> dm = boost::shared_ptr<SpiderMonkeyDataModel>(new SpiderMonkeyDataModel()); + dm->_interpreter = interpreter; + dm->_jsCtx = JS_NewContext(_jsRuntime, 8192); + if (!dm->_jsCtx) { + throw std::bad_alloc(); + } + JS_SetOptions(dm->_jsCtx, JSOPTION_VAROBJFIX); + JS_SetErrorReporter(dm->_jsCtx, reportError); + + dm->_global = JS_NewObject(dm->_jsCtx, &global_class, nullptr, nullptr); + if (!JS_InitStandardClasses(dm->_jsCtx, dm->_global)) { + throw std::bad_alloc(); + } + + return dm; +} + +void SpiderMonkeyDataModel::pushContext() { +} + +void SpiderMonkeyDataModel::popContext() { +} + +void SpiderMonkeyDataModel::initialize() { +} + +void SpiderMonkeyDataModel::setEvent(const Event& event) { +} + +Data SpiderMonkeyDataModel::getStringAsData(const std::string& content) { + Data data; + return data; +} + + +bool SpiderMonkeyDataModel::validate(const std::string& location, const std::string& schema) { + return true; +} + +bool SpiderMonkeyDataModel::isLocation(const std::string& expr) { + return true; +} + +uint32_t SpiderMonkeyDataModel::getLength(const std::string& expr) { + return 0; +} + +void SpiderMonkeyDataModel::setForeach(const std::string& item, + const std::string& array, + const std::string& index, + uint32_t iteration) { +} + +void SpiderMonkeyDataModel::eval(const Element<std::string>& scriptElem, + const std::string& expr) { +} + +bool SpiderMonkeyDataModel::isDeclared(const std::string& expr) { + return true; +} + +bool SpiderMonkeyDataModel::evalAsBool(const std::string& expr) { + return evalAsBool(Arabica::DOM::Element<std::string>(), expr); +} + +bool SpiderMonkeyDataModel::evalAsBool(const Arabica::DOM::Element<std::string>& node, const std::string& expr) { +} + +std::string SpiderMonkeyDataModel::evalAsString(const std::string& expr) { + return ""; +} + +double SpiderMonkeyDataModel::evalAsNumber(const std::string& expr) { + return 0; +} + +void SpiderMonkeyDataModel::assign(const Element<std::string>& assignElem, + const Node<std::string>& node, + const std::string& content) { +} + +void SpiderMonkeyDataModel::assign(const std::string& location, + const Data& data) { +} + +void SpiderMonkeyDataModel::init(const Element<std::string>& dataElem, + const Node<std::string>& doc, + const std::string& content) { +}; + +void SpiderMonkeyDataModel::init(const std::string& location, + const Data& data) { +} + +std::string SpiderMonkeyDataModel::andExpressions(std::list<std::string> expressions) { + if (expressions.size() == 0) + return ""; + + if (expressions.size() == 1) + return *(expressions.begin()); + + std::ostringstream exprSS; + exprSS << "("; + std::string conjunction = ""; + for (std::list<std::string>::const_iterator exprIter = expressions.begin(); + exprIter != expressions.end(); + exprIter++) { + exprSS << conjunction << "(" << *exprIter << ")"; + conjunction = " && "; + } + exprSS << ")"; + return exprSS.str(); +} + +}
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.h new file mode 100644 index 0000000..fbbdb69 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/SpiderMonkey/SpiderMonkeyDataModel.h @@ -0,0 +1,105 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see <http://www.opensource.org/licenses/bsd-license>. + * @endcond + */ + +#ifndef SPIDERMONKEYDATAMODEL_H_88841EE2 +#define SPIDERMONKEYDATAMODEL_H_88841EE2 + +#include "uscxml/Interpreter.h" +#include <list> +#include "jsapi.h" + +#ifdef BUILD_AS_PLUGINS +#include "uscxml/plugins/Plugins.h" +#endif + +namespace uscxml { +class Event; +class Data; +} + +namespace uscxml { + +class SpiderMonkeyDataModel : public DataModelImpl { +public: + SpiderMonkeyDataModel(); + virtual ~SpiderMonkeyDataModel(); + virtual boost::shared_ptr<DataModelImpl> create(InterpreterImpl* interpreter); + + virtual std::list<std::string> getNames() { + std::list<std::string> names; + names.push_back("ecmascript"); + return names; + } + + virtual void initialize(); + virtual void setEvent(const Event& event); + + virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); + + virtual uint32_t getLength(const std::string& expr); + virtual void setForeach(const std::string& item, + const std::string& array, + const std::string& index, + uint32_t iteration); + virtual void pushContext(); + virtual void popContext(); + + virtual void eval(const Arabica::DOM::Element<std::string>& scriptElem, + const std::string& expr); + virtual void assign(const Arabica::DOM::Element<std::string>& assignElem, + const Arabica::DOM::Node<std::string>& node, + const std::string& content); + virtual void assign(const std::string& location, + const Data& data); + + virtual void init(const Arabica::DOM::Element<std::string>& dataElem, + const Arabica::DOM::Node<std::string>& node, + const std::string& content); + virtual void init(const std::string& location, + const Data& data); + + virtual std::string andExpressions(std::list<std::string>); + + virtual Data getStringAsData(const std::string& content); + + virtual bool isDeclared(const std::string& expr); + + virtual std::string evalAsString(const std::string& expr); + virtual bool evalAsBool(const Arabica::DOM::Element<std::string>& node, const std::string& expr); + virtual bool evalAsBool(const std::string& expr); + virtual double evalAsNumber(const std::string& expr); + + static void reportError(JSContext *cx, const char *message, JSErrorReport *report); + +protected: + + JSObject* _global; + + JSContext* _jsCtx; + static JSRuntime* _jsRuntime; +}; + +#ifdef BUILD_AS_PLUGINS +PLUMA_INHERIT_PROVIDER(SpiderMonkeyDataModel, DataModelImpl); +#endif + +} + +#endif /* end of include guard: SPIDERMONKEYDATAMODEL_H_88841EE2 */ diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp index 7db9e66..fc18e18 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp @@ -27,7 +27,7 @@ #include <Pluma/Connector.hpp> #endif -#define ISSUE_REQUEST(name) {\ +#define ISSUE_REQUEST(name, block) {\ Arabica::DOM::Document<std::string> name##XML = name.toXML(true);\ name##XML.getDocumentElement().setPrefix("mmi");\ std::stringstream name##XMLSS;\ @@ -36,7 +36,7 @@ std::cout << "SEND: " << name##XMLSS.str() << std::endl; \ name##URL.setOutContent(name##XMLSS.str());\ name##URL.addOutHeader("Content-type", "application/xml");\ - name##URL.download(false);\ + name##URL.download(block);\ } namespace uscxml { @@ -72,7 +72,7 @@ bool VoiceXMLInvoker::httpRecvRequest(const HTTPServer::Request& request) { } const Arabica::DOM::Node<std::string>& node = request.data.at("content").node; - std::cout << "RCVD: " << node << std::endl; +// std::cout << "RCVD: " << node << std::endl; switch(MMIEvent::getType(node)) { case MMIEvent::NEWCONTEXTRESPONSE: { @@ -95,7 +95,7 @@ bool VoiceXMLInvoker::httpRecvRequest(const HTTPServer::Request& request) { std::stringstream contentSS; startReq.contentDOM = _invokeReq.dom; } - ISSUE_REQUEST(startReq); + ISSUE_REQUEST(startReq, false); } else { // already got a context! @@ -113,20 +113,26 @@ bool VoiceXMLInvoker::httpRecvRequest(const HTTPServer::Request& request) { _compState = MMI_IDLE; break; } - - case MMIEvent::EXTENSIONNOTIFICATION: { - ExtensionNotification resp = ExtensionNotification::fromXML(node); - Event ev; - ev.name = "mmi.extensionnotification"; - if (resp.dataDOM) { - ev.dom = resp.dataDOM; - } else if(resp.data.size() > 0) { - ev.data = Data::fromJSON(resp.data); // try to parse as JSON - if (ev.data.empty()) { - ev.content = resp.data; + + case MMIEvent::STATUSRESPONSE: { + StatusResponse resp = StatusResponse::fromXML(node); + switch (resp.status) { + case StatusResponse::DEAD: + _compState = MMI_DEAD; + case StatusResponse::FAILURE: { + Event ev = resp; + returnEvent(ev); + break; } + default: + break; } - returnEvent(ev); + break; + } + + case MMIEvent::EXTENSIONNOTIFICATION: { + Event resp = ExtensionNotification::fromXML(node); + returnEvent(resp); } default: @@ -169,7 +175,7 @@ void VoiceXMLInvoker::invoke(const InvokeRequest& req) { newCtxReq.source = _url; newCtxReq.target = _target; newCtxReq.requestId = uscxml::UUID::getUUID(); - ISSUE_REQUEST(newCtxReq); + ISSUE_REQUEST(newCtxReq, false); _isRunning = true; _thread = new tthread::thread(VoiceXMLInvoker::run, this); @@ -182,11 +188,12 @@ void VoiceXMLInvoker::uninvoke() { clrCtxReq.source = _url; clrCtxReq.target = _target; clrCtxReq.requestId = uscxml::UUID::getUUID(); - ISSUE_REQUEST(clrCtxReq); + ISSUE_REQUEST(clrCtxReq, false); if (_isRunning) _isRunning = false; + // unblock queue SendRequest req; _workQueue.push(req); @@ -222,8 +229,12 @@ void VoiceXMLInvoker::process(SendRequest& req) { return; } + if (_compState != MMI_RUNNING) + // remote component is not running + return; + // dispatch over send request - + // Is there something special to do here? // if we did nothing else, send as ExtensionNotification ExtensionNotification extNotif; @@ -251,8 +262,7 @@ void VoiceXMLInvoker::process(SendRequest& req) { extNotif.data = Data::toJSON(req.data); } - ISSUE_REQUEST(extNotif); - + ISSUE_REQUEST(extNotif, false); } }
\ No newline at end of file diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h index 6f2a248..4ad5023 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h @@ -37,7 +37,8 @@ public: enum ComponentState { MMI_IDLE, MMI_PAUSED, - MMI_RUNNING + MMI_RUNNING, + MMI_DEAD }; VoiceXMLInvoker(); diff --git a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp index 285db72..eb82edb 100644 --- a/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/xhtml/XHTMLInvoker.cpp @@ -88,7 +88,17 @@ bool XHTMLInvoker::httpRecvRequest(const HTTPServer::Request& req) { ev.name = req.data.at("type").atom; } ev.origin = _invokeId; - ev.initContent(req.data.at("content").atom); + + // initialize data + ev.data = Data::fromJSON(req.data.at("content").atom); + if (ev.data.empty()) { + if (req.dom) { + ev.dom = req.dom; + } else { + ev.content = req.content; + } + } + ev.data.compound["Connection"] = req.data; // content is already on ev.raw ev.data.compound["Connection"].compound.erase("content"); |