diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-13 13:29:38 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-08-13 13:29:38 (GMT) |
commit | fe941ab36b44f083886c07a72d371b2cfba55fe3 (patch) | |
tree | 2dfe945f5b0b4272f573cda18f24caa623c122c7 | |
parent | 02f52d15e7df2500c0c6e96660a43a985add16e8 (diff) | |
download | uscxml-fe941ab36b44f083886c07a72d371b2cfba55fe3.zip uscxml-fe941ab36b44f083886c07a72d371b2cfba55fe3.tar.gz uscxml-fe941ab36b44f083886c07a72d371b2cfba55fe3.tar.bz2 |
Build on Linux and Windows again
-rw-r--r-- | src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp | 2 | ||||
-rw-r--r-- | src/uscxml/server/Socket.cpp | 47 | ||||
-rw-r--r-- | src/uscxml/server/Socket.h | 4 | ||||
-rw-r--r-- | test/CMakeLists.txt | 19 | ||||
-rw-r--r-- | test/src/test-sockets.cpp | 4 | ||||
-rw-r--r-- | test/src/test-vxml-mmi-http.cpp | 25 |
6 files changed, 63 insertions, 38 deletions
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp index 67a2371..1c5b98a 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp +++ b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp @@ -160,7 +160,7 @@ Arabica::DOM::Document<std::string> ContentRequest::toXML(bool encapsulateInMMI) Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild()); if (contentURL.href.size() > 0) { - Element<std::string> contentURLElem = doc.createElementNS(nameSpace, "contentURL"); + Element<std::string> contentURLElem = doc.createElementNS(nameSpace, "ContentURL"); contentURLElem.setAttributeNS(nameSpace, "href", contentURL.href); contentURLElem.setAttributeNS(nameSpace, "fetchtimeout", contentURL.fetchTimeout); contentURLElem.setAttributeNS(nameSpace, "max-age", contentURL.maxAge); diff --git a/src/uscxml/server/Socket.cpp b/src/uscxml/server/Socket.cpp index 2d474ea..fc79357 100644 --- a/src/uscxml/server/Socket.cpp +++ b/src/uscxml/server/Socket.cpp @@ -19,6 +19,7 @@ #include "Socket.h" +#include "uscxml/Common.h" // for Data, Event #include "uscxml/Message.h" // for Data, Event #include "uscxml/config.h" // for OPENSSL_FOUND @@ -46,14 +47,6 @@ Socket::Socket(int domain, int type, int protocol) { if (_socketFD == -1) throw std::runtime_error(std::string("socket: ") + strerror(errno)); -#ifndef WIN32 - { - int one = 1; - if (setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) != 0) { - throw std::runtime_error(std::string("setsockopt: ") + strerror(errno)); - } - } -#endif } @@ -300,16 +293,25 @@ void ServerSocket::listen(const std::string& address, int port) { setupSockAddr(address, port); bind(); - int reuseaddr_on = 1; - setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_on, sizeof(reuseaddr_on)); + int one = 1; + if (setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one)) != 0) { + throw std::runtime_error(std::string("setsockopt: ") + strerror(errno)); + } +#ifndef _WIN32 int flags = fcntl(_socketFD, F_GETFL); if (flags >= 0) { flags |= O_NONBLOCK; if (fcntl(_socketFD, F_SETFL, flags) < 0) { - // could not set to non-blocj + // could not set to non-block } } +#else + unsigned long on = 1; + if (ioctlsocket(_socketFD, FIONBIO, &on) != 0) { + // could not set to non-block + } +#endif _listenerEvent = event_new(_base->base, _socketFD, EV_READ|EV_PERSIST, acceptCallback, (void*)this); /*XXX check it */ @@ -353,13 +355,24 @@ void ServerSocket::Connection::reply(const char* data, size_t size) { bufferevent_write(bufferEvent, data, size); } +PacketServerSocket::~PacketServerSocket() { + for(std::map<Connection, std::stringstream*>::iterator fragIter = _fragments.begin(); + fragIter != _fragments.end(); + fragIter++) { + delete fragIter->second; + } +} + void PacketServerSocket::readCallback(const char* data, size_t size, Connection& conn) { - std::stringstream& fragment = _fragments[conn]; - fragment << std::string(data, size); + if (_fragments.find(conn) == _fragments.end()) + _fragments[conn] = new std::stringstream(); + + std::stringstream* fragment = _fragments[conn]; + *fragment << std::string(data, size); size_t startPos = 0; size_t endPos; - const std::string& buffer = fragment.str(); + const std::string& buffer = fragment->str(); while((endPos = buffer.find(_sep, startPos)) != std::string::npos) { // std::cout << ">" << buffer.substr(startPos, endPos - startPos) << "<" << std::endl; readCallback(buffer.substr(startPos, endPos - startPos), conn); @@ -367,9 +380,9 @@ void PacketServerSocket::readCallback(const char* data, size_t size, Connection& } if (startPos != 0 && startPos < buffer.size() + 1) { std::string rest = buffer.substr(startPos); - fragment.str(std::string()); - fragment.clear(); - fragment << rest; + fragment->str(std::string()); + fragment->clear(); + *fragment << rest; } } diff --git a/src/uscxml/server/Socket.h b/src/uscxml/server/Socket.h index 9330c4b..7bb8ebe 100644 --- a/src/uscxml/server/Socket.h +++ b/src/uscxml/server/Socket.h @@ -103,14 +103,14 @@ protected: class USCXML_API PacketServerSocket : public ServerSocket { public: PacketServerSocket(int domain, int type, int protocol, const std::string& sep) : ServerSocket(domain, type, protocol), _sep(sep) {} - virtual ~PacketServerSocket() {} + virtual ~PacketServerSocket(); void readCallback(const char* data, size_t size, Connection& conn); virtual void readCallback(const std::string& packet, Connection& conn) = 0; protected: std::string _sep; - std::map<Connection, std::stringstream> _fragments; + std::map<Connection, std::stringstream*> _fragments; }; class USCXML_API ClientSocket : public Socket { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dbc5a15..b879401 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,6 +62,16 @@ add_test(test-lifecycle ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-lifecycle) set_target_properties(test-lifecycle PROPERTIES FOLDER "Tests") if (NOT WIN32) + add_executable(test-vxml-mmi-socket src/test-vxml-mmi-socket.cpp) + target_link_libraries(test-vxml-mmi-socket uscxml) + # add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-sockets) + set_target_properties(test-vxml-mmi-socket PROPERTIES FOLDER "Tests") + + add_executable(test-vxml-mmi-http src/test-vxml-mmi-http.cpp) + target_link_libraries(test-vxml-mmi-http uscxml) + # add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-sockets) + set_target_properties(test-vxml-mmi-http PROPERTIES FOLDER "Tests") + add_executable(test-trie src/test-trie.cpp) target_link_libraries(test-trie uscxml) add_test(test-trie ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-trie) @@ -141,15 +151,6 @@ target_link_libraries(test-sockets uscxml) # add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-sockets) set_target_properties(test-sockets PROPERTIES FOLDER "Tests") -add_executable(test-vxml-mmi-socket src/test-vxml-mmi-socket.cpp) -target_link_libraries(test-vxml-mmi-socket uscxml) -# add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-sockets) -set_target_properties(test-vxml-mmi-socket PROPERTIES FOLDER "Tests") - -add_executable(test-vxml-mmi-http src/test-vxml-mmi-http.cpp) -target_link_libraries(test-vxml-mmi-http uscxml) -# add_test(test-datamodel ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-sockets) -set_target_properties(test-vxml-mmi-http PROPERTIES FOLDER "Tests") # if (NOT WIN32) # add_executable(test-mmi src/test-mmi.cpp) diff --git a/test/src/test-sockets.cpp b/test/src/test-sockets.cpp index ad567f7..993aaff 100644 --- a/test/src/test-sockets.cpp +++ b/test/src/test-sockets.cpp @@ -87,7 +87,7 @@ int main(int argc, char** argv) { client.write(contentSS.str()); while(packetSeq != iterations) - usleep(10000); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(20)); } if (1) { @@ -105,7 +105,7 @@ int main(int argc, char** argv) { } while(packetSeq != iterations) - usleep(10000); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(20)); } exit(0); diff --git a/test/src/test-vxml-mmi-http.cpp b/test/src/test-vxml-mmi-http.cpp index 50a8dd0..130441c 100644 --- a/test/src/test-vxml-mmi-http.cpp +++ b/test/src/test-vxml-mmi-http.cpp @@ -31,9 +31,10 @@ std::stringstream name##XMLSS;\ name##XMLSS << name##XML;\ URL name##URL(target);\ + std::cout << name##XMLSS.str();\ name##URL.setOutContent(name##XMLSS.str());\ name##URL.addOutHeader("Content-type", "application/xml");\ - name##URL.download(true);\ + name##URL.download(false);\ } using namespace uscxml; @@ -44,25 +45,34 @@ std::map<std::string, MMIEvent*> Replies; tthread::condition_variable Cond; tthread::mutex Mutex; +std::string context; + class MMIServlet : public HTTPServlet { public: bool httpRecvRequest(const HTTPServer::Request& request) { tthread::lock_guard<tthread::mutex> lock(Mutex); - NameSpacingParser parser = NameSpacingParser::fromXML(request.content); - switch(MMIEvent::getType(parser.getDocument().getDocumentElement())) { + const Arabica::DOM::Document<std::string>& doc = request.data.at("content").node.getOwnerDocument(); +// NameSpacingParser parser = NameSpacingParser::fromXML(request.content); + switch(MMIEvent::getType(doc.getDocumentElement())) { case MMIEvent::NEWCONTEXTRESPONSE: { - NewContextResponse* resp = new NewContextResponse(NewContextResponse::fromXML(parser.getDocument().getDocumentElement())); + NewContextResponse* resp = new NewContextResponse(NewContextResponse::fromXML(doc.getDocumentElement())); + context = resp->context; Replies[resp->requestId] = resp; + break; } case MMIEvent::STARTRESPONSE: { - StartResponse* resp = new StartResponse(StartResponse::fromXML(parser.getDocument().getDocumentElement())); + StartResponse* resp = new StartResponse(StartResponse::fromXML(doc.getDocumentElement())); Replies[resp->requestId] = resp; } default: ; } Cond.notify_all(); + + HTTPServer::Reply reply(request); + HTTPServer::reply(reply); + return true; } void setURL(const std::string& url) { @@ -135,7 +145,7 @@ int main(int argc, char** argv) { NewContextRequest newCtxReq; newCtxReq.source = source; newCtxReq.target = target; - newCtxReq.requestId = UUID::getUUID(); + newCtxReq.requestId = uscxml::UUID::getUUID(); Requests[newCtxReq.requestId] = &newCtxReq; ISSUE_REQUEST(newCtxReq); @@ -144,9 +154,10 @@ int main(int argc, char** argv) { Cond.wait(Mutex); StartRequest startReq; + startReq.context = context; startReq.source = source; startReq.target = target; - startReq.requestId = UUID::getUUID(); + startReq.requestId = uscxml::UUID::getUUID(); startReq.contentURL.href = document; //"https://raw.githubusercontent.com/Roland-Taizun-Azhar/TaskAssistance-Project/master/WebContent/hello.vxml"; |