summaryrefslogtreecommitdiff
path: root/orkbasecxx/ConfigManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'orkbasecxx/ConfigManager.cpp')
-rw-r--r--orkbasecxx/ConfigManager.cpp59
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();