summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2006-08-09 06:08:59 +0000
committerMike Buland <eichlan@xagasoft.com>2006-08-09 06:08:59 +0000
commit97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a (patch)
treeff5880313318001005eb27a1904e4331c1d81f06
parent62bee6bf7f2be96c331cdb334d5a00067a67591e (diff)
downloadlibbu++-97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a.tar.gz
libbu++-97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a.tar.bz2
libbu++-97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a.tar.xz
libbu++-97e6e0c3bce47da037ce4bbaeb977120f0ce6f5a.zip
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++.
Diffstat (limited to '')
-rw-r--r--src/configmanager.cpp121
-rw-r--r--src/configmanager.h32
2 files changed, 153 insertions, 0 deletions
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 @@
1#include <stdlib.h>
2#include <string.h>
3#include "xmlnode.h"
4#include "xmlfilereader.h"
5#include "configmanager.h"
6#include "multilog.h"
7#include "multilogtext.h"
8#include "config.h"
9
10#ifndef DEF_DEF_LANG
11# error You must define a default default language in DEF_DEF_LANG
12#endif
13
14ConfigManager::ConfigManager() :
15 sDefLang( DEF_DEF_LANG )
16{
17}
18
19ConfigManager::~ConfigManager()
20{
21}
22
23void ConfigManager::loadConfig( const char *lpProfile )
24{
25 // Try a few locations...
26 char *locs[] = {"./" CONFIGNAME, SYSCONFIG, NULL};
27
28 for( int j = 0; locs[j] != NULL; j++ )
29 {
30 if( parseConfig( locs[j], lpProfile ) )
31 {
32 break;
33 }
34 }
35}
36
37bool ConfigManager::parseConfig( const char *lpFileName, const char *lpProfile )
38{
39 XmlNode *pRoot, *pCur;
40 XmlFileReader doc( lpFileName );
41
42 pRoot = doc.getRoot();
43 if( pRoot == NULL )
44 {
45 return false;
46 }
47
48 if( strcmp("config", pRoot->getName() ) )
49 {
50 return false;
51 }
52
53 for( int j = 0;; j++ )
54 {
55 pCur = pRoot->getChild( "profile", j );
56 if( pCur == NULL )
57 return false;
58
59 if( !strcmp( pCur->getProperty("id"), lpProfile ) )
60 {
61 return processProfile( pCur );
62 }
63 }
64
65 return false;
66}
67
68bool 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
113std::string &ConfigManager::getDefLanguage()
114{
115 return sDefLang;
116}
117
118std::string &ConfigManager::getBackend()
119{
120 return sBackend;
121}
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 @@
1#ifndef CONFIG_MANAGER_H
2#define CONFIG_MANAGER_H
3
4#include "config.h"
5#include "singleton.h"
6#include <string>
7
8class ConfigManager : public Singleton<ConfigManager>
9{
10 friend class Singleton<ConfigManager>;
11protected:
12 ConfigManager();
13 ~ConfigManager();
14
15public:
16 void loadConfig( const char *lpProfile="default" );
17
18private:
19 bool parseConfig( const char *lpFileName, const char *lpProfile );
20 bool processProfile( class XmlNode *pBase );
21
22public: // Getters, these should be moved if we make this a base class...
23 std::string &getDefLanguage();
24 std::string &getBackend();
25
26private: // Properties, these should be moved if we make this a base class...
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};
31
32#endif