summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenri Herscher <henri@oreka.org>2006-06-16 19:10:27 +0000
committerHenri Herscher <henri@oreka.org>2006-06-16 19:10:27 +0000
commit37e831162bd5080be5e111a39880a51d4406bcca (patch)
tree261fed75d90ebab01efa7ba668ebe3f68ae88cf4
parent5752a8ab946c82cc61b0dc73c1114293a75309f3 (diff)
Successfully moved MultiThreadedServer.cpp and MultiThreadedServer.h from orkaudio to orkbasecxx so that it is accessible by all modules/plugins.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@262 09dcff7a-b715-0410-9601-b79a96267cd0
-rw-r--r--orkaudio/MultiThreadedServer.cpp223
-rw-r--r--orkaudio/MultiThreadedServer.h53
-rw-r--r--orkaudio/OrkAudio.dsp8
-rw-r--r--orkbasecxx/MultiThreadedServer.cpp32
-rw-r--r--orkbasecxx/MultiThreadedServer.h15
-rw-r--r--orkbasecxx/OrkBase.dsp8
6 files changed, 42 insertions, 297 deletions
diff --git a/orkaudio/MultiThreadedServer.cpp b/orkaudio/MultiThreadedServer.cpp
deleted file mode 100644
index 3dcc417..0000000
--- a/orkaudio/MultiThreadedServer.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Oreka -- A media capture and retrieval platform
- *
- * Copyright (C) 2005, orecx LLC
- *
- * http://www.orecx.com
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License.
- * Please refer to http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "MultiThreadedServer.h"
-
-#include "ace/INET_Addr.h"
-#include "ace/OS_NS_string.h"
-#include "ObjectFactory.h"
-#include "serializers/SingleLineSerializer.h"
-#include "serializers/DomSerializer.h"
-#include "serializers/UrlSerializer.h"
-#include "LogManager.h"
-#include "Utils.h"
-#include <xercesc/parsers/XercesDOMParser.hpp>
-#include <xercesc/dom/DOMWriter.hpp>
-#include <xercesc/dom/DOMImplementation.hpp>
-#include <xercesc/dom/DOMImplementationRegistry.hpp>
-
-
-int CommandLineServer::open (void *void_acceptor)
-{
- return this->activate (THR_DETACHED);
-}
-
-
-void CommandLineServer::run(void* args)
-{
- unsigned short tcpPort = (unsigned short)(unsigned int)args;
- CommandLineAcceptor peer_acceptor;
- ACE_INET_Addr addr (tcpPort);
- ACE_Reactor reactor;
-
- if (peer_acceptor.open (addr, &reactor) == -1)
- {
- CStdString tcpPortString = IntToString(tcpPort);
- LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start command line server on port:") + tcpPortString);
- }
- else
- {
- for(;;)
- {
- reactor.handle_events();
- }
- }
-}
-
-int CommandLineServer::svc(void)
-{
- for (bool active = true;active == true;)
- {
- char buf[2048];
- ACE_Time_Value timeout;
- timeout.sec(3600);
- int i = 0;
-
- // Display prompt
- char prompt[] = "\r\n>";
- peer().send(prompt, 3);
-
- // Get one command line
- bool foundCRLF = false;
- while(active && !foundCRLF && i<2040)
- {
- ssize_t size = peer().recv(buf+i, 2040-i, &timeout);
-
- if (size == 0 || size == -1)
- {
- active = false;
- }
- else
- {
- for(int j=0; j<size && !foundCRLF;j++)
- {
- if(buf[i+j] == '\r' || buf[i+j] == '\n')
- {
- foundCRLF = true;
- buf[i+j] = '\0';
- CStdString command(buf);
- try
- {
- CStdString className = SingleLineSerializer::FindClass(command);
- ObjectRef objRef = ObjectFactorySingleton::instance()->NewInstance(className);
- if (objRef.get())
- {
- objRef->DeSerializeSingleLine(command);
- ObjectRef response = objRef->Process();
- CStdString responseString = response->SerializeSingleLine();
- peer().send((PCSTR)responseString, responseString.GetLength());
- }
- else
- {
- CStdString error = "Unrecognized command";
- peer().send(error, error.GetLength()); ;
- }
- }
- catch (CStdString& e)
- {
- peer().send(e, e.GetLength()); ;
- }
- }
- }
- i += size;
- }
- }
- }
- return 0;
-}
-
-
-//==============================================================
-
-int HttpServer::open (void *void_acceptor)
-{
- return this->activate (THR_DETACHED);
-}
-
-
-void HttpServer::run(void* args)
-{
- unsigned short tcpPort = (unsigned short)(unsigned int)args;
- HttpAcceptor peer_acceptor;
- ACE_INET_Addr addr (tcpPort);
- ACE_Reactor reactor;
-
- if (peer_acceptor.open (addr, &reactor) == -1)
- {
- CStdString tcpPortString = IntToString(tcpPort);
- LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start http server on port:") + tcpPortString);
- }
- else
- {
- for(;;)
- {
- reactor.handle_events();
- }
- }
-}
-
-int HttpServer::svc(void)
-{
- char buf[2048];
- buf[2047] = '\0'; // security
- ACE_Time_Value timeout;
-
- ssize_t size = peer().recv(buf, 2040);
-
- if (size > 5)
- {
- try
- {
- int startUrlOffset = 5; // get rid of "GET /" from Http request, so skip 5 chars
- char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP"); // detect location of post-URL trailing stuff
- if(!stopUrl)
- {
- throw (CStdString("Malformed http request")); ;
- }
- *stopUrl = '\0'; // Remove post-URL trailing stuff
- CStdString url(buf+startUrlOffset);
- int queryOffset = url.Find("?");
- if (queryOffset > 0)
- {
- // Strip beginning of URL in case the command is received as an URL "query" of the form:
- // http://hostname/service/command?type=ping
- url = url.Right(url.size() - queryOffset - 1);
- }
-
-
- CStdString className = UrlSerializer::FindClass(url);
- ObjectRef objRef = ObjectFactorySingleton::instance()->NewInstance(className);
- if (objRef.get())
- {
- objRef->DeSerializeUrl(url);
- ObjectRef response = objRef->Process();
-
- DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm());
- XERCES_CPP_NAMESPACE::DOMDocument* myDoc;
- myDoc = impl->createDocument(
- 0, // root element namespace URI.
- XStr("response").unicodeForm(), // root element name
- 0); // document type object (DTD).
- response->SerializeDom(myDoc);
- CStdString pingResponse = DomSerializer::DomNodeToString(myDoc);
-
- CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n");
- peer().send(httpOk, httpOk.GetLength());
- peer().send(pingResponse, pingResponse.GetLength());
- }
- else
- {
- throw (CStdString("Command not found:") + className); ;
- }
-
- }
- catch (CStdString &e)
- {
- CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n");
- error = error + e + "\r\n";
- peer().send(error, error.GetLength());
- }
- catch(const XMLException& e)
- {
- CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n");
- peer().send(error, error.GetLength());
- }
- }
- else
- {
- CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n");
- peer().send(notFound, notFound.GetLength());
- }
- return 0;
-}
-
diff --git a/orkaudio/MultiThreadedServer.h b/orkaudio/MultiThreadedServer.h
deleted file mode 100644
index 19c58bc..0000000
--- a/orkaudio/MultiThreadedServer.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Oreka -- A media capture and retrieval platform
- *
- * Copyright (C) 2005, orecx LLC
- *
- * http://www.orecx.com
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License.
- * Please refer to http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#ifndef __MULTITHREADEDSERVER_H__
-#define __MULTITHREADEDSERVER_H__
-
-#include "ace/Acceptor.h"
-#include "ace/SOCK_Acceptor.h"
-
-/** This server accepts permanent telnet like connections.
- commands are accepted in "single line" format.
- one thread per connection
-*/
-class CommandLineServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
-{
-public:
- virtual int open (void *);
- /** daemon thread */
- static void run(void *args);
- /** service routine */
- virtual int svc (void);
-};
-typedef ACE_Acceptor<CommandLineServer, ACE_SOCK_ACCEPTOR> CommandLineAcceptor;
-
-
-/** This server is a lightweight http server that extracts commands from URLs and outputs results in xml format
- one thread per connection
- Example url:
- http://localhost:23000/message=print&text=hello
-*/
-class HttpServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
-{
-public:
- virtual int open (void *);
- /** daemon thread */
- static void run(void *args);
- /** service routine */
- virtual int svc (void);
-};
-typedef ACE_Acceptor<HttpServer, ACE_SOCK_ACCEPTOR> HttpAcceptor;
-
-#endif
-
diff --git a/orkaudio/OrkAudio.dsp b/orkaudio/OrkAudio.dsp
index 8e21d3f..c78995f 100644
--- a/orkaudio/OrkAudio.dsp
+++ b/orkaudio/OrkAudio.dsp
@@ -247,14 +247,6 @@ SOURCE=.\LogManager.h
# End Source File
# Begin Source File
-SOURCE=.\MultiThreadedServer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\MultiThreadedServer.h
-# End Source File
-# Begin Source File
-
SOURCE=.\OrkAudio.cpp
# End Source File
# Begin Source File
diff --git a/orkbasecxx/MultiThreadedServer.cpp b/orkbasecxx/MultiThreadedServer.cpp
index 3dcc417..1d3a8bf 100644
--- a/orkbasecxx/MultiThreadedServer.cpp
+++ b/orkbasecxx/MultiThreadedServer.cpp
@@ -11,30 +11,35 @@
*
*/
-#include "MultiThreadedServer.h"
-
#include "ace/INET_Addr.h"
#include "ace/OS_NS_string.h"
+#include <xercesc/parsers/XercesDOMParser.hpp>
+#include <xercesc/dom/DOMWriter.hpp>
+#include <xercesc/dom/DOMImplementation.hpp>
+#include <xercesc/dom/DOMImplementationRegistry.hpp>
+
#include "ObjectFactory.h"
#include "serializers/SingleLineSerializer.h"
#include "serializers/DomSerializer.h"
#include "serializers/UrlSerializer.h"
-#include "LogManager.h"
#include "Utils.h"
-#include <xercesc/parsers/XercesDOMParser.hpp>
-#include <xercesc/dom/DOMWriter.hpp>
-#include <xercesc/dom/DOMImplementation.hpp>
-#include <xercesc/dom/DOMImplementationRegistry.hpp>
+#include "MultiThreadedServer.h"
+log4cxx::LoggerPtr CommandLineServer::s_log;
+
+// This is run at the start of each connection
int CommandLineServer::open (void *void_acceptor)
{
+ LOG4CXX_INFO(s_log, "new connection");
return this->activate (THR_DETACHED);
}
-
+// This is run at program initialization
void CommandLineServer::run(void* args)
{
+ s_log = log4cxx::Logger::getLogger("interface.commandlineserver");
+
unsigned short tcpPort = (unsigned short)(unsigned int)args;
CommandLineAcceptor peer_acceptor;
ACE_INET_Addr addr (tcpPort);
@@ -43,7 +48,7 @@ void CommandLineServer::run(void* args)
if (peer_acceptor.open (addr, &reactor) == -1)
{
CStdString tcpPortString = IntToString(tcpPort);
- LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start command line server on port:") + tcpPortString);
+ LOG4CXX_ERROR(s_log, CStdString("Failed to start command line server on port:") + tcpPortString);
}
else
{
@@ -119,14 +124,19 @@ int CommandLineServer::svc(void)
//==============================================================
+log4cxx::LoggerPtr HttpServer::s_log;
+
+// This is run at the start of each connection
int HttpServer::open (void *void_acceptor)
{
return this->activate (THR_DETACHED);
}
-
+// This is run at program initialization
void HttpServer::run(void* args)
{
+ s_log = log4cxx::Logger::getLogger("interface.httpserver");
+
unsigned short tcpPort = (unsigned short)(unsigned int)args;
HttpAcceptor peer_acceptor;
ACE_INET_Addr addr (tcpPort);
@@ -135,7 +145,7 @@ void HttpServer::run(void* args)
if (peer_acceptor.open (addr, &reactor) == -1)
{
CStdString tcpPortString = IntToString(tcpPort);
- LOG4CXX_ERROR(LOG.rootLog, CStdString("Failed to start http server on port:") + tcpPortString);
+ LOG4CXX_ERROR(s_log, CStdString("Failed to start http server on port:") + tcpPortString);
}
else
{
diff --git a/orkbasecxx/MultiThreadedServer.h b/orkbasecxx/MultiThreadedServer.h
index 19c58bc..b004007 100644
--- a/orkbasecxx/MultiThreadedServer.h
+++ b/orkbasecxx/MultiThreadedServer.h
@@ -17,11 +17,15 @@
#include "ace/Acceptor.h"
#include "ace/SOCK_Acceptor.h"
+#include <log4cxx/logger.h>
+
+#include "OrkBase.h"
+
/** This server accepts permanent telnet like connections.
commands are accepted in "single line" format.
one thread per connection
*/
-class CommandLineServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
+class DLL_IMPORT_EXPORT CommandLineServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
virtual int open (void *);
@@ -29,6 +33,9 @@ public:
static void run(void *args);
/** service routine */
virtual int svc (void);
+
+private:
+ static log4cxx::LoggerPtr s_log;
};
typedef ACE_Acceptor<CommandLineServer, ACE_SOCK_ACCEPTOR> CommandLineAcceptor;
@@ -38,7 +45,7 @@ typedef ACE_Acceptor<CommandLineServer, ACE_SOCK_ACCEPTOR> CommandLineAcceptor;
Example url:
http://localhost:23000/message=print&text=hello
*/
-class HttpServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
+class DLL_IMPORT_EXPORT HttpServer : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
virtual int open (void *);
@@ -46,6 +53,10 @@ public:
static void run(void *args);
/** service routine */
virtual int svc (void);
+
+private:
+ static log4cxx::LoggerPtr s_log;
+
};
typedef ACE_Acceptor<HttpServer, ACE_SOCK_ACCEPTOR> HttpAcceptor;
diff --git a/orkbasecxx/OrkBase.dsp b/orkbasecxx/OrkBase.dsp
index 68f2b4a..79a3091 100644
--- a/orkbasecxx/OrkBase.dsp
+++ b/orkbasecxx/OrkBase.dsp
@@ -260,6 +260,14 @@ SOURCE=.\g711.h
# End Source File
# Begin Source File
+SOURCE=.\MultiThreadedServer.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\MultiThreadedServer.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Object.cpp
!IF "$(CFG)" == "OrkBase - Win32 Release"