From abf1495c5e6e33a93a0277ef301643e7ff2ab4dd Mon Sep 17 00:00:00 2001 From: Gerald Begumisa Date: Thu, 19 Jul 2007 09:34:07 +0000 Subject: Multiple orkaudio instances may be ran on one server by setting the environment variables ORKAUDIO_CONFIG_PATH and ORKAUDIO_LOGGING_PATH to point to the location of the configuration files and log files respectively. Two variables in config.xml and have been added which specify the ports for the command line server and HTTP server respectively - these default to 59130 and 59140 respectively, note that previously the default ports were 10000 and 20000 respectively. git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@455 09dcff7a-b715-0410-9601-b79a96267cd0 --- orkbasecxx/Config.cpp | 27 ++++++++++++++++- orkbasecxx/Config.h | 6 ++++ orkbasecxx/ConfigManager.cpp | 59 +++++++++++++++++++++++++++++--------- orkbasecxx/LogManager.cpp | 53 ++++++++++++++++++++++++++-------- orkbasecxx/MultiThreadedServer.cpp | 10 +++++-- 5 files changed, 127 insertions(+), 28 deletions(-) diff --git a/orkbasecxx/Config.cpp b/orkbasecxx/Config.cpp index e93a762..334864f 100644 --- a/orkbasecxx/Config.cpp +++ b/orkbasecxx/Config.cpp @@ -14,6 +14,7 @@ #define _WINSOCKAPI_ // prevents the inclusion of winsock.h #include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_dirent.h" #include "Utils.h" #include "serializers/Serializer.h" #include "Config.h" @@ -58,6 +59,9 @@ Config::Config() m_remoteProcessingHostname = REMOTE_PROCESSING_HOSTNAME_DEFAULT; m_remoteProcessingTcpPort = REMOTE_PROCESSING_TCP_PORT_DEFAULT; m_remoteProcessingServiceName = REMOTE_PROCESSING_SERVICE_NAME_DEFAULT; + + m_commandLineServerPort = COMMAND_LINE_SERVER_PORT_DEFAULT; + m_httpServerPort = HTTP_SERVER_PORT_DEFAULT; } void Config::Define(Serializer* s) @@ -84,7 +88,26 @@ void Config::Define(Serializer* s) s->StringValue(SERVICE_NAME_PARAM, m_serviceName); s->IntValue(REPORTING_RETRY_DELAY_PARAM, m_reportingRetryDelay); s->IntValue(CLIENT_TIMEOUT_PARAM, m_clientTimeout); - s->StringValue(AUDIO_OUTPUT_PATH_PARAM, m_audioOutputPath); + + /* As per Ticket 174, with reference to + * http://wush.net/trac/grinob/wiki/MultipleOrkaudioPerServer + */ + char *loggingPath = NULL; + int pathSet = 0; + + loggingPath = ACE_OS::getenv("ORKAUDIO_LOGGING_PATH"); + if(loggingPath) { + ACE_DIR* dir = ACE_OS::opendir(loggingPath); + if(dir) { + ACE_OS::closedir(dir); + m_audioOutputPath.Format("%s", loggingPath); + pathSet = 1; + } + } + + if(!pathSet) + s->StringValue(AUDIO_OUTPUT_PATH_PARAM, m_audioOutputPath); + s->IntValue(IMMEDIATE_PROCESSING_QUEUE_SIZE_PARAM, m_immediateProcessingQueueSize); s->IntValue(BATCH_PROCESSING_QUEUE_SIZE_PARAM, m_batchProcessingQueueSize); s->BoolValue(BATCH_PROCESSING_ENHANCE_PRIORITY_PARAM, m_batchProcessingEnhancePriority); @@ -100,6 +123,8 @@ void Config::Define(Serializer* s) s->StringValue(REMOTE_PROCESSING_HOSTNAME_PARAM, m_remoteProcessingHostname); s->IntValue(REMOTE_PROCESSING_TCP_PORT_PARAM, m_remoteProcessingTcpPort); s->StringValue(REMOTE_PROCESSING_SERVICE_NAME_PARAM, m_remoteProcessingServiceName); + s->IntValue(COMMAND_LINE_SERVER_PORT_PARAM, m_commandLineServerPort); + s->IntValue(HTTP_SERVER_PORT_PARAM, m_httpServerPort); } void Config::Validate() diff --git a/orkbasecxx/Config.h b/orkbasecxx/Config.h index 50271c9..1e0ac8b 100644 --- a/orkbasecxx/Config.h +++ b/orkbasecxx/Config.h @@ -86,6 +86,10 @@ #define REMOTE_PROCESSING_TCP_PORT_DEFAULT 20000 #define REMOTE_PROCESSING_SERVICE_NAME_PARAM "RemoteProcessingServiceName" #define REMOTE_PROCESSING_SERVICE_NAME_DEFAULT "orkaudio" +#define COMMAND_LINE_SERVER_PORT_PARAM "CommandLineServerPort" +#define COMMAND_LINE_SERVER_PORT_DEFAULT 59130 +#define HTTP_SERVER_PORT_PARAM "HttpServerPort" +#define HTTP_SERVER_PORT_DEFAULT 59140 class DLL_IMPORT_EXPORT_ORKBASE Config : public Object { @@ -136,6 +140,8 @@ public: CStdString m_remoteProcessingHostname; int m_remoteProcessingTcpPort; CStdString m_remoteProcessingServiceName; + int m_commandLineServerPort; + int m_httpServerPort; private: log4cxx::LoggerPtr m_log; diff --git a/orkbasecxx/ConfigManager.cpp b/orkbasecxx/ConfigManager.cpp index 6d16bcb..adba47d 100644 --- a/orkbasecxx/ConfigManager.cpp +++ b/orkbasecxx/ConfigManager.cpp @@ -14,6 +14,7 @@ #define _WINSOCKAPI_ // prevents the inclusion of winsock.h +#include "ace/OS_NS_dirent.h" #include "Utils.h" #include #include @@ -25,6 +26,10 @@ #define CONFIG_FILE_NAME "config.xml" #define ETC_CONFIG_FILE_NAME "/etc/orkaudio/config.xml" +#ifdef WIN32 +# define snprintf _snprintf +#endif + ConfigManager ConfigManager::m_singleton; ConfigManager* ConfigManager::Instance() @@ -37,23 +42,46 @@ void ConfigManager::Initialize() bool failed = false; m_configTopNode = NULL; - try - { + try + { char* cfgFilename = ""; - FILE* file = ACE_OS::fopen(CONFIG_FILE_NAME, "r"); - if(file) - { - // config.xml exists in the current directory - cfgFilename = CONFIG_FILE_NAME; - fclose(file); + char* cfgEnvPath = ""; + int cfgAlloc = 0; + + cfgEnvPath = ACE_OS::getenv("ORKAUDIO_CONFIG_PATH"); + if(cfgEnvPath) { + ACE_DIR* dir = ACE_OS::opendir(cfgEnvPath); + if(dir) { + int len = 0; + + ACE_OS::closedir(dir); + len = strlen(cfgEnvPath)+1+strlen(CONFIG_FILE_NAME)+1; + cfgFilename = (char*)malloc(len); + + if(cfgFilename) { + cfgAlloc = 1; + snprintf(cfgFilename, len, "%s/%s", cfgEnvPath, CONFIG_FILE_NAME); + } + } } - else - { - // config.xml could not be found in the current directory, try to find it in system configuration directory - cfgFilename = ETC_CONFIG_FILE_NAME; + + if(!cfgFilename || !strlen(cfgFilename)) { + FILE* file = ACE_OS::fopen(CONFIG_FILE_NAME, "r"); + if(file) + { + // config.xml exists in the current directory + cfgFilename = CONFIG_FILE_NAME; + fclose(file); + } + else + { + // config.xml could not be found in the current + // directory, try to find it in system configuration directory + cfgFilename = ETC_CONFIG_FILE_NAME; + } } - XMLPlatformUtils::Initialize(); + XMLPlatformUtils::Initialize(); // By default, the DOM document generated by the parser will be free() by the parser. // If we ever need to free the parser and the document separately, we need to do this: @@ -68,6 +96,11 @@ void ConfigManager::Initialize() DOMNode *doc = NULL; doc = m_parser->getDocument(); + // XXX is it okay to free here? + if(cfgAlloc) { + free(cfgFilename); + } + if (doc) { DOMNode *firstChild = doc->getFirstChild(); diff --git a/orkbasecxx/LogManager.cpp b/orkbasecxx/LogManager.cpp index 2162ef9..5d83985 100644 --- a/orkbasecxx/LogManager.cpp +++ b/orkbasecxx/LogManager.cpp @@ -13,6 +13,7 @@ #define _WINSOCKAPI_ // prevents the inclusion of winsock.h +#include "ace/OS_NS_dirent.h" #include "LogManager.h" #include #include @@ -29,23 +30,51 @@ void OrkLogManager::Initialize() { BasicConfigurator::configure(); - char* logCfgFilename = ""; - FILE* file = ACE_OS::fopen("logging.properties", "r"); - if(file) - { - // logging.properties exists in the current directory - logCfgFilename = "logging.properties"; - fclose(file); - } - else - { - // logging.properties could not be found in the current directory, try to find it in system configuration directory - logCfgFilename = "/etc/orkaudio/logging.properties"; + char* logCfgFilename = ""; + char* cfgEnvPath = ""; + int cfgAlloc = 0; + + cfgEnvPath = ACE_OS::getenv("ORKAUDIO_CONFIG_PATH"); + if(cfgEnvPath) { + ACE_DIR* dir = ACE_OS::opendir(cfgEnvPath); + if(dir) { + int len = 0; + + ACE_OS::closedir(dir); + len = strlen(cfgEnvPath)+1+strlen("logging.properties")+1; + logCfgFilename = (char*)malloc(len); + + if(logCfgFilename) { + cfgAlloc = 1; + snprintf(logCfgFilename, len, "%s/%s", cfgEnvPath, "logging.properties"); + } + } + } + + if(!logCfgFilename || !strlen(logCfgFilename)) { + FILE* file = ACE_OS::fopen("logging.properties", "r"); + if(file) + { + // logging.properties exists in the current directory + logCfgFilename = "logging.properties"; + fclose(file); + } + else + { + // logging.properties could not be found in the current + // directory, try to find it in system configuration directory + logCfgFilename = "/etc/orkaudio/logging.properties"; + } } // If this one fails, the above default configuration stays valid PropertyConfigurator::configure(logCfgFilename); + // XXX should we free this here? + if(cfgAlloc) { + free(logCfgFilename); + } + rootLog = Logger::getLogger("root"); topLog = Logger::getLogger("top"); immediateProcessingLog = Logger::getLogger("immediateProcessing"); diff --git a/orkbasecxx/MultiThreadedServer.cpp b/orkbasecxx/MultiThreadedServer.cpp index 7cbf4db..cec42db 100644 --- a/orkbasecxx/MultiThreadedServer.cpp +++ b/orkbasecxx/MultiThreadedServer.cpp @@ -41,17 +41,20 @@ void CommandLineServer::run(void* args) s_log = log4cxx::Logger::getLogger("interface.commandlineserver"); unsigned short tcpPort = (unsigned short)(unsigned long)args; + //unsigned short tcpPort = (unsigned short)*(int*)args; + CommandLineAcceptor peer_acceptor; ACE_INET_Addr addr (tcpPort); ACE_Reactor reactor; + CStdString tcpPortString = IntToString(tcpPort); if (peer_acceptor.open (addr, &reactor) == -1) { - CStdString tcpPortString = IntToString(tcpPort); LOG4CXX_ERROR(s_log, CStdString("Failed to start command line server on port:") + tcpPortString); } else { + LOG4CXX_INFO(s_log, CStdString("Started command line server on port:")+tcpPortString); for(;;) { reactor.handle_events(); @@ -138,17 +141,20 @@ void HttpServer::run(void* args) s_log = log4cxx::Logger::getLogger("interface.httpserver"); unsigned short tcpPort = (unsigned short)(unsigned long)args; + //unsigned short tcpPort = (unsigned short)*(int*)args; + HttpAcceptor peer_acceptor; ACE_INET_Addr addr (tcpPort); ACE_Reactor reactor; + CStdString tcpPortString = IntToString(tcpPort); if (peer_acceptor.open (addr, &reactor) == -1) { - CStdString tcpPortString = IntToString(tcpPort); LOG4CXX_ERROR(s_log, CStdString("Failed to start http server on port:") + tcpPortString); } else { + LOG4CXX_INFO(s_log, CStdString("Started HTTP server on port:")+tcpPortString); for(;;) { reactor.handle_events(); -- cgit v1.2.3