diff options
-rw-r--r-- | src/configmanager.cpp | 82 | ||||
-rw-r--r-- | src/configmanager.h | 28 |
2 files changed, 22 insertions, 88 deletions
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 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include "xmlnode.h" | 3 | #include "xmlnode.h" |
4 | #include "xmlfilereader.h" | 4 | #include "xmlfilereader.h" |
5 | #include "configmanager.h" | 5 | #include "configmanagerbase.h" |
6 | #include "multilog.h" | ||
7 | #include "multilogtext.h" | ||
8 | #include "config.h" | ||
9 | 6 | ||
10 | #ifndef DEF_DEF_LANG | 7 | ConfigManagerBase::ConfigManager() |
11 | # error You must define a default default language in DEF_DEF_LANG | 8 | { |
12 | #endif | 9 | } |
13 | 10 | ||
14 | ConfigManager::ConfigManager() : | 11 | ConfigManagerBase::~ConfigManager() |
15 | sDefLang( DEF_DEF_LANG ) | ||
16 | { | 12 | { |
17 | } | 13 | } |
18 | 14 | ||
19 | ConfigManager::~ConfigManager() | 15 | void ConfigManagerBase::addSearchPath( const std::string &sPath ) |
20 | { | 16 | { |
17 | lSearchPath.push_back( sPath ); | ||
21 | } | 18 | } |
22 | 19 | ||
23 | void ConfigManager::loadConfig( const char *lpProfile ) | 20 | void ConfigManagerBase::loadConfig( const char *lpProfile ) |
24 | { | 21 | { |
25 | // Try a few locations... | 22 | // Try a few locations... |
26 | char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL}; | 23 | std::list<std::string>::const_iterator i; |
27 | 24 | for( i = lSearchPath.begin(); i != lSearchPath.end(); i++ ) | |
28 | for( int j = 0; locs[j] != NULL; j++ ) | ||
29 | { | 25 | { |
30 | if( parseConfig( locs[j], lpProfile ) ) | 26 | if( parseConfig( (*i).c_str(), lpProfile ) ) |
31 | { | 27 | { |
32 | break; | 28 | break; |
33 | } | 29 | } |
34 | } | 30 | } |
35 | } | 31 | } |
36 | 32 | ||
37 | bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) | 33 | bool ConfigManagerBase::parseConfig( const char *lpFileName, const char *lpProfile ) |
38 | { | 34 | { |
39 | XmlNode *pRoot, *pCur; | 35 | XmlNode *pRoot, *pCur; |
40 | XmlFileReader doc( lpFileName ); | 36 | XmlFileReader doc( lpFileName ); |
@@ -65,57 +61,3 @@ bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile ) | |||
65 | return false; | 61 | return false; |
66 | } | 62 | } |
67 | 63 | ||
68 | bool ConfigManager::processProfile( XmlNode *pBase ) | ||
69 | { | ||
70 | XmlNode *pCur; | ||
71 | |||
72 | for( int j = 0; (pCur = pBase->getChild("listen", j)); j++ ) | ||
73 | { | ||
74 | } | ||
75 | |||
76 | for( int j = 0; (pCur = pBase->getChild("log", j)); j++ ) | ||
77 | { | ||
78 | if( !strcmp( pCur->getProperty("type"), "text" ) ) | ||
79 | { | ||
80 | int nLevel = atoi( pCur->getProperty("level") ); | ||
81 | int nArchive = atoi( pCur->getProperty("archive") ); | ||
82 | |||
83 | printf("Adding log file: %s\n", pCur->getProperty("file") ); | ||
84 | |||
85 | MultiLog::getInstance().addChannel( | ||
86 | new MultiLogText( | ||
87 | pCur->getProperty("file"), | ||
88 | pCur->getProperty("format") | ||
89 | ) | ||
90 | ); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | XmlNode *pDefs; | ||
95 | if( pDefs = pBase->getChild("defaults") ) | ||
96 | { | ||
97 | if( pCur = pDefs->getChild("language") ) | ||
98 | { | ||
99 | sDefLang = pCur->getContent(); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if( pCur = pBase->getChild("backend") ) | ||
104 | { | ||
105 | sBackend = pCur->getProperty("plugin"); | ||
106 | sBackend = sBackend; | ||
107 | pBackend = pBase->getCopy(); | ||
108 | } | ||
109 | |||
110 | return true; | ||
111 | } | ||
112 | |||
113 | std::string &ConfigManager::getDefLanguage() | ||
114 | { | ||
115 | return sDefLang; | ||
116 | } | ||
117 | |||
118 | std::string &ConfigManager::getBackend() | ||
119 | { | ||
120 | return sBackend; | ||
121 | } | ||
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 @@ | |||
1 | #ifndef CONFIG_MANAGER_H | 1 | #ifndef CONFIG_MANAGER_BASE_H |
2 | #define CONFIG_MANAGER_H | 2 | #define CONFIG_MANAGER_BASE_H |
3 | 3 | ||
4 | #include "config.h" | ||
5 | #include "singleton.h" | ||
6 | #include <string> | 4 | #include <string> |
5 | #include <list> | ||
7 | 6 | ||
8 | class ConfigManager : public Singleton<ConfigManager> | 7 | class ConfigManagerBase |
9 | { | 8 | { |
10 | friend class Singleton<ConfigManager>; | 9 | public: |
11 | protected: | 10 | ConfigManagerBase(); |
12 | ConfigManager(); | 11 | ~ConfigManagerBase(); |
13 | ~ConfigManager(); | ||
14 | 12 | ||
15 | public: | 13 | public: |
14 | void addSearchPath( const std::string &sPath ); | ||
16 | void loadConfig( const char *lpProfile="default" ); | 15 | void loadConfig( const char *lpProfile="default" ); |
17 | 16 | ||
18 | private: | 17 | private: |
19 | bool parseConfig( const char *lpFileName, const char *lpProfile ); | 18 | bool parseConfig( const char *lpFileName, const char *lpProfile ); |
20 | bool processProfile( class XmlNode *pBase ); | 19 | virtual bool processProfile( class XmlNode *pBase )=0; |
21 | |||
22 | public: // Getters, these should be moved if we make this a base class... | ||
23 | std::string &getDefLanguage(); | ||
24 | std::string &getBackend(); | ||
25 | 20 | ||
26 | private: // Properties, these should be moved if we make this a base class... | 21 | std::list<std::string> lSearchPath; |
27 | std::string sDefLang; /**< The default language for all operations. */ | ||
28 | std::string sBackend; /**< The backend database plugin name. */ | ||
29 | XmlNode *pBackend; /**< The xml snippet describing the backend. */ | ||
30 | }; | 22 | }; |
31 | 23 | ||
32 | #endif | 24 | #endif |