From 97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 9 Aug 2006 06:08:59 +0000 Subject: The start of the configmanager to libbu++, they are good, but make congo not build now, for a while, and don't actually work yet, so just don't use this revision of libbu++. --- src/configmanager.cpp | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/configmanager.h | 32 +++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/configmanager.cpp create mode 100644 src/configmanager.h (limited to 'src') diff --git a/src/configmanager.cpp b/src/configmanager.cpp new file mode 100644 index 0000000..c3ad695 --- /dev/null +++ b/src/configmanager.cpp @@ -0,0 +1,121 @@ +#include +#include +#include "xmlnode.h" +#include "xmlfilereader.h" +#include "configmanager.h" +#include "multilog.h" +#include "multilogtext.h" +#include "config.h" + +#ifndef DEF_DEF_LANG +# error You must define a default default language in DEF_DEF_LANG +#endif + +ConfigManager::ConfigManager() : + sDefLang( DEF_DEF_LANG ) +{ +} + +ConfigManager::~ConfigManager() +{ +} + +void ConfigManager::loadConfig( const char *lpProfile ) +{ + // Try a few locations... + char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL}; + + for( int j = 0; locs[j] != NULL; j++ ) + { + if( parseConfig( locs[j], lpProfile ) ) + { + break; + } + } +} + +bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) +{ + XmlNode *pRoot, *pCur; + XmlFileReader doc( lpFileName ); + + pRoot = doc.getRoot(); + if( pRoot == NULL ) + { + return false; + } + + if( strcmp("config", pRoot->getName() ) ) + { + return false; + } + + for( int j = 0;; j++ ) + { + pCur = pRoot->getChild( "profile", j ); + if( pCur == NULL ) + return false; + + if( !strcmp( pCur->getProperty("id"), lpProfile ) ) + { + return processProfile( pCur ); + } + } + + 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 new file mode 100644 index 0000000..d5ecd7d --- /dev/null +++ b/src/configmanager.h @@ -0,0 +1,32 @@ +#ifndef CONFIG_MANAGER_H +#define CONFIG_MANAGER_H + +#include "config.h" +#include "singleton.h" +#include + +class ConfigManager : public Singleton +{ + friend class Singleton; +protected: + ConfigManager(); + ~ConfigManager(); + +public: + 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(); + +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. */ +}; + +#endif -- cgit v1.2.3