diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-13 15:02:25 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-13 15:02:25 (GMT) |
commit | 66b0852b0618cc4bfff08d47aa0af56353226190 (patch) | |
tree | f1194ccb83779aef83e6d4afbfe8aee0aaedd224 | |
parent | fe941ab36b44f083886c07a72d371b2cfba55fe3 (diff) | |
download | uscxml-66b0852b0618cc4bfff08d47aa0af56353226190.zip uscxml-66b0852b0618cc4bfff08d47aa0af56353226190.tar.gz uscxml-66b0852b0618cc4bfff08d47aa0af56353226190.tar.bz2 |
Started renewed VoiceXMLInvoker
-rw-r--r-- | src/uscxml/Factory.cpp | 7 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.cpp (renamed from src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp) | 0 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.h (renamed from src/uscxml/plugins/ioprocessor/modality/MMIMessages.h) | 0 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/CMakeLists.txt | 38 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp | 2 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp | 87 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h | 25 | ||||
-rw-r--r-- | src/uscxml/server/HTTPServer.cpp | 4 | ||||
-rw-r--r-- | test/src/test-url.cpp | 2 | ||||
-rw-r--r-- | test/src/test-vxml-mmi-http.cpp | 8 | ||||
-rw-r--r-- | test/src/test-vxml-mmi-socket.cpp | 3 | ||||
-rw-r--r-- | test/uscxml/test-jvoicexml.scxml | 70 |
12 files changed, 133 insertions, 113 deletions
diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 3bad07f..ce09a27 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -58,6 +58,7 @@ # include "uscxml/plugins/element/postpone/PostponeElement.h" # include "uscxml/plugins/ioprocessor/comet/CometIOProcessor.h" +# include "uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h" # endif @@ -68,7 +69,6 @@ # if (defined UMUNDO_FOUND && defined PROTOBUF_FOUND) # include "uscxml/plugins/invoker/umundo/UmundoInvoker.h" -//# include "uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h" #endif # ifdef OPENSCENEGRAPH_FOUND @@ -370,6 +370,11 @@ void Factory::registerPlugins() { registerInvoker(invoker); } { + VoiceXMLInvoker* invoker = new VoiceXMLInvoker(); + registerInvoker(invoker); + } + + { FetchElement* element = new FetchElement(); registerExecutableContent(element); } diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp b/src/uscxml/messages/MMIMessages.cpp index 1c5b98a..1c5b98a 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp +++ b/src/uscxml/messages/MMIMessages.cpp diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h b/src/uscxml/messages/MMIMessages.h index e4456f8..e4456f8 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.h +++ b/src/uscxml/messages/MMIMessages.h diff --git a/src/uscxml/plugins/invoker/CMakeLists.txt b/src/uscxml/plugins/invoker/CMakeLists.txt index 31ec444..2d55aa1 100644 --- a/src/uscxml/plugins/invoker/CMakeLists.txt +++ b/src/uscxml/plugins/invoker/CMakeLists.txt @@ -550,27 +550,23 @@ if (NOT BUILD_MINIMAL) endif() - # VoiceXML modality components - - if (UMUNDO_FOUND AND OFF) - set(USCXML_INVOKERS "vxml ${USCXML_INVOKERS}") - file(GLOB_RECURSE VXML_INVOKER - vxml/*.cpp - vxml/*.h - ) - if (BUILD_AS_PLUGINS) - source_group("" FILES ${VXML_INVOKER}) - add_library( - invoker_voicexml SHARED - ${VXML_INVOKER} - "../Plugins.cpp") - target_link_libraries(invoker_voicexml uscxml) - set_target_properties(invoker_voicexml PROPERTIES FOLDER "Plugin Invoker") - set_target_properties(invoker_voicexml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") - set_target_properties(invoker_voicexml PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib") - else() - list (APPEND USCXML_FILES ${VXML_INVOKER}) - endif() + set(USCXML_INVOKERS "vxml ${USCXML_INVOKERS}") + file(GLOB_RECURSE VXML_INVOKER + vxml/*.cpp + vxml/*.h + ) + if (BUILD_AS_PLUGINS) + source_group("" FILES ${VXML_INVOKER}) + add_library( + invoker_voicexml SHARED + ${VXML_INVOKER} + "../Plugins.cpp") + target_link_libraries(invoker_voicexml uscxml) + set_target_properties(invoker_voicexml PROPERTIES FOLDER "Plugin Invoker") + set_target_properties(invoker_voicexml PROPERTIES COMPILE_FLAGS "-DPLUMA_EXPORTS") + set_target_properties(invoker_voicexml PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib") + else() + list (APPEND USCXML_FILES ${VXML_INVOKER}) endif() endif() # BUILD_MINIMAL diff --git a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp index f8b4904..cc06b52 100644 --- a/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp +++ b/src/uscxml/plugins/invoker/heartbeat/HeartbeatInvoker.cpp @@ -98,7 +98,7 @@ void HeartbeatInvoker::invoke(const InvokeRequest& req) { void HeartbeatInvoker::dispatch(void* instance, std::string name) { HeartbeatInvoker* invoker = (HeartbeatInvoker*)instance; - invoker->returnEvent(invoker->_event); + invoker->returnEvent(invoker->_event, true); } HeartbeatDispatcher* HeartbeatDispatcher::_instance = NULL; diff --git a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp index 573920f..5a79094 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.cpp @@ -19,11 +19,25 @@ #include "VoiceXMLInvoker.h" #include <glog/logging.h> +#include "uscxml/UUID.h" + +#include <DOM/io/Stream.hpp> #ifdef BUILD_AS_PLUGINS #include <Pluma/Connector.hpp> #endif +#define ISSUE_REQUEST(name) {\ + Arabica::DOM::Document<std::string> name##XML = name.toXML(true);\ + name##XML.getDocumentElement().setPrefix("mmi");\ + std::stringstream name##XMLSS;\ + name##XMLSS << name##XML;\ + URL name##URL(target);\ + name##URL.setOutContent(name##XMLSS.str());\ + name##URL.addOutHeader("Content-type", "application/xml");\ + name##URL.download(false);\ +} + namespace uscxml { #ifdef BUILD_AS_PLUGINS @@ -43,20 +57,15 @@ VoiceXMLInvoker::~VoiceXMLInvoker() { boost::shared_ptr<InvokerImpl> VoiceXMLInvoker::create(InterpreterImpl* interpreter) { boost::shared_ptr<VoiceXMLInvoker> invoker = boost::shared_ptr<VoiceXMLInvoker>(new VoiceXMLInvoker()); invoker->_interpreter = interpreter; - invoker->_pub = umundo::TypedPublisher("mmi:jvoicexml"); - invoker->_sub = umundo::TypedSubscriber("mmi:jvoicexml"); - - invoker->_pub.registerType("LifeCycleEvent", new ::LifeCycleEvent()); - - - invoker->_node.addPublisher(invoker->_pub); - invoker->_node.addSubscriber(invoker->_sub); - return invoker; } -void VoiceXMLInvoker::receive(void* object, umundo::Message* msg) { - std::cout << msg->getMeta("um.s11n.type") << std::endl; +bool VoiceXMLInvoker::httpRecvRequest(const HTTPServer::Request& request) { + return true; +} + +void VoiceXMLInvoker::setURL(const std::string& url) { + _url = url; } Data VoiceXMLInvoker::getDataModelVariables() { @@ -65,33 +74,43 @@ Data VoiceXMLInvoker::getDataModelVariables() { } void VoiceXMLInvoker::send(const SendRequest& req) { - StartRequest start; - std::stringstream domSS; -// if (req.dom) { -// // hack until jVoiceXML supports XML -// std::cout << req.dom; -// Arabica::DOM::NodeList<std::string> prompts = req.dom.getElementsByTagName("vxml:prompt"); -// for (int i = 0; i < prompts.getLength(); i++) { -// if (prompts.item(i).hasChildNodes()) { -// domSS << prompts.item(i).getFirstChild().getNodeValue() << "."; -// } -// } -// } -// domSS << req.getFirstDOMElement(); - domSS << req.dom; - start.content = domSS.str(); - _interpreter->getDataModel().replaceExpressions(start.content); - - start.requestId = "asdf"; - start.source = "asdf"; - start.target = "umundo://mmi/jvoicexml"; - ::LifeCycleEvent lce = MMIProtoBridge::toProto(start); - _pub.sendObj("LifeCycleEvent", &lce); } void VoiceXMLInvoker::invoke(const InvokeRequest& req) { - _pub.waitForSubscribers(1); + HTTPServer::getInstance()->registerServlet(req.invokeid, this); + + std::string target; + Event::getParam(req.params, "target", target); + + NewContextRequest newCtxReq; + newCtxReq.source = _url; + newCtxReq.target = target; + newCtxReq.requestId = uscxml::UUID::getUUID(); + ISSUE_REQUEST(newCtxReq); + + _isRunning = true; + _thread = new tthread::thread(VoiceXMLInvoker::run, this); + +} +void VoiceXMLInvoker::run(void* instance) { + VoiceXMLInvoker* INSTANCE = (VoiceXMLInvoker*)instance; + while(true) { + SendRequest req = INSTANCE->_workQueue.pop(); + if (INSTANCE->_isRunning) { + INSTANCE->process(req); + } else { + return; + } + } +} + +void VoiceXMLInvoker::process(SendRequest& ctx) { + +} + +void VoiceXMLInvoker::uninvoke() { + HTTPServer::getInstance()->unregisterServlet(this); } }
\ 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 88afc1b..b70a073 100644 --- a/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h +++ b/src/uscxml/plugins/invoker/vxml/VoiceXMLInvoker.h @@ -21,11 +21,10 @@ #define VOICEXMLINVOKER_H_W09J90F0 #include <uscxml/Interpreter.h> -#include <uscxml/plugins/ioprocessor/modality/MMIMessages.h> -#include <uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h> +#include <uscxml/messages/MMIMessages.h> +#include "uscxml/server/HTTPServer.h" -#include <umundo/core.h> -#include <umundo/s11n.h> +// #include <uscxml/plugins/ioprocessor/modality/MMIProtoBridge.h> #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" @@ -33,7 +32,7 @@ namespace uscxml { -class VoiceXMLInvoker : public InvokerImpl, public umundo::TypedReceiver { +class VoiceXMLInvoker : public InvokerImpl, public HTTPServlet { public: VoiceXMLInvoker(); virtual ~VoiceXMLInvoker(); @@ -47,17 +46,23 @@ public: return names; } - virtual void receive(void* object, umundo::Message* msg); - + bool httpRecvRequest(const HTTPServer::Request& request); + void setURL(const std::string& url); + virtual Data getDataModelVariables(); virtual void send(const SendRequest& req); virtual void invoke(const InvokeRequest& req); + virtual void uninvoke(); + static void run(void*); + void process(SendRequest& ctx); protected: - umundo::Node _node; - umundo::TypedPublisher _pub; - umundo::TypedSubscriber _sub; + std::string _url; + + tthread::thread* _thread; + concurrency::BlockingQueue<SendRequest> _workQueue; + bool _isRunning; }; #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index 9efdc07..a49bf4e 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -560,8 +560,10 @@ void HTTPServer::wsSendCallback(evutil_socket_t fd, short what, void *arg) { bool HTTPServer::registerServlet(const std::string& path, HTTPServlet* servlet) { HTTPServer* INSTANCE = getInstance(); - if (!INSTANCE->_httpHandle) + if (!INSTANCE->_httpHandle) { + LOG(ERROR) << "Registering a servlet at '" << path << "' with no HTTPServer running, did you forget to specify a port?"; return true; // this is the culprit! + } tthread::lock_guard<tthread::recursive_mutex> lock(INSTANCE->_mutex); diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 046cc8b..b3f9e28 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -48,6 +48,8 @@ int main(int argc, char** argv) { WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
+ HTTPServer::getInstance(8099, 8100);
+
std::string exeName = argv[0];
exeName = exeName.substr(exeName.find_last_of("\\/") + 1);
diff --git a/test/src/test-vxml-mmi-http.cpp b/test/src/test-vxml-mmi-http.cpp index 130441c..a2dd14f 100644 --- a/test/src/test-vxml-mmi-http.cpp +++ b/test/src/test-vxml-mmi-http.cpp @@ -1,5 +1,4 @@ #include "uscxml/config.h" -#include "uscxml/server/Socket.h" #include "uscxml/UUID.h" #include <iostream> #include <stdexcept> @@ -16,22 +15,20 @@ #include "uscxml/server/HTTPServer.h" #include "uscxml/URL.h" #include "uscxml/concurrency/tinythread.h" -#include "uscxml/plugins/ioprocessor/modality/MMIMessages.h" +#include "uscxml/messages/MMIMessages.h" #include <DOM/io/Stream.hpp> #ifdef _WIN32 #include "XGetopt.h" #endif -#include "uscxml/plugins/ioprocessor/modality/MMIMessages.cpp" - #define ISSUE_REQUEST(name) {\ Arabica::DOM::Document<std::string> name##XML = name.toXML(true);\ name##XML.getDocumentElement().setPrefix("mmi");\ std::stringstream name##XMLSS;\ name##XMLSS << name##XML;\ URL name##URL(target);\ - std::cout << name##XMLSS.str();\ + std::cout << "SEND:" << std::endl << name##XMLSS.str() << std::flush;\ name##URL.setOutContent(name##XMLSS.str());\ name##URL.addOutHeader("Content-type", "application/xml");\ name##URL.download(false);\ @@ -50,6 +47,7 @@ std::string context; class MMIServlet : public HTTPServlet { public: bool httpRecvRequest(const HTTPServer::Request& request) { + std::cout << "RCVD:" << std::endl << request << std::flush; tthread::lock_guard<tthread::mutex> lock(Mutex); const Arabica::DOM::Document<std::string>& doc = request.data.at("content").node.getOwnerDocument(); diff --git a/test/src/test-vxml-mmi-socket.cpp b/test/src/test-vxml-mmi-socket.cpp index 8246c3b..99662c9 100644 --- a/test/src/test-vxml-mmi-socket.cpp +++ b/test/src/test-vxml-mmi-socket.cpp @@ -12,10 +12,9 @@ #endif #include "uscxml/concurrency/tinythread.h" -#include "uscxml/plugins/ioprocessor/modality/MMIMessages.h" +#include "uscxml/messages/MMIMessages.h" #include <DOM/io/Stream.hpp> -#include "uscxml/plugins/ioprocessor/modality/MMIMessages.cpp" using namespace uscxml; diff --git a/test/uscxml/test-jvoicexml.scxml b/test/uscxml/test-jvoicexml.scxml index 691a951..311f1c8 100644 --- a/test/uscxml/test-jvoicexml.scxml +++ b/test/uscxml/test-jvoicexml.scxml @@ -2,56 +2,50 @@ xmlns:vxml="http://www.w3.org/2001/vxml" datamodel="ecmascript"> <script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" /> + <state id="start"> <invoke type="heartbeat"> - <param name="interval" expr="'4s'" /> + <param name="interval" expr="'5s'" /> </invoke> - - <invoke type="vxml" id="vxml"> - <finalize> - <script> - dump(_event); - </script> - </finalize> - </invoke> - - <onentry> - <log expr="'Starting!!'" /> - </onentry> + + <state id="vxmlHello"> + <invoke type="vxml" id="vxml"> + <param name="target" expr="'http://localhost:9090/mmi'" /> + <finalize> + <script>dump(_event);</script> + </finalize> + + <content> + <vxml:vxml version="2.1" xml:lang="en" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schematicLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd"> + <vxml:form id="say_hello"> + <vxml:block> + Hello World! + <vxml:goto next="#say_goodbye" /> + </vxml:block> + </vxml:form> + <vxml:form id="say_goodbye"> + <vxml:block> + <vxml:prompt>Goodbye!</vxml:prompt> + </vxml:block> + </vxml:form> + </vxml:vxml> + </content> + </invoke> + + <transition event="heartbeat" target="idle" /> + </state> <state id="idle"> <onentry> <log expr="'Idling!'" /> </onentry> - <transition event="heartbeat.4s" target="vxmlHello"> + <transition event="heartbeat" target="vxmlHello"> <log expr="'Foo!'" /> </transition> </state> - <state id="vxmlHello"> - <onentry> - <send target="#_vxml"> - <content> - <vxml:vxml version="2.1" xml:lang="en" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schematicLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml20/vxml.xsd"> - <vxml:form id="say_hello"> - <vxml:block> - Hello World! - <vxml:goto next="#say_goodbye" /> - </vxml:block> - </vxml:form> - <vxml:form id="say_goodbye"> - <vxml:block> - <vxml:prompt>Goodbye!</vxml:prompt> - </vxml:block> - </vxml:form> - </vxml:vxml> - </content> - </send> - </onentry> - <transition target="idle" /> - </state> </state> </scxml>
\ No newline at end of file |