diff options
author | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-07-19 09:34:07 +0000 |
---|---|---|
committer | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-07-19 09:34:07 +0000 |
commit | abf1495c5e6e33a93a0277ef301643e7ff2ab4dd (patch) | |
tree | dc8a36564f3760f36060b5a1c0c9a6f07ef444fc /orkbasecxx/ConfigManager.cpp | |
parent | a78ef547ae120f95a2569c9643cd60992ba547c7 (diff) |
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 <CommandLineServerPort> and <HttpServerPort> 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
Diffstat (limited to 'orkbasecxx/ConfigManager.cpp')
-rw-r--r-- | orkbasecxx/ConfigManager.cpp | 59 |
1 files changed, 46 insertions, 13 deletions
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 <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/dom/DOMWriter.hpp> @@ -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(); |