summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/ioprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/plugins/ioprocessor')
-rw-r--r--src/uscxml/plugins/ioprocessor/CMakeLists.txt126
-rw-r--r--src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp142
-rw-r--r--src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h16
-rw-r--r--src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp115
-rw-r--r--src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h72
-rw-r--r--src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.cpp19
-rw-r--r--src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.h19
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp210
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h72
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp132
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h53
-rw-r--r--src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp59
-rw-r--r--src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h66
-rw-r--r--src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp155
-rw-r--r--src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h15
15 files changed, 147 insertions, 1124 deletions
diff --git a/src/uscxml/plugins/ioprocessor/CMakeLists.txt b/src/uscxml/plugins/ioprocessor/CMakeLists.txt
index 3c882ed..1171d73 100644
--- a/src/uscxml/plugins/ioprocessor/CMakeLists.txt
+++ b/src/uscxml/plugins/ioprocessor/CMakeLists.txt
@@ -1,25 +1,3 @@
-# LIBEVENT basichttp ioprocessor - this one is already required above
-
-set(USCXML_IOPROCESSORS "basichttp ${USCXML_IOPROCESSORS}")
-file(GLOB_RECURSE BASICHTTP_IOPROCESSOR
- basichttp/*.cpp
- basichttp/*.h
-)
-if (BUILD_AS_PLUGINS)
- source_group("" FILES ${BASICHTTP_IOPROCESSOR})
- add_library(
- ioprocessor_basichttp SHARED
- ${BASICHTTP_IOPROCESSOR}
- "../Plugins.cpp")
- target_link_libraries(ioprocessor_basichttp uscxml)
- set_target_properties(ioprocessor_basichttp PROPERTIES FOLDER "Plugin IOProcessor")
- set_target_properties(ioprocessor_basichttp PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS")
- set_target_properties(ioprocessor_basichttp PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib")
-else()
- list (APPEND USCXML_FILES ${BASICHTTP_IOPROCESSOR})
-endif()
-
-
# scxml ioprocessor
set(USCXML_IOPROCESSORS "scxml ${USCXML_IOPROCESSORS}")
@@ -27,110 +5,16 @@ file(GLOB_RECURSE SCXML_IOPROCESSOR
scxml/*.cpp
scxml/*.h
)
+list (APPEND USCXML_FILES ${SCXML_IOPROCESSOR})
+
+set(USCXML_IOPROCESSORS "basichttp ${USCXML_IOPROCESSORS}")
file(GLOB_RECURSE BASICHTTP_IOPROCESSOR
basichttp/*.cpp
basichttp/*.h
)
-if (BUILD_AS_PLUGINS)
- source_group("" FILES ${SCXML_IOPROCESSOR})
- add_library(
- ioprocessor_scxml SHARED
- ${SCXML_IOPROCESSOR}
- ${BASICHTTP_IOPROCESSOR}
- "../Plugins.cpp")
- # scxml ioprocessor is a basichttp ioprocessor
- target_link_libraries(ioprocessor_scxml uscxml)
- set_target_properties(ioprocessor_scxml PROPERTIES FOLDER "Plugin IOProcessor")
- set_target_properties(ioprocessor_scxml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS")
- set_target_properties(ioprocessor_scxml PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib")
-else()
- list (APPEND USCXML_FILES ${SCXML_IOPROCESSOR})
-endif()
-
-
-if (NOT BUILD_MINIMAL)
-
- set(USCXML_IOPROCESSORS "sample ${USCXML_IOPROCESSORS}")
- file(GLOB_RECURSE SAMPLE_IOPROCESSOR
- sample/*.cpp
- sample/*.h
- )
- if (BUILD_AS_PLUGINS)
- source_group("" FILES ${SAMPLE_IOPROCESSOR})
- add_library(
- ioprocessor_sample SHARED
- ${SAMPLE_IOPROCESSOR}
- "../Plugins.cpp")
- target_link_libraries(ioprocessor_sample uscxml)
- set_target_properties(ioprocessor_sample PROPERTIES FOLDER "Plugin IOProcessor")
- set_target_properties(ioprocessor_sample PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS")
- set_target_properties(ioprocessor_sample PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib")
- else()
- list (APPEND USCXML_FILES ${SAMPLE_IOPROCESSOR})
- endif()
-
- set(USCXML_IOPROCESSORS "comet ${USCXML_IOPROCESSORS}")
- file(GLOB_RECURSE COMET_IOPROCESSOR
- comet/*.cpp
- comet/*.h
- )
- if (BUILD_AS_PLUGINS)
- source_group("" FILES ${COMET_IOPROCESSOR})
- add_library(
- ioprocessor_comet SHARED
- ${COMET_IOPROCESSOR}
- "../Plugins.cpp")
- target_link_libraries(ioprocessor_comet uscxml)
- set_target_properties(ioprocessor_comet PROPERTIES FOLDER "Plugin IOProcessor")
- set_target_properties(ioprocessor_comet PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS")
- set_target_properties(ioprocessor_comet PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib")
- else()
- list (APPEND USCXML_FILES ${COMET_IOPROCESSOR})
- endif()
-
-
- # mmi ioprocessor
-
- if (PROTOBUF_FOUND AND OFF)
-
- if (NOT PROTOBUF_PROTOC_EXECUTABLE)
- message(FATAL_ERROR "protoc binary required for serialization")
- endif()
-
- set(USCXML_IOPROCESSORS "mmi ${USCXML_IOPROCESSORS}")
- file(GLOB_RECURSE MMI_IOPROCESSOR
- modality/*.cpp
- modality/*.h
- )
-
- # process .proto files
- file(GLOB_RECURSE PROTOBUF_INTERFACES ${PROJECT_SOURCE_DIR}/contrib/proto/*.proto)
- list (APPEND USCXML_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR})
-
- PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${PROTOBUF_INTERFACES})
- # set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
-
- # this needs to be here for dependencies on the generated proto files
- add_library(mmi_proto STATIC ${PROTO_SRCS})
- set_target_properties(mmi_proto PROPERTIES FOLDER "Generated")
-
- if (BUILD_AS_PLUGINS)
- source_group("" FILES ${MMI_IOPROCESSOR})
- add_library(
- ioprocessor_mmi SHARED
- ${MMI_IOPROCESSOR}
- "../Plugins.cpp")
- target_link_libraries(ioprocessor_mmi uscxml mmi_proto)
- set_target_properties(ioprocessor_mmi PROPERTIES FOLDER "Plugin IOProcessor")
- set_target_properties(ioprocessor_mmi PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS")
- set_target_properties(ioprocessor_mmi PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib")
- else()
- list (APPEND USCXML_FILES ${MMI_IOPROCESSOR})
- list (APPEND USCXML_OPT_LIBS mmi_proto)
- endif()
- endif()
+list (APPEND BASICHTTP_IOPROCESSOR "")
-endif() # BUILD_MINIMAL
+list (APPEND USCXML_FILES ${BASICHTTP_IOPROCESSOR})
set(USCXML_INCLUDE_DIRS ${USCXML_INCLUDE_DIRS} PARENT_SCOPE)
set(USCXML_OPT_LIBS ${USCXML_OPT_LIBS} PARENT_SCOPE)
diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp
index 1bced48..f81cf54 100644
--- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp
+++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp
@@ -20,9 +20,8 @@
#include "uscxml/Common.h"
#include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h"
-#include "uscxml/Message.h"
-#include "uscxml/dom/DOMUtils.h"
-#include "uscxml/dom/NameSpacingParser.h"
+#include "uscxml/messages/Event.h"
+#include "uscxml/util/DOM.h"
#include <iostream>
#include <event2/dns.h>
@@ -31,8 +30,7 @@
#include <string.h>
-#include <io/uri.hpp>
-#include <glog/logging.h>
+#include <easylogging++.h>
#include <boost/algorithm/string.hpp>
#ifdef _WIN32
@@ -65,6 +63,7 @@ bool pluginConnect(pluma::Host& host) {
// see http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor
BasicHTTPIOProcessor::BasicHTTPIOProcessor() {
+ HTTPServer::getInstance();
}
BasicHTTPIOProcessor::~BasicHTTPIOProcessor() {
@@ -73,8 +72,8 @@ BasicHTTPIOProcessor::~BasicHTTPIOProcessor() {
}
-boost::shared_ptr<IOProcessorImpl> BasicHTTPIOProcessor::create(InterpreterImpl* interpreter) {
- boost::shared_ptr<BasicHTTPIOProcessor> io = boost::shared_ptr<BasicHTTPIOProcessor>(new BasicHTTPIOProcessor());
+std::shared_ptr<IOProcessorImpl> BasicHTTPIOProcessor::create(InterpreterImpl* interpreter) {
+ std::shared_ptr<BasicHTTPIOProcessor> io(new BasicHTTPIOProcessor());
io->_interpreter = interpreter;
// register at http server
@@ -104,19 +103,19 @@ Data BasicHTTPIOProcessor::getDataModelVariables() {
data.compound["path"] = Data(url.path(), Data::VERBATIM);
data.compound["scheme"] = Data(url.scheme(), Data::VERBATIM);
- std::vector<std::string> pathComps = url.pathComponents();
- std::vector<std::string>::const_iterator pathCompIter = pathComps.begin();
+ std::list<std::string> pathComps = url.pathComponents();
+ std::list<std::string>::const_iterator pathCompIter = pathComps.begin();
while(pathCompIter != pathComps.end()) {
- data.compound["pathComponens"].array.push_back(Data(*pathCompIter, Data::VERBATIM));
+ data.compound["pathComponents"].array.push_back(Data(*pathCompIter, Data::VERBATIM));
pathCompIter++;
}
return data;
}
-bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) {
- Event reqEvent = req;
- reqEvent.eventType = Event::EXTERNAL;
+bool BasicHTTPIOProcessor::requestFromHTTP(const HTTPServer::Request& req) {
+ Event event = req;
+ event.eventType = Event::EXTERNAL;
// std::cout << req.raw << std::endl;
@@ -130,10 +129,10 @@ bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) {
// if we sent ourself an event it will end up here
// this will call the const subscript operator
if (req.data.at("content").hasKey("_scxmleventname")) {
- reqEvent.name = req.data.at("content").at("_scxmleventname").atom;
+ event.name = req.data.at("content").at("_scxmleventname").atom;
}
if (req.data.at("content").hasKey("content")) {
- reqEvent.content = req.data.at("content").at("content").atom;
+ event.data.atom = req.data.at("content").at("content").atom;
}
}
@@ -143,9 +142,9 @@ bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) {
for(std::map<std::string, Data>::const_iterator compIter = data.compound.begin();
compIter!= data.compound.end(); compIter++) {
if (compIter->first == "content") {
- reqEvent.content = compIter->second.atom;
+ event.data.atom = compIter->second.atom;
} else {
- reqEvent.data[compIter->first] = compIter->second;
+ event.data[compIter->first] = compIter->second;
}
}
}
@@ -155,62 +154,60 @@ bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) {
for(std::map<std::string, Data>::const_iterator compIter = data.compound.begin();
compIter!= data.compound.end(); compIter++) {
if (compIter->first == "_scxmleventname") {
- reqEvent.name = compIter->second.atom;
+ event.name = compIter->second.atom;
}
}
}
- // check whether we can parse it as XML
- if (reqEvent.content.length() > 0) {
- NameSpacingParser parser = NameSpacingParser::fromXML(reqEvent.content);
- if (!parser.errorsReported()) {
- reqEvent.dom = parser.getDocument();
- }
- }
-
- /// test532
- if (reqEvent.name.length() == 0)
- reqEvent.name = "http." + req.data.compound.at("type").atom;
+ // test 532
+ if (event.name.length() == 0)
+ event.name = "http." + req.data.compound.at("type").atom;
- returnEvent(reqEvent);
+ eventToSCXML(event, USCXML_IOPROC_BASICHTTP_TYPE, _url);
evhttp_send_reply(req.evhttpReq, 200, "OK", NULL);
return true;
}
-void BasicHTTPIOProcessor::send(const SendRequest& req) {
+bool BasicHTTPIOProcessor::isValidTarget(const std::string& target) {
+ try {
+ URL url(target);
+ if (url.scheme().compare("http") != 0)
+ return false;
- if (req.target.length() == 0) {
- _interpreter->receiveInternal(Event("error.communication", Event::PLATFORM));
- return;
+ return true;
+ } catch (ErrorEvent e) {
}
+ return false;
+}
- bool isLocal = false;
- std::string target;
- if (!boost::equals(req.target, _url)) {
- target = req.target;
- } else {
- isLocal = true;
- target = _url;
+void BasicHTTPIOProcessor::eventFromSCXML(const std::string& target, const Event& event) {
+
+ // TODO: is this still needed with isValidTarget()?
+ if (target.length() == 0) {
+ _interpreter->enqueueInternal(Event("error.communication", Event::PLATFORM));
+ return;
}
+
+ bool isLocal = target == _url;
URL targetURL(target);
std::stringstream kvps;
std::string kvpSeperator;
// event name
- if (req.name.size() > 0) {
+ if (event.name.size() > 0) {
char* eventNameCStr = evhttp_encode_uri("_scxmleventname");
- char* eventValueCStr = evhttp_encode_uri(req.name.c_str());
+ char* eventValueCStr = evhttp_encode_uri(event.name.c_str());
kvps << kvpSeperator << eventNameCStr << "=" << eventValueCStr;
kvpSeperator = "&";
free(eventNameCStr);
free(eventValueCStr);
-// targetURL.addOutHeader("_scxmleventname", evhttp_encode_uri(req.name.c_str()));
+ targetURL.addOutHeader("_scxmleventname", evhttp_encode_uri(event.name.c_str()));
}
// event namelist
- if (req.namelist.size() > 0) {
- std::map<std::string, Data>::const_iterator namelistIter = req.namelist.begin();
- while (namelistIter != req.namelist.end()) {
+ if (event.namelist.size() > 0) {
+ std::map<std::string, Data>::const_iterator namelistIter = event.namelist.begin();
+ while (namelistIter != event.namelist.end()) {
char* keyCStr = evhttp_encode_uri(namelistIter->first.c_str());
// this is simplified - Data might be more elaborate than a simple string atom
char* valueCStr = evhttp_encode_uri(namelistIter->second.atom.c_str());
@@ -218,15 +215,15 @@ void BasicHTTPIOProcessor::send(const SendRequest& req) {
free(keyCStr);
free(valueCStr);
kvpSeperator = "&";
-// targetURL.addOutHeader(namelistIter->first, namelistIter->second);
+ targetURL.addOutHeader(namelistIter->first, namelistIter->second);
namelistIter++;
}
}
// event params
- if (req.params.size() > 0) {
- std::multimap<std::string, Data>::const_iterator paramIter = req.params.begin();
- while (paramIter != req.params.end()) {
+ if (event.params.size() > 0) {
+ std::multimap<std::string, Data>::const_iterator paramIter = event.params.begin();
+ while (paramIter != event.params.end()) {
char* keyCStr = evhttp_encode_uri(paramIter->first.c_str());
// this is simplified - Data might be more elaborate than a simple string atom
char* valueCStr = evhttp_encode_uri(paramIter->second.atom.c_str());
@@ -234,35 +231,23 @@ void BasicHTTPIOProcessor::send(const SendRequest& req) {
free(keyCStr);
free(valueCStr);
kvpSeperator = "&";
-// targetURL.addOutHeader(paramIter->first, paramIter->second);
+ targetURL.addOutHeader(paramIter->first, paramIter->second);
paramIter++;
}
}
// try hard to find actual content
char* keyCStr = evhttp_encode_uri("content");
- if (req.content.size() > 0) {
- char* valueCStr = evhttp_encode_uri(req.content.c_str());
- kvps << kvpSeperator << keyCStr << "=" << valueCStr;
- free(valueCStr);
- kvpSeperator = "&";
- } else if (req.dom) {
- std::stringstream xmlStream;
- xmlStream << req.dom;
- char* valueCStr = evhttp_encode_uri(xmlStream.str().c_str());
- kvps << kvpSeperator << keyCStr << "=" << valueCStr;
- free(valueCStr);
- kvpSeperator = "&";
- } else if (!req.data.empty()) {
+ if (!event.data.empty()) {
char* valueCStr = NULL;
- if (req.data.atom.length() || req.data.array.size() || req.data.compound.size()) {
- valueCStr = evhttp_encode_uri(Data::toJSON(req.data).c_str());
- } else if(req.data.node) {
+ if (event.data.atom.length() || event.data.array.size() || event.data.compound.size()) {
+ valueCStr = evhttp_encode_uri(Data::toJSON(event.data).c_str());
+ } else if(event.data.node) {
std::stringstream xmlStream;
- xmlStream << req.data.node;
+ xmlStream << event.data.node;
valueCStr = evhttp_encode_uri(xmlStream.str().c_str());
- } else if(req.data.binary) {
- valueCStr = evhttp_encode_uri(req.data.binary.base64().c_str());
+ } else if(event.data.binary) {
+ valueCStr = evhttp_encode_uri(event.data.binary.base64().c_str());
}
if (valueCStr != NULL) {
kvps << kvpSeperator << keyCStr << "=" << valueCStr;
@@ -273,13 +258,12 @@ void BasicHTTPIOProcessor::send(const SendRequest& req) {
free(keyCStr);
targetURL.setOutContent(kvps.str());
+ targetURL.addOutHeader("Content-Type", "application/x-www-form-urlencoded");
-// targetURL.addOutHeader("Content-Type", "application/x-www-form-urlencoded");
-
- targetURL.setRequestType("post");
+ targetURL.setRequestType(URLRequestType::POST);
targetURL.addMonitor(this);
- _sendRequests[req.sendid] = std::make_pair(targetURL, req);
+ _sendRequests[event.sendid] = std::make_pair(targetURL, event);
if (isLocal) {
// test201 use a blocking request with local communication
targetURL.download(true);
@@ -291,7 +275,7 @@ void BasicHTTPIOProcessor::send(const SendRequest& req) {
void BasicHTTPIOProcessor::downloadStarted(const URL& url) {}
void BasicHTTPIOProcessor::downloadCompleted(const URL& url) {
- std::map<std::string, std::pair<URL, SendRequest> >::iterator reqIter = _sendRequests.begin();
+ std::map<std::string, std::pair<URL, Event> >::iterator reqIter = _sendRequests.begin();
while(reqIter != _sendRequests.end()) {
if (reqIter->second.first == url) {
// test513
@@ -302,7 +286,7 @@ void BasicHTTPIOProcessor::downloadCompleted(const URL& url) {
Event event;
event.data = url;
event.name = "HTTP." + statusPrefix + "." + statusRest;
-// returnEvent(event);
+ eventToSCXML(event, USCXML_IOPROC_BASICHTTP_TYPE, std::string(_url));
}
_sendRequests.erase(reqIter);
return;
@@ -314,12 +298,12 @@ void BasicHTTPIOProcessor::downloadCompleted(const URL& url) {
void BasicHTTPIOProcessor::downloadFailed(const URL& url, int errorCode) {
- std::map<std::string, std::pair<URL, SendRequest> >::iterator reqIter = _sendRequests.begin();
+ std::map<std::string, std::pair<URL, Event> >::iterator reqIter = _sendRequests.begin();
while(reqIter != _sendRequests.end()) {
if (reqIter->second.first == url) {
Event failEvent;
failEvent.name = "error.communication";
- returnEvent(failEvent);
+ eventToSCXML(failEvent, USCXML_IOPROC_BASICHTTP_TYPE, std::string(_url));
_sendRequests.erase(reqIter);
return;
diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h
index 3a43e49..f7e9f10 100644
--- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h
+++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h
@@ -35,10 +35,9 @@ extern "C" {
# define USCXML_PLUGIN_API
#endif
-#include "uscxml/concurrency/DelayedEventQueue.h"
#include "uscxml/server/HTTPServer.h"
#include "uscxml/Interpreter.h"
-#include "uscxml/Factory.h"
+#include "uscxml/plugins/Factory.h"
#ifndef _WIN32
#include <sys/time.h>
#endif
@@ -47,27 +46,30 @@ extern "C" {
#include "uscxml/plugins/Plugins.h"
#endif
+#define USCXML_IOPROC_BASICHTTP_TYPE "http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor"
+
namespace uscxml {
class USCXML_PLUGIN_API BasicHTTPIOProcessor : public IOProcessorImpl, public HTTPServlet, public URLMonitor {
public:
BasicHTTPIOProcessor();
virtual ~BasicHTTPIOProcessor();
- virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
+ virtual std::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
virtual std::list<std::string> getNames() {
std::list<std::string> names;
names.push_back("basichttp");
- names.push_back("http://www.w3.org/TR/scxml/#BasicHTTPEventProcessor");
+ names.push_back(USCXML_IOPROC_BASICHTTP_TYPE);
return names;
}
- virtual void send(const SendRequest& req);
+ virtual void eventFromSCXML(const std::string& target, const Event& event);
+ virtual bool isValidTarget(const std::string& target);
Data getDataModelVariables();
/// HTTPServlet
- bool httpRecvRequest(const HTTPServer::Request& req);
+ bool requestFromHTTP(const HTTPServer::Request& req);
void setURL(const std::string& url) {
_url = url;
}
@@ -83,7 +85,7 @@ public:
protected:
std::string _url;
- std::map<std::string, std::pair<URL, SendRequest> > _sendRequests;
+ std::map<std::string, std::pair<URL, Event> > _sendRequests;
};
// do not implement pluma plugins if we build an inherited plugin
diff --git a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp
deleted file mode 100644
index 9ec5c00..0000000
--- a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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/plugins/ioprocessor/comet/CometIOProcessor.h"
-#include "uscxml/Message.h"
-#include <iostream>
-
-#include <DOM/io/Stream.hpp>
-#include <string.h>
-
-#ifdef BUILD_AS_PLUGINS
-#include <Pluma/Connector.hpp>
-#endif
-
-namespace uscxml {
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_CONNECTOR
-bool pluginConnect(pluma::Host& host) {
- host.add( new CometIOProcessorProvider() );
- return true;
-}
-#endif
-
-CometIOProcessor::CometIOProcessor() {
-}
-
-CometIOProcessor::~CometIOProcessor() {
- HTTPServer::unregisterServlet(this);
-}
-
-boost::shared_ptr<IOProcessorImpl> CometIOProcessor::create(InterpreterImpl* interpreter) {
- boost::shared_ptr<CometIOProcessor> io = boost::shared_ptr<CometIOProcessor>(new CometIOProcessor());
- io->_interpreter = interpreter;
-
- // register at http server
- std::string path = interpreter->getName();
- int i = 2;
- while (!HTTPServer::registerServlet(path + "/comet", io.get())) {
- std::stringstream ss;
- ss << interpreter->getName() << i++;
- path = ss.str();
- }
-
- return io;
-}
-
-Data CometIOProcessor::getDataModelVariables() {
- Data data;
- return data;
-}
-
-void CometIOProcessor::send(const SendRequest& req) {
- tthread::lock_guard<tthread::recursive_mutex> lock(_mutex);
- if (!_longPollingReq) {
- _outQueue.push_back(req);
- return;
- }
- reply(req, _longPollingReq);
-}
-
-void CometIOProcessor::reply(const SendRequest& req, const HTTPServer::Request& longPoll) {
- HTTPServer::Reply reply(longPoll);
-
- if (req.dom) {
- std::stringstream ss;
- ss << req.dom;
- reply.content = ss.str();
- reply.headers["Content-Type"] = "application/xml";
- } else if (!req.data.empty()) {
- reply.content = Data::toJSON(req.data);
- reply.headers["Content-Type"] = "application/json";
- } else if (req.content.length() > 0) {
- reply.content = req.content;
- reply.headers["Content-Type"] = "text/plain";
- }
-
- if (req.params.find("Content-Type") != req.params.end())
- reply.headers["Content-Type"] = req.params.find("Content-Type")->first;
-
- HTTPServer::reply(reply);
-}
-
-bool CometIOProcessor::httpRecvRequest(const HTTPServer::Request& request) {
- tthread::lock_guard<tthread::recursive_mutex> lock(_mutex);
-
- if (_longPollingReq)
- // send 204 to last request and remember new one
- evhttp_send_error(_longPollingReq.evhttpReq, 204, NULL);
- _longPollingReq = request;
- if (!_outQueue.empty()) {
- send(_outQueue.front());
- _outQueue.pop_front();
- }
- return true;
-}
-
-} \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h b/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h
deleted file mode 100644
index 0a57d70..0000000
--- a/src/uscxml/plugins/ioprocessor/comet/CometIOProcessor.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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 COMETIOPROCESSOR_H_2CUY93KU
-#define COMETIOPROCESSOR_H_2CUY93KU
-
-#include "uscxml/concurrency/DelayedEventQueue.h"
-#include "uscxml/server/HTTPServer.h"
-#include "uscxml/Interpreter.h"
-#include "uscxml/Factory.h"
-
-#ifdef BUILD_AS_PLUGINS
-#include "uscxml/plugins/Plugins.h"
-#endif
-
-namespace uscxml {
-
-class CometIOProcessor : public IOProcessorImpl, public HTTPServlet {
-public:
- CometIOProcessor();
- virtual ~CometIOProcessor();
- virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
-
- virtual std::list<std::string> getNames() {
- std::list<std::string> names;
- names.push_back("comet");
- names.push_back("http://www.w3.org/TR/scxml/#CometEventProcessor");
- return names;
- }
-
- /// This method can be overridden for specific replies
- virtual void reply(const SendRequest& req, const HTTPServer::Request& longPoll);
-
- virtual void send(const SendRequest& req);
- Data getDataModelVariables();
-
- virtual bool httpRecvRequest(const HTTPServer::Request& request);
- virtual void setURL(const std::string& url) {
- _url = url;
- }
-
-protected:
- tthread::recursive_mutex _mutex;
- std::string _url;
- std::deque<SendRequest> _outQueue;
- HTTPServer::Request _longPollingReq;
-
-};
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_INHERIT_PROVIDER(CometIOProcessor, IOProcessorImpl);
-#endif
-
-}
-
-#endif /* end of include guard: COMETIOPROCESSOR_H_2CUY93KU */ \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.cpp
deleted file mode 100644
index 1a3417a..0000000
--- a/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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
- */
-
diff --git a/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.h b/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.h
deleted file mode 100644
index 1a3417a..0000000
--- a/src/uscxml/plugins/ioprocessor/dom/DOMIOProcessor.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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
- */
-
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp
deleted file mode 100644
index 15c05c0..0000000
--- a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h"
-#include "uscxml/Message.h"
-
-#ifdef BUILD_AS_PLUGINS
-#include <Pluma/Connector.hpp>
-#endif
-
-namespace uscxml {
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_CONNECTOR
-bool pluginConnect(pluma::Host& host) {
- host.add( new MMIHTTPIOProcessorProvider() );
- return true;
-}
-#endif
-
-MMIHTTPIOProcessor::MMIHTTPIOProcessor() {
-}
-
-MMIHTTPIOProcessor::~MMIHTTPIOProcessor() {
-}
-
-boost::shared_ptr<IOProcessorImpl> MMIHTTPIOProcessor::create(InterpreterImpl* interpreter) {
- boost::shared_ptr<MMIHTTPIOProcessor> io = boost::shared_ptr<MMIHTTPIOProcessor>(new MMIHTTPIOProcessor());
- io->_interpreter = interpreter;
-
- // register at http server
- std::string path = interpreter->getName();
- int i = 2;
- while (!HTTPServer::registerServlet(path + "/mmihttp", io.get())) {
- std::stringstream ss;
- ss << interpreter->getName() << i++;
- path = ss.str();
- }
-
- return io;
-}
-
-bool MMIHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) {
- Event reqEvent = req;
- reqEvent.eventType = Event::EXTERNAL;
- bool scxmlStructFound = false;
-
- if (reqEvent.data.compound["header"].compound.find("Content-Type") != reqEvent.data.compound["header"].compound.end() &&
- boost::iequals(reqEvent.data.compound["header"].compound["Content-Type"].atom, "application/x-www-form-urlencoded")) {
- std::stringstream ss(reqEvent.data.compound["content"].atom);
- std::string term;
- while(std::getline(ss, term, '&')) {
- size_t split = term.find_first_of("=");
- if (split != std::string::npos) {
- std::string key = evhttp_decode_uri(term.substr(0, split).c_str());
- std::string value = evhttp_decode_uri(term.substr(split + 1).c_str());
- if (boost::iequals(key, "_scxmleventname")) {
- reqEvent.name = value;
- } else if (boost::iequals(key, "content")) {
- reqEvent.initContent(value);
- } else {
- reqEvent.data.compound[key] = value;
- reqEvent.params.insert(std::make_pair(key, value));
- }
- } else {
- // this is most likely wrong
- reqEvent.content = evhttp_decode_uri(term.c_str());
- }
- }
- } else {
- if (reqEvent.data.compound["header"].compound.find("_scxmleventstruct") != reqEvent.data.compound["header"].compound.end()) {
- // TODO: this looses all other information
- reqEvent = Event::fromXML(evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventstruct"].atom.c_str()));
- scxmlStructFound = true;
- }
- if (reqEvent.data.compound["header"].compound.find("_scxmleventname") != reqEvent.data.compound["header"].compound.end()) {
- reqEvent.name = evhttp_decode_uri(reqEvent.data.compound["header"].compound["_scxmleventname"].atom.c_str());
- }
- }
- std::map<std::string, Data>::iterator headerIter = reqEvent.data.compound["header"].compound.begin();
- while(headerIter != reqEvent.data.compound["header"].compound.end()) {
- reqEvent.data.compound[headerIter->first] = Data(evhttp_decode_uri(headerIter->second.atom.c_str()), Data::VERBATIM);
- headerIter++;
- }
-
-#if 0
- std::map<std::string, std::string>::const_iterator headerIter = req.headers.begin();
- while(headerIter != req.headers.end()) {
- if (boost::iequals("_scxmleventstruct", headerIter->first)) {
- reqEvent = Event::fromXML(evhttp_decode_uri(headerIter->second.c_str()));
- scxmlStructFound = true;
- break;
- } else if (boost::iequals("_scxmleventname", headerIter->first)) {
- reqEvent.name = evhttp_decode_uri(headerIter->second.c_str());
- } else {
- reqEvent.data.compound[headerIter->first] = Data(evhttp_decode_uri(headerIter->second.c_str()), Data::VERBATIM);
- }
- headerIter++;
- }
-#endif
-
- /// test532
- if (reqEvent.name.length() == 0)
- reqEvent.name = "http." + req.data.compound.at("type").atom;
-
- if (!scxmlStructFound) {
- // get content into event
- reqEvent.data.compound["content"] = Data(req.content, Data::VERBATIM);
- }
-
- returnEvent(reqEvent);
- evhttp_send_reply(req.curlReq, 200, "OK", NULL);
- return true;
-}
-
-void MMIHTTPIOProcessor::send(const SendRequest& req) {
-
- if (req.target.length() == 0) {
- _interpreter->receiveInternal(Event("error.communication", Event::PLATFORM));
- return;
- }
-
- bool isLocal = false;
- std::string target;
- if (!boost::equals(req.target, _url)) {
- target = req.target;
- } else {
- isLocal = true;
- target = _url;
- }
- URL targetURL(target);
- std::stringstream kvps;
- std::string kvpSeperator;
-
- // event name
- if (req.name.size() > 0) {
- kvps << kvpSeperator << evhttp_encode_uri("_scxmleventname") << "=" << evhttp_encode_uri(req.name.c_str());
- kvpSeperator = "&";
-// targetURL.addOutHeader("_scxmleventname", evhttp_encode_uri(req.name.c_str()));
- }
-
- // event namelist
- if (req.namelist.size() > 0) {
- std::map<std::string, Data>::const_iterator namelistIter = req.namelist.begin();
- while (namelistIter != req.namelist.end()) {
- // this is simplified - Data might be more elaborate than a simple string atom
- kvps << kvpSeperator << evhttp_encode_uri(namelistIter->first.c_str()) << "=" << evhttp_encode_uri(namelistIter->second.atom.c_str());
- kvpSeperator = "&";
-// targetURL.addOutHeader(namelistIter->first, namelistIter->second);
- namelistIter++;
- }
- }
-
- // event params
- if (req.params.size() > 0) {
- std::multimap<std::string, Data>::const_iterator paramIter = req.params.begin();
- while (paramIter != req.params.end()) {
- // this is simplified - Data might be more elaborate than a simple string atom
- kvps << kvpSeperator << evhttp_encode_uri(paramIter->first.c_str()) << "=" << evhttp_encode_uri(paramIter->second.atom.c_str());
- kvpSeperator = "&";
-// targetURL.addOutHeader(paramIter->first, paramIter->second);
- paramIter++;
- }
- }
-
- // content
-
- if (req.content.size() > 0) {
- kvps << kvpSeperator << evhttp_encode_uri("content") << "=" << evhttp_encode_uri(req.content.c_str());
- kvpSeperator = "&";
- }
- if (req.dom) {
- std::stringstream xmlStream;
- xmlStream << req.dom;
- kvps << kvpSeperator << evhttp_encode_uri("content") << "=" << evhttp_encode_uri(xmlStream.str().c_str());
- kvpSeperator = "&";
- }
- targetURL.setOutContent(kvps.str());
-
- targetURL.setRequestType("post");
- targetURL.addMonitor(this);
-
- _sendRequests[req.sendid] = std::make_pair(targetURL, req);
- if (isLocal) {
- // test201 use a blocking request with local communication
- targetURL.download(true);
- } else {
- URLFetcher::fetchURL(targetURL);
- }
-}
-
-
-
-} \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h
deleted file mode 100644
index 00b47c7..0000000
--- a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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 MMIHTTPIOPROCESSOR_H_P1FN0YPL
-#define MMIHTTPIOPROCESSOR_H_P1FN0YPL
-
-#include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h"
-#include "uscxml/Interpreter.h"
-#include "uscxml/Factory.h"
-#ifndef _WIN32
-#include <sys/time.h>
-#endif
-
-#include <event2/http.h>
-#include <event2/http_struct.h>
-
-#ifdef BUILD_AS_PLUGINS
-#include "uscxml/plugins/Plugins.h"
-#endif
-
-namespace uscxml {
-
-class MMIHTTPIOProcessor : public BasicHTTPIOProcessor {
-public:
- MMIHTTPIOProcessor();
- virtual ~MMIHTTPIOProcessor();
- virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
-
- virtual std::list<std::string> getNames() {
- std::list<std::string> names;
- names.push_back("mmihttp");
- names.push_back("http://www.w3.org/TR/mmi-arch/#HTTPTransport");
- return names;
- }
-
- virtual void send(const SendRequest& req);
-
- /// HTTPServlet
- bool httpRecvRequest(const HTTPServer::Request& req);
-
- bool canAdaptPath() {
- return false;
- }
-
-protected:
- std::string _url;
- std::map<std::string, std::pair<URL, SendRequest> > _sendRequests;
-};
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_INHERIT_PROVIDER(MMIHTTPIOProcessor, IOProcessorImpl);
-#endif
-
-}
-
-#endif /* end of include guard: MMIHTTPIOPROCESSOR_H_P1FN0YPL */
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp
deleted file mode 100644
index c649a17..0000000
--- a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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 "MMIProtoBridge.h"
-
-#define INIT_PROTO_LIFE_CYCLE_EVENT(type) \
-::LifeCycleEvent lifeCycleEvent; \
-lifeCycleEvent.set_type(type); \
-lifeCycleEvent.set_requestid(mmiEvent.requestId); \
-lifeCycleEvent.set_source(mmiEvent.source); \
-lifeCycleEvent.set_target(mmiEvent.target);
-
-namespace uscxml {
-
-::LifeCycleEvent MMIProtoBridge::toProto(const NewContextRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_NEW_CONTEXT_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const NewContextResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_NEW_CONTEXT_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const PrepareRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_PREPARE_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const PrepareResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_PREPARE_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const StartRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_START_REQUEST);
-
- ::LifeCycleRequest* lifeCycleRequest = lifeCycleEvent.MutableExtension(::LifeCycleRequest::Request);
- lifeCycleRequest->set_context(mmiEvent.context);
-
- ::StartRequest* startRequest = lifeCycleRequest->MutableExtension(::StartRequest::Request);
- startRequest->set_content(mmiEvent.content);
- startRequest->set_contenturl(mmiEvent.contentURL.href);
-
- ::StartRequestData* startRequestData = startRequest->MutableExtension(::StartRequestData::Request);
- startRequestData->set_data(mmiEvent.data);
-
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const StartResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_START_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const DoneNotification& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_DONE_NOTIFICATION);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const CancelRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_CANCEL_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const CancelResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_CANCEL_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const PauseRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_PAUSE_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const PauseResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_PAUSE_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const ResumeRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_RESUME_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const ResumeResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_RESUME_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const ExtensionNotification& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_EXTENSION_NOTIFICATION);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const ClearContextRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_CLEAR_CONTEXT_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const ClearContextResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_CLEAR_CONTEXT_RESPONSE);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const StatusRequest& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_STATUS_REQUEST);
- return lifeCycleEvent;
-}
-
-::LifeCycleEvent MMIProtoBridge::toProto(const StatusResponse& mmiEvent) {
- INIT_PROTO_LIFE_CYCLE_EVENT(::LifeCycleEvent_LifeCycleEventType_STATUS_RESPONSE);
- return lifeCycleEvent;
-}
-
-} \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h b/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h
deleted file mode 100644
index 60ba824..0000000
--- a/src/uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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 MMIPROTOBRIDGE_H_T6VXUX69
-#define MMIPROTOBRIDGE_H_T6VXUX69
-
-#include "LifeCycleEvents.pb.h"
-#include "StringDataExtension.pb.h"
-#include "MMIMessages.h"
-
-namespace uscxml {
-
-class MMIProtoBridge {
-public:
- static ::LifeCycleEvent toProto(const NewContextRequest&);
- static ::LifeCycleEvent toProto(const NewContextResponse&);
- static ::LifeCycleEvent toProto(const PrepareRequest&);
- static ::LifeCycleEvent toProto(const PrepareResponse&);
- static ::LifeCycleEvent toProto(const StartRequest&);
- static ::LifeCycleEvent toProto(const StartResponse&);
- static ::LifeCycleEvent toProto(const DoneNotification&);
- static ::LifeCycleEvent toProto(const CancelRequest&);
- static ::LifeCycleEvent toProto(const CancelResponse&);
- static ::LifeCycleEvent toProto(const PauseRequest&);
- static ::LifeCycleEvent toProto(const PauseResponse&);
- static ::LifeCycleEvent toProto(const ResumeRequest&);
- static ::LifeCycleEvent toProto(const ResumeResponse&);
- static ::LifeCycleEvent toProto(const ExtensionNotification&);
- static ::LifeCycleEvent toProto(const ClearContextRequest&);
- static ::LifeCycleEvent toProto(const ClearContextResponse&);
- static ::LifeCycleEvent toProto(const StatusRequest&);
- static ::LifeCycleEvent toProto(const StatusResponse&);
-};
-
-}
-
-#endif /* end of include guard: MMIPROTOBRIDGE_H_T6VXUX69 */
diff --git a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp
deleted file mode 100644
index bca2344..0000000
--- a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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/plugins/ioprocessor/sample/SampleIOProcessor.h"
-#include "uscxml/Message.h"
-#include <iostream>
-
-#include <string.h>
-
-#ifdef BUILD_AS_PLUGINS
-#include <Pluma/Connector.hpp>
-#endif
-
-namespace uscxml {
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_CONNECTOR
-bool pluginConnect(pluma::Host& host) {
- host.add( new SampleIOProcessorProvider() );
- return true;
-}
-#endif
-
-SampleIOProcessor::SampleIOProcessor() {
-}
-
-SampleIOProcessor::~SampleIOProcessor() {
-}
-
-boost::shared_ptr<IOProcessorImpl> SampleIOProcessor::create(InterpreterImpl* interpreter) {
- boost::shared_ptr<SampleIOProcessor> io = boost::shared_ptr<SampleIOProcessor>(new SampleIOProcessor());
- return io;
-}
-
-Data SampleIOProcessor::getDataModelVariables() {
- Data data;
- return data;
-}
-
-void SampleIOProcessor::send(const SendRequest& req) {
-}
-
-} \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h b/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h
deleted file mode 100644
index 05dd3ef..0000000
--- a/src/uscxml/plugins/ioprocessor/sample/SampleIOProcessor.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * @file
- * @author 2012-2013 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 SAMPLEIOPROCESSOR_H_2CUY93KU
-#define SAMPLEIOPROCESSOR_H_2CUY93KU
-
-#include "uscxml/Factory.h"
-
-#ifdef BUILD_AS_PLUGINS
-#include "uscxml/plugins/Plugins.h"
-#endif
-
-#if defined(_WIN32) && !defined(USCXML_STATIC)
-# if (defined ioprocessor_sample_EXPORTS || defined USCXML_EXPORT)
-# define USCXML_PLUGIN_API __declspec(dllexport)
-# else
-# define USCXML_PLUGIN_API __declspec(dllimport)
-# endif
-#else
-# define USCXML_PLUGIN_API
-#endif
-
-namespace uscxml {
-
-class USCXML_PLUGIN_API SampleIOProcessor : public IOProcessorImpl {
-public:
- SampleIOProcessor();
- virtual ~SampleIOProcessor();
- virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
-
- virtual std::list<std::string> getNames() {
- std::list<std::string> names;
- names.push_back("sample");
- names.push_back("http://www.w3.org/TR/scxml/#SampleEventProcessor");
- return names;
- }
-
- virtual void send(const SendRequest& req);
- Data getDataModelVariables();
-
-protected:
-};
-
-#ifdef BUILD_AS_PLUGINS
-PLUMA_INHERIT_PROVIDER(SampleIOProcessor, IOProcessorImpl);
-#endif
-
-}
-
-#endif /* end of include guard: SAMPLEIOPROCESSOR_H_2CUY93KU */ \ No newline at end of file
diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp
index 6905e22..c53915b 100644
--- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp
+++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp
@@ -17,88 +17,64 @@
* @endcond
*/
-#include <boost/algorithm/string.hpp>
-#ifdef _WIN32
-#define NOMINMAX
-#include <winsock2.h>
-#include <windows.h>
-#endif
-
-#include "uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h"
-#include "uscxml/Message.h"
-#include <iostream>
-#include <event2/dns.h>
-#include <event2/buffer.h>
-#include <event2/keyvalq_struct.h>
+#include "SCXMLIOProcessor.h"
+#include "uscxml/messages/Event.h"
+#include "uscxml/interpreter/InterpreterImpl.h"
#include <string.h>
-#include <io/uri.hpp>
-#include <glog/logging.h>
#ifndef _WIN32
#include <netdb.h>
#include <arpa/inet.h>
#endif
-#ifdef BUILD_AS_PLUGINS
-#include <Pluma/Connector.hpp>
-#endif
-
namespace uscxml {
-#ifdef BUILD_AS_PLUGINS
-PLUMA_CONNECTOR
-bool pluginConnect(pluma::Host& host) {
- host.add( new SCXMLIOProcessorProvider() );
- return true;
-}
-#endif
-
// see http://www.w3.org/TR/scxml/#SCXMLEventProcessor
SCXMLIOProcessor::SCXMLIOProcessor() {
}
SCXMLIOProcessor::~SCXMLIOProcessor() {
- HTTPServer::unregisterServlet(this);
}
-boost::shared_ptr<IOProcessorImpl> SCXMLIOProcessor::create(InterpreterImpl* interpreter) {
- boost::shared_ptr<SCXMLIOProcessor> io = boost::shared_ptr<SCXMLIOProcessor>(new SCXMLIOProcessor());
+std::shared_ptr<IOProcessorImpl> SCXMLIOProcessor::create(InterpreterImpl* interpreter) {
+ std::shared_ptr<SCXMLIOProcessor> io(new SCXMLIOProcessor());
io->_interpreter = interpreter;
-
- // register at http server
- std::string path = interpreter->getName();
- int i = 2;
- while (!HTTPServer::registerServlet(path + "/scxml", io.get())) {
- std::stringstream ss;
- ss << interpreter->getName() << i++;
- path = ss.str();
- }
return io;
}
Data SCXMLIOProcessor::getDataModelVariables() {
Data data;
- if(_url.length() > 0)
- data.compound["location"] = Data(_url, Data::VERBATIM);
+
+ data.compound["location"] = Data("#_scxml_" + _interpreter->getSessionId(), Data::VERBATIM);
+
return data;
}
+bool SCXMLIOProcessor::isValidTarget(const std::string& target) {
+ if (target.size() > 0 && (target[0] != '#' || target[1] != '_')) {
+ ERROR_EXECUTION_THROW("Target '" + target + "' not supported in send");
+ }
+ return true;
+}
+
-void SCXMLIOProcessor::send(const SendRequest& req) {
+void SCXMLIOProcessor::eventFromSCXML(const std::string& target, const Event& event) {
// see http://www.w3.org/TR/scxml/#SendTargets
+ Event eventCopy(event);
- SendRequest reqCopy(req);
- // test 253
- reqCopy.origintype = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor";
- reqCopy.origin = _url;
+ // test 253 / 198 / 336
+ eventCopy.origintype = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor";
+
+ // test 336
+ eventCopy.origin = "#_scxml_" + _interpreter->getSessionId();
if (false) {
- } else if(reqCopy.target.length() == 0) {
+ } else if(target.length() == 0) {
/**
* If neither the 'target' nor the 'targetexpr' attribute is specified, the
* SCXML Processor must add the event will be added to the external event
@@ -107,16 +83,31 @@ void SCXMLIOProcessor::send(const SendRequest& req) {
// test333 vs test351
// reqCopy.sendid = "";
+
// test 198
- _interpreter->receive(reqCopy);
- } else if (iequals(reqCopy.target, "#_internal")) {
+ _interpreter->enqueueExternal(eventCopy);
+
+ } else if (iequals(target, "#_internal")) {
/**
* #_internal: If the target is the special term '#_internal', the Processor
* must add the event to the internal event queue of the sending session.
*/
- _interpreter->receiveInternal(reqCopy);
+ _interpreter->enqueueInternal(eventCopy);
- } else if(boost::starts_with(reqCopy.target, "#_scxml_")) {
+ } else if (iequals(target, "#_parent")) {
+ /**
+ * #_parent: If the target is the special term '#_parent', the Processor must
+ * add the event to the external event queue of the SCXML session that invoked
+ * the sending session, if there is one.
+ */
+
+ if (_interpreter->_parentQueue) {
+ _interpreter->_parentQueue.enqueue(eventCopy);
+ } else {
+ ERROR_COMMUNICATION_THROW("Sending to parent invoker, but none is set");
+ }
+
+ } else if (target.length() > 8 && iequals(target.substr(0, 8), "#_scxml_")) {
/**
* #_scxml_sessionid: If the target is the special term '#_scxml_sessionid',
* where sessionid is the id of an SCXML session that is accessible to the
@@ -124,66 +115,46 @@ void SCXMLIOProcessor::send(const SendRequest& req) {
* session. The set of SCXML sessions that are accessible to a given SCXML
* Processor is platform-dependent.
*/
- std::string sessionId = reqCopy.target.substr(8, reqCopy.target.length() - 8);
- std::map<std::string, boost::weak_ptr<InterpreterImpl> > instances = Interpreter::getInstances();
- if (instances.find(sessionId) != instances.end()) {
- boost::shared_ptr<InterpreterImpl> other = instances[sessionId].lock();
- other->receive(reqCopy);
- } else {
- ERROR_COMMUNICATION(error, "Can not send to scxml session " + sessionId + " - not known");
- error.sendid = reqCopy.sendid;
- _interpreter->receiveInternal(error);
+ std::string sessionId = target.substr(8);
- }
- } else if (iequals(reqCopy.target, "#_parent")) {
- /**
- * #_parent: If the target is the special term '#_parent', the Processor must
- * add the event to the external event queue of the SCXML session that invoked
- * the sending session, if there is one.
- */
- if (_interpreter->_parentQueue != NULL) {
- _interpreter->_parentQueue->push(reqCopy);
+ std::lock_guard<std::recursive_mutex> lock(_interpreter->_instanceMutex);
+ std::map<std::string, std::weak_ptr<InterpreterImpl> > instances = InterpreterImpl::getInstances();
+ if (instances.find(sessionId) != instances.end()) {
+ std::shared_ptr<InterpreterImpl> otherSession = instances[sessionId].lock();
+ if (otherSession) {
+ otherSession->enqueueExternal(eventCopy);
+ } else {
+ ERROR_COMMUNICATION_THROW("Can not send to scxml session " + sessionId + " - not known");
+ }
} else {
- ERROR_COMMUNICATION(error, "Can not send to parent, we were not invoked or no parent queue is set");
- error.sendid = reqCopy.sendid;
- _interpreter->receiveInternal(error);
+ ERROR_COMMUNICATION_THROW("Invalid target scxml session for send");
}
- } else if (boost::starts_with(reqCopy.target, "#_")) {
+
+ } else if (target.length() > 2 && iequals(target.substr(0, 2), "#_")) {
/**
* #_invokeid: If the target is the special term '#_invokeid', where invokeid
* is the invokeid of an SCXML session that the sending session has created
* by <invoke>, the Processor must add the event to the external queue of that
* session.
*/
- std::string invokeId = reqCopy.target.substr(2, reqCopy.target.length() - 2);
+ std::string invokeId = target.substr(2);
if (_interpreter->_invokers.find(invokeId) != _interpreter->_invokers.end()) {
- tthread::lock_guard<tthread::recursive_mutex> lock(_interpreter->_mutex);
+ std::lock_guard<std::recursive_mutex> lock(_interpreter->_instanceMutex);
try {
- _interpreter->_invokers[invokeId].send(reqCopy);
+ _interpreter->_invokers[invokeId].eventFromSCXML(eventCopy);
} catch(Event e) {
// Is this the right thing to do?
- _interpreter->receive(e);
+// _interpreter->enqueueExternal(eventCopy);
} catch (const std::exception &e) {
- LOG(ERROR) << "Exception caught while sending event to invoker " << invokeId << ": " << e.what();
+ ERROR_COMMUNICATION_THROW("Exception caught while sending event to invoker '" + invokeId + "': " + e.what());
} catch(...) {
- LOG(ERROR) << "Exception caught while sending event to invoker " << invokeId;
+ ERROR_COMMUNICATION_THROW("Exception caught while sending event to invoker '" + invokeId + "'");
}
} else {
- ERROR_COMMUNICATION(error, "Can not send to invoked component '" + invokeId + "', no such invokeId");
- error.sendid = reqCopy.sendid;
- _interpreter->receiveInternal(error);
+ ERROR_COMMUNICATION_THROW("Can not send to invoked component '" + invokeId + "', no such invokeId");
}
} else {
- URL target(reqCopy.target);
- if (target.isAbsolute()) {
- BasicHTTPIOProcessor::send(reqCopy);
- } else {
- ERROR_EXECUTION(error, "Not sure what to make of the target '" + reqCopy.target + "' - raising error");
- error.sendid = reqCopy.sendid;
- // test 159 still fails
-// _interpreter->receiveInternal(error);
- throw error;
- }
+ ERROR_COMMUNICATION_THROW("Not sure what to make of the target '" + target + "' - raising error");
}
}
diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h
index 3eca2db..3b08e30 100644
--- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h
+++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.h
@@ -20,19 +20,15 @@
#ifndef SCXMLIOProcessor_H_2CUY93KU
#define SCXMLIOProcessor_H_2CUY93KU
-#include "uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.h"
-
-#ifdef BUILD_AS_PLUGINS
-#include "uscxml/plugins/Plugins.h"
-#endif
+#include "uscxml/plugins/IOProcessor.h"
namespace uscxml {
-class SCXMLIOProcessor : public BasicHTTPIOProcessor {
+class SCXMLIOProcessor : public IOProcessorImpl {
public:
SCXMLIOProcessor();
virtual ~SCXMLIOProcessor();
- virtual boost::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
+ virtual std::shared_ptr<IOProcessorImpl> create(uscxml::InterpreterImpl* interpreter);
virtual std::list<std::string> getNames() {
std::list<std::string> names;
@@ -41,9 +37,12 @@ public:
return names;
}
- virtual void send(const SendRequest& req);
+ virtual void eventFromSCXML(const std::string& target, const Event& event);
+ virtual bool isValidTarget(const std::string& target);
Data getDataModelVariables();
+protected:
+ InterpreterImpl* _interpreter;
};
#ifdef BUILD_AS_PLUGINS