diff options
Diffstat (limited to 'src')
-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 |
8 files changed, 95 insertions, 68 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); |