From 3b036371ae3edebb53fd878ddc8c916e78ee1279 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 9 Aug 2006 07:49:38 +0000 Subject: This may work, now the filenames just need to be changed. --- src/configmanager.cpp | 82 ++++++++------------------------------------------- src/configmanager.h | 28 +++++++----------- 2 files changed, 22 insertions(+), 88 deletions(-) (limited to 'src') diff --git a/src/configmanager.cpp b/src/configmanager.cpp index c3ad695..6c239f8 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -2,39 +2,35 @@ #include #include "xmlnode.h" #include "xmlfilereader.h" -#include "configmanager.h" -#include "multilog.h" -#include "multilogtext.h" -#include "config.h" +#include "configmanagerbase.h" -#ifndef DEF_DEF_LANG -# error You must define a default default language in DEF_DEF_LANG -#endif +ConfigManagerBase::ConfigManager() +{ +} -ConfigManager::ConfigManager() : - sDefLang( DEF_DEF_LANG ) +ConfigManagerBase::~ConfigManager() { } -ConfigManager::~ConfigManager() +void ConfigManagerBase::addSearchPath( const std::string &sPath ) { + lSearchPath.push_back( sPath ); } -void ConfigManager::loadConfig( const char *lpProfile ) +void ConfigManagerBase::loadConfig( const char *lpProfile ) { // Try a few locations... - char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL}; - - for( int j = 0; locs[j] != NULL; j++ ) + std::list::const_iterator i; + for( i = lSearchPath.begin(); i != lSearchPath.end(); i++ ) { - if( parseConfig( locs[j], lpProfile ) ) + if( parseConfig( (*i).c_str(), lpProfile ) ) { break; } } } -bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) +bool ConfigManagerBase::parseConfig( const char *lpFileName, const char *lpProfile ) { XmlNode *pRoot, *pCur; XmlFileReader doc( lpFileName ); @@ -65,57 +61,3 @@ bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) return false; } -bool ConfigManager::processProfile( XmlNode *pBase ) -{ - XmlNode *pCur; - - for( int j = 0; (pCur = pBase->getChild("listen", j)); j++ ) - { - } - - for( int j = 0; (pCur = pBase->getChild("log", j)); j++ ) - { - if( !strcmp( pCur->getProperty("type"), "text" ) ) - { - int nLevel = atoi( pCur->getProperty("level") ); - int nArchive = atoi( pCur->getProperty("archive") ); - - printf("Adding log file: %s\n", pCur->getProperty("file") ); - - MultiLog::getInstance().addChannel( - new MultiLogText( - pCur->getProperty("file"), - pCur->getProperty("format") - ) - ); - } - } - - XmlNode *pDefs; - if( pDefs = pBase->getChild("defaults") ) - { - if( pCur = pDefs->getChild("language") ) - { - sDefLang = pCur->getContent(); - } - } - - if( pCur = pBase->getChild("backend") ) - { - sBackend = pCur->getProperty("plugin"); - sBackend = sBackend; - pBackend = pBase->getCopy(); - } - - return true; -} - -std::string &ConfigManager::getDefLanguage() -{ - return sDefLang; -} - -std::string &ConfigManager::getBackend() -{ - return sBackend; -} diff --git a/src/configmanager.h b/src/configmanager.h index d5ecd7d..b60c73a 100644 --- a/src/configmanager.h +++ b/src/configmanager.h @@ -1,32 +1,24 @@ -#ifndef CONFIG_MANAGER_H -#define CONFIG_MANAGER_H +#ifndef CONFIG_MANAGER_BASE_H +#define CONFIG_MANAGER_BASE_H -#include "config.h" -#include "singleton.h" #include +#include -class ConfigManager : public Singleton +class ConfigManagerBase { - friend class Singleton; -protected: - ConfigManager(); - ~ConfigManager(); +public: + ConfigManagerBase(); + ~ConfigManagerBase(); public: + void addSearchPath( const std::string &sPath ); void loadConfig( const char *lpProfile="default" ); private: bool parseConfig( const char *lpFileName, const char *lpProfile ); - bool processProfile( class XmlNode *pBase ); - -public: // Getters, these should be moved if we make this a base class... - std::string &getDefLanguage(); - std::string &getBackend(); + virtual bool processProfile( class XmlNode *pBase )=0; -private: // Properties, these should be moved if we make this a base class... - std::string sDefLang; /**< The default language for all operations. */ - std::string sBackend; /**< The backend database plugin name. */ - XmlNode *pBackend; /**< The xml snippet describing the backend. */ + std::list lSearchPath; }; #endif -- cgit v1.2.3