summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp')
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp196
1 files changed, 143 insertions, 53 deletions
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
index 717e174..bf32b9d 100644
--- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
+++ b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
@@ -5,15 +5,86 @@
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <SAX/helpers/InputSourceResolver.hpp>
+#include <uscxml/NameSpacingParser.h>
+
#include <boost/algorithm/string.hpp>
+#define STRING_ATTR_OR_EXPR(element, name)\
+(element.hasAttributeNS(nameSpace, "name##Expr") && interpreter ? \
+ interpreter->getDataModel().evalAsString(element.getAttributeNS(nameSpace, "name##Expr")) : \
+ (element.hasAttributeNS(nameSpace, #name) ? element.getAttributeNS(nameSpace, #name) : "") \
+)
+
+
namespace uscxml {
using namespace Arabica::DOM;
-std::string MMIMessage::nameSpace = "http://www.w3.org/2008/04/mmi-arch";
+std::string MMIEvent::nameSpace = "http://www.w3.org/2008/04/mmi-arch";
+
+ MMIEvent::Type MMIEvent::getType(Arabica::DOM::Node<std::string> node) {
+ if (!node)
+ return INVALID;
+
+ if (boost::iequals(node.getLocalName(), "NEWCONTEXTREQUEST"))
+ return NEWCONTEXTREQUEST;
+ if (boost::iequals(node.getLocalName(), "NEWCONTEXTRESPONSE"))
+ return NEWCONTEXTRESPONSE;
+ if (boost::iequals(node.getLocalName(), "PREPAREREQUEST"))
+ return PREPAREREQUEST;
+ if (boost::iequals(node.getLocalName(), "PREPARERESPONSE"))
+ return PREPARERESPONSE;
+ if (boost::iequals(node.getLocalName(), "STARTREQUEST"))
+ return STARTREQUEST;
+ if (boost::iequals(node.getLocalName(), "STARTRESPONSE"))
+ return STARTRESPONSE;
+ if (boost::iequals(node.getLocalName(), "DONENOTIFICATION"))
+ return DONENOTIFICATION;
+ if (boost::iequals(node.getLocalName(), "CANCELREQUEST"))
+ return CANCELREQUEST;
+ if (boost::iequals(node.getLocalName(), "CANCELRESPONSE"))
+ return CANCELRESPONSE;
+ if (boost::iequals(node.getLocalName(), "PAUSEREQUEST"))
+ return PAUSEREQUEST;
+ if (boost::iequals(node.getLocalName(), "PAUSERESPONSE"))
+ return PAUSERESPONSE;
+ if (boost::iequals(node.getLocalName(), "RESUMEREQUEST"))
+ return RESUMEREQUEST;
+ if (boost::iequals(node.getLocalName(), "RESUMERESPONSE"))
+ return RESUMERESPONSE;
+ if (boost::iequals(node.getLocalName(), "EXTENSIONNOTIFICATION"))
+ return EXTENSIONNOTIFICATION;
+ if (boost::iequals(node.getLocalName(), "CLEARCONTEXTREQUEST"))
+ return CLEARCONTEXTREQUEST;
+ if (boost::iequals(node.getLocalName(), "CLEARCONTEXTRESPONSE"))
+ return CLEARCONTEXTRESPONSE;
+ if (boost::iequals(node.getLocalName(), "STATUSREQUEST"))
+ return STATUSREQUEST;
+ if (boost::iequals(node.getLocalName(), "STATUSRESPONSE"))
+ return STATUSRESPONSE;
+ return INVALID;
+ }
+
+ Arabica::DOM::Node<std::string> MMIEvent::getEventNode(Arabica::DOM::Node<std::string> node) {
+ if (node.getNodeType() == Node_base::DOCUMENT_NODE)
+ node = Arabica::DOM::Document<std::string>(node).getDocumentElement();
+
+ // get the first element
+ while (node && node.getNodeType() != Node_base::ELEMENT_NODE) {
+ node = node.getNextSibling();
+ }
+ // get the contained message
+ if (node && getType(node) == INVALID) {
+ node = node.getFirstChild();
+ while (node && node.getNodeType() != Node_base::ELEMENT_NODE && getType(node) == INVALID) {
+ node = node.getNextSibling();
+ }
+ }
+ return node;
+ }
-Arabica::DOM::Document<std::string> MMIMessage::toXML() {
+
+Arabica::DOM::Document<std::string> MMIEvent::toXML() const {
Arabica::DOM::DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation();
Document<std::string> doc = domFactory.createDocument(nameSpace, "", 0);
Element<std::string> mmiElem = doc.createElementNS(nameSpace, "mmi");
@@ -23,7 +94,7 @@ Arabica::DOM::Document<std::string> MMIMessage::toXML() {
msgElem.setAttributeNS(nameSpace, "RequestID", requestId);
if (data.size() > 0) {
- Element<std::string> dataElem = doc.createElementNS(nameSpace, "data");
+ Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data");
// try to parse content
std::stringstream* ss = new std::stringstream();
@@ -32,7 +103,7 @@ Arabica::DOM::Document<std::string> MMIMessage::toXML() {
Arabica::SAX::InputSource<std::string> inputSource;
inputSource.setByteStream(ssPtr);
- Arabica::SAX2DOM::Parser<std::string> parser;
+ NameSpacingParser parser;
if(parser.parse(inputSource)) {
Node<std::string> importedNode = doc.importNode(parser.getDocument().getDocumentElement(), true);
dataElem.appendChild(importedNode);
@@ -45,18 +116,17 @@ Arabica::DOM::Document<std::string> MMIMessage::toXML() {
mmiElem.appendChild(msgElem);
doc.appendChild(mmiElem);
- std::cout << doc;
return doc;
}
-Arabica::DOM::Document<std::string> ContextualizedRequest::toXML() {
- Document<std::string> doc = MMIMessage::toXML();
+Arabica::DOM::Document<std::string> ContextualizedRequest::toXML() const {
+ Document<std::string> doc = MMIEvent::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
msgElem.setAttributeNS(nameSpace, "Context", context);
return doc;
}
-Arabica::DOM::Document<std::string> ContentRequest::toXML() {
+Arabica::DOM::Document<std::string> ContentRequest::toXML() const {
Document<std::string> doc = ContextualizedRequest::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
@@ -92,14 +162,14 @@ Arabica::DOM::Document<std::string> ContentRequest::toXML() {
return doc;
}
-Arabica::DOM::Document<std::string> ExtensionNotification::toXML() {
+Arabica::DOM::Document<std::string> ExtensionNotification::toXML() const {
Document<std::string> doc = ContextualizedRequest::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
msgElem.setAttributeNS(nameSpace, "Name", name);
return doc;
}
-Arabica::DOM::Document<std::string> StatusResponse::toXML() {
+Arabica::DOM::Document<std::string> StatusResponse::toXML() const {
Document<std::string> doc = ContextualizedRequest::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
if (status == ALIVE) {
@@ -114,7 +184,7 @@ Arabica::DOM::Document<std::string> StatusResponse::toXML() {
return doc;
}
-Arabica::DOM::Document<std::string> StatusInfoResponse::toXML() {
+Arabica::DOM::Document<std::string> StatusInfoResponse::toXML() const {
Document<std::string> doc = StatusResponse::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
@@ -126,7 +196,7 @@ Arabica::DOM::Document<std::string> StatusInfoResponse::toXML() {
return doc;
}
-Arabica::DOM::Document<std::string> StatusRequest::toXML() {
+Arabica::DOM::Document<std::string> StatusRequest::toXML() const {
Document<std::string> doc = ContextualizedRequest::toXML();
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
@@ -139,19 +209,18 @@ Arabica::DOM::Document<std::string> StatusRequest::toXML() {
return doc;
}
-MMIMessage MMIMessage::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- MMIMessage msg;
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+MMIEvent MMIEvent::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ MMIEvent msg;
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
node = node.getNextSibling();
}
Element<std::string> msgElem(node);
- msg.source = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Source");
- msg.target = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Target");
-// msg.data = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Data");
- msg.requestId = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "RequestID");
+ 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;
@@ -167,35 +236,47 @@ MMIMessage MMIMessage::fromXML(const Arabica::DOM::Document<std::string>& doc) {
if (dataElem && boost::iequals(dataElem.getLocalName(), "data")) {
std::stringstream ss;
node = dataElem.getFirstChild();
- while (node) {
- if (node.getNodeType() == Node_base::ELEMENT_NODE) {
- ss << node;
- break;
- }
- node = node.getNextSibling();
- }
+ if (node)
+ ss << node;
msg.data = ss.str();
}
return msg;
}
-ContextualizedRequest ContextualizedRequest::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- ContextualizedRequest msg(NewContextRequest::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+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;
+}
+
+ContextualizedRequest ContextualizedRequest::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ ContextualizedRequest msg(MMIEvent::fromXML(node, interpreter));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
node = node.getNextSibling();
}
Element<std::string> msgElem(node);
- msg.context = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Context");
+ msg.context = STRING_ATTR_OR_EXPR(msgElem, Context);
return msg;
}
-ContentRequest ContentRequest::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- ContentRequest msg(ContextualizedRequest::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+ContextualizedRequest::operator Event() const {
+ Event ev = MMIEvent::operator Event();
+ // do we want to represent the context? It's the interpreters name already
+ return ev;
+}
+
+
+ContentRequest ContentRequest::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ ContentRequest msg(ContextualizedRequest::fromXML(node, interpreter));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
@@ -228,39 +309,48 @@ ContentRequest ContentRequest::fromXML(const Arabica::DOM::Document<std::string>
}
msg.content = ss.str();
} else if(boost::iequals(contentElem.getLocalName(), "contentURL")) {
- msg.contentURL.href = contentElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "href");
- msg.contentURL.maxAge = contentElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "max-age");
- msg.contentURL.fetchTimeout = contentElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "fetchtimeout");
+ msg.contentURL.href = STRING_ATTR_OR_EXPR(contentElem, href);
+ msg.contentURL.maxAge = STRING_ATTR_OR_EXPR(contentElem, max-age);
+ msg.contentURL.fetchTimeout = STRING_ATTR_OR_EXPR(contentElem, fetchtimeout);
}
}
- //msg.content = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Context");
+ //msg.content = msgElem.getAttributeNS(nameSpace, "Context");
return msg;
}
-ExtensionNotification ExtensionNotification::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- ExtensionNotification msg(ContextualizedRequest::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+ExtensionNotification ExtensionNotification::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ ExtensionNotification msg(ContextualizedRequest::fromXML(node, interpreter));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
node = node.getNextSibling();
}
Element<std::string> msgElem(node);
- msg.name = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Name");
+ msg.name = STRING_ATTR_OR_EXPR(msgElem, Name);
+ msg.type = EXTENSIONNOTIFICATION;
return msg;
}
-StatusResponse StatusResponse::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- StatusResponse msg(ContextualizedRequest::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+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));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
node = node.getNextSibling();
}
Element<std::string> msgElem(node);
- std::string status = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "Status");
+ std::string status = STRING_ATTR_OR_EXPR(msgElem, Status);
if (boost::iequals(status, "ALIVE")) {
msg.status = ALIVE;
@@ -271,12 +361,12 @@ StatusResponse StatusResponse::fromXML(const Arabica::DOM::Document<std::string>
} else if(boost::iequals(status, "SUCCESS")) {
msg.status = SUCCESS;
}
+ msg.type = STATUSRESPONSE;
return msg;
}
-StatusInfoResponse StatusInfoResponse::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- StatusInfoResponse msg(StatusResponse::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+StatusInfoResponse StatusInfoResponse::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ StatusInfoResponse msg(StatusResponse::fromXML(node, interpreter));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
@@ -305,21 +395,19 @@ StatusInfoResponse StatusInfoResponse::fromXML(const Arabica::DOM::Document<std:
node = node.getNextSibling();
}
}
-
return msg;
}
-StatusRequest StatusRequest::fromXML(const Arabica::DOM::Document<std::string>& doc) {
- StatusRequest msg(ContextualizedRequest::fromXML(doc));
- Node<std::string> node = doc.getDocumentElement().getFirstChild();
+StatusRequest StatusRequest::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl* interpreter) {
+ StatusRequest msg(ContextualizedRequest::fromXML(node, interpreter));
while (node) {
if (node.getNodeType() == Node_base::ELEMENT_NODE)
break;
node = node.getNextSibling();
}
Element<std::string> msgElem(node);
- std::string autoUpdate = msgElem.getAttributeNS("http://www.w3.org/2008/04/mmi-arch", "RequestAutomaticUpdate");
+ std::string autoUpdate = STRING_ATTR_OR_EXPR(msgElem, RequestAutomaticUpdate);
if (boost::iequals(autoUpdate, "true")) {
msg.automaticUpdate = true;
@@ -332,7 +420,9 @@ StatusRequest StatusRequest::fromXML(const Arabica::DOM::Document<std::string>&
} else {
msg.automaticUpdate = false;
}
+ msg.type = STATUSREQUEST;
return msg;
}
+
} \ No newline at end of file