summaryrefslogtreecommitdiffstats
path: root/src/uscxml/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/server')
-rw-r--r--src/uscxml/server/HTTPServer.cpp42
-rw-r--r--src/uscxml/server/HTTPServer.h6
-rw-r--r--src/uscxml/server/InterpreterServlet.cpp8
-rw-r--r--src/uscxml/server/InterpreterServlet.h4
4 files changed, 40 insertions, 20 deletions
diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp
index e5c83d7..9efdc07 100644
--- a/src/uscxml/server/HTTPServer.cpp
+++ b/src/uscxml/server/HTTPServer.cpp
@@ -596,6 +596,20 @@ bool HTTPServer::registerServlet(const std::string& path, HTTPServlet* servlet)
return true;
}
+void HTTPServer::unregisterServlet(HTTPServlet* servlet) {
+ HTTPServer* INSTANCE = getInstance();
+ tthread::lock_guard<tthread::recursive_mutex> lock(INSTANCE->_mutex);
+ http_servlet_iter_t servletIter = INSTANCE->_httpServlets.begin();
+ while(servletIter != INSTANCE->_httpServlets.end()) {
+ if (servletIter->second == servlet) {
+ evhttp_del_cb(INSTANCE->_http, std::string("/" + servletIter->first).c_str());
+ INSTANCE->_httpServlets.erase(servletIter);
+ break;
+ }
+ servletIter++;
+ }
+}
+
bool HTTPServer::registerServlet(const std::string& path, WebSocketServlet* servlet) {
HTTPServer* INSTANCE = getInstance();
@@ -636,6 +650,20 @@ bool HTTPServer::registerServlet(const std::string& path, WebSocketServlet* serv
return true;
}
+void HTTPServer::unregisterServlet(WebSocketServlet* servlet) {
+ HTTPServer* INSTANCE = getInstance();
+ tthread::lock_guard<tthread::recursive_mutex> lock(INSTANCE->_mutex);
+ ws_servlet_iter_t servletIter = INSTANCE->_wsServlets.begin();
+ while(servletIter != INSTANCE->_wsServlets.end()) {
+ if (servletIter->second == servlet) {
+ evhttp_del_cb(INSTANCE->_http, std::string("/" + servletIter->first).c_str());
+ INSTANCE->_wsServlets.erase(servletIter);
+ break;
+ }
+ servletIter++;
+ }
+}
+
std::string HTTPServer::getBaseURL(ServerType type) {
HTTPServer* INSTANCE = getInstance();
std::stringstream servletURL;
@@ -658,20 +686,6 @@ std::string HTTPServer::getBaseURL(ServerType type) {
return servletURL.str();
}
-void HTTPServer::unregisterServlet(HTTPServlet* servlet) {
- HTTPServer* INSTANCE = getInstance();
- tthread::lock_guard<tthread::recursive_mutex> lock(INSTANCE->_mutex);
- http_servlet_iter_t servletIter = INSTANCE->_httpServlets.begin();
- while(servletIter != INSTANCE->_httpServlets.end()) {
- if (servletIter->second == servlet) {
- evhttp_del_cb(INSTANCE->_http, std::string("/" + servletIter->first).c_str());
- INSTANCE->_httpServlets.erase(servletIter);
- break;
- }
- servletIter++;
- }
-}
-
void HTTPServer::start() {
_isRunning = true;
_thread = new tthread::thread(HTTPServer::run, this);
diff --git a/src/uscxml/server/HTTPServer.h b/src/uscxml/server/HTTPServer.h
index 09a31df..398bb12 100644
--- a/src/uscxml/server/HTTPServer.h
+++ b/src/uscxml/server/HTTPServer.h
@@ -85,9 +85,9 @@ public:
};
enum ServerType {
- HTTPS,
- HTTP,
- WebSockets
+ HTTPS,
+ HTTP,
+ WebSockets
};
static HTTPServer* getInstance(unsigned short port, unsigned short wsPort, SSLConfig* sslConf = NULL);
diff --git a/src/uscxml/server/InterpreterServlet.cpp b/src/uscxml/server/InterpreterServlet.cpp
index 2bbb856..3c5c3a0 100644
--- a/src/uscxml/server/InterpreterServlet.cpp
+++ b/src/uscxml/server/InterpreterServlet.cpp
@@ -23,6 +23,10 @@
namespace uscxml {
+InterpreterHTTPServlet::~InterpreterHTTPServlet() {
+ HTTPServer::unregisterServlet(this);
+}
+
InterpreterHTTPServlet::InterpreterHTTPServlet(InterpreterImpl* interpreter) {
_interpreter = interpreter;
@@ -85,7 +89,9 @@ void InterpreterHTTPServlet::send(const SendRequest& req) {
LOG(ERROR) << "send not supported by http iorprocessor, use the fetch element";
}
-
+InterpreterWebSocketServlet::~InterpreterWebSocketServlet() {
+ HTTPServer::unregisterServlet(this);
+}
InterpreterWebSocketServlet::InterpreterWebSocketServlet(InterpreterImpl* interpreter) {
_interpreter = interpreter;
diff --git a/src/uscxml/server/InterpreterServlet.h b/src/uscxml/server/InterpreterServlet.h
index 9ff1d34..960ff8f 100644
--- a/src/uscxml/server/InterpreterServlet.h
+++ b/src/uscxml/server/InterpreterServlet.h
@@ -31,7 +31,7 @@ class InterpreterHTTPServlet : public HTTPServlet, public IOProcessorImpl {
public:
InterpreterHTTPServlet() {};
InterpreterHTTPServlet(InterpreterImpl* interpreter);
- virtual ~InterpreterHTTPServlet() {}
+ virtual ~InterpreterHTTPServlet();
virtual boost::shared_ptr<IOProcessorImpl> create(InterpreterImpl* interpreter);
@@ -82,7 +82,7 @@ class InterpreterWebSocketServlet : public WebSocketServlet, public IOProcessorI
public:
InterpreterWebSocketServlet() {};
InterpreterWebSocketServlet(InterpreterImpl* interpreter);
- virtual ~InterpreterWebSocketServlet() {}
+ virtual ~InterpreterWebSocketServlet();
virtual boost::shared_ptr<IOProcessorImpl> create(InterpreterImpl* interpreter);