UUID functions renamed to avoid conflict with Mac OS X system functions
[public/netxms.git] / include / nxconfig.h
CommitLineData
d9794cb6 1/*
8a5ba964 2** NetXMS - Network Management System
68f384ea 3** Copyright (C) 2003-2010 Victor Kirhenshtein
8a5ba964
AK
4**
5** This program is free software; you can redistribute it and/or modify
68f384ea
VK
6** it under the terms of the GNU Lesser General Public License as published
7** by the Free Software Foundation; either version 3 of the License, or
8a5ba964
AK
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
8a5ba964
AK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nxconfig.h
20**
21**/
22
23#ifndef _nxconfig_h_
24#define _nxconfig_h_
25
e6c91aac
VK
26#include <nms_common.h>
27#include <nms_util.h>
c9df9ad9 28#include <uuid.h>
e6c91aac 29
8b7ae7eb
VK
30/**
31 * Config entry
32 */
e6c91aac
VK
33class LIBNETXMS_EXPORTABLE ConfigEntry
34{
35private:
36 TCHAR *m_name;
37 ConfigEntry *m_parent;
38 ConfigEntry *m_next;
9387bc59
VK
39 ConfigEntry *m_first;
40 ConfigEntry *m_last;
e6c91aac
VK
41 int m_valueCount;
42 TCHAR **m_values;
43 TCHAR *m_file;
44 int m_line;
a65c1819 45 int m_id;
8b7ae7eb 46 StringMap m_attributes;
e6c91aac 47
9387bc59 48 void addEntry(ConfigEntry *entry);
203e9d8a 49 void linkEntry(ConfigEntry *entry) { entry->m_next = m_next; m_next = entry; }
e6c91aac
VK
50
51public:
a65c1819 52 ConfigEntry(const TCHAR *name, ConfigEntry *parent, const TCHAR *file, int line, int id);
e6c91aac
VK
53 ~ConfigEntry();
54
55 ConfigEntry *getNext() { return m_next; }
203e9d8a 56 ConfigEntry *getParent() { return m_parent; }
e6c91aac
VK
57
58 const TCHAR *getName() { return m_name; }
a65c1819 59 int getId() { return m_id; }
e6c91aac
VK
60 int getValueCount() { return m_valueCount; }
61 int getConcatenatedValuesLength();
d9794cb6 62
a65c1819 63 const TCHAR *getValue(int index = 0);
31b0f68b
VK
64 INT32 getValueAsInt(int index = 0, INT32 defaultValue = 0);
65 UINT32 getValueAsUInt(int index = 0, UINT32 defaultValue = 0);
66 INT64 getValueAsInt64(int index = 0, INT64 defaultValue = 0);
67 UINT64 getValueAsUInt64(int index = 0, UINT64 defaultValue = 0);
68 bool getValueAsBoolean(int index = 0, bool defaultValue = false);
999945fa 69 uuid getValueAsUUID(int index);
31b0f68b
VK
70
71 void addValue(const TCHAR *value);
99877e7b 72 void addValuePreallocated(TCHAR *value);
31b0f68b 73 void setValue(const TCHAR*value);
a65c1819
VK
74
75 const TCHAR *getSubEntryValue(const TCHAR *name, int index = 0, const TCHAR *defaultValue = NULL);
31b0f68b
VK
76 INT32 getSubEntryValueAsInt(const TCHAR *name, int index = 0, INT32 defaultValue = 0);
77 UINT32 getSubEntryValueAsUInt(const TCHAR *name, int index = 0, UINT32 defaultValue = 0);
78 INT64 getSubEntryValueAsInt64(const TCHAR *name, int index = 0, INT64 defaultValue = 0);
79 UINT64 getSubEntryValueAsUInt64(const TCHAR *name, int index = 0, UINT64 defaultValue = 0);
80 bool getSubEntryValueAsBoolean(const TCHAR *name, int index = 0, bool defaultValue = false);
de4af576 81 uuid getSubEntryValueAsUUID(const TCHAR *name, int index = 0);
e6c91aac 82
8b7ae7eb 83 const TCHAR *getAttribute(const TCHAR *name) { return m_attributes.get(name); }
31b0f68b
VK
84 INT32 getAttributeAsInt(const TCHAR *name, INT32 defaultValue = 0);
85 UINT32 getAttributeAsUInt(const TCHAR *name, UINT32 defaultValue = 0);
86 INT64 getAttributeAsInt64(const TCHAR *name, INT64 defaultValue = 0);
87 UINT64 getAttributeAsUInt64(const TCHAR *name, UINT64 defaultValue = 0);
88 bool getAttributeAsBoolean(const TCHAR *name, bool defaultValue = false);
89
8b7ae7eb
VK
90 void setAttribute(const TCHAR *name, const TCHAR *value) { m_attributes.set(name, value); }
91 void setAttributePreallocated(TCHAR *name, TCHAR *value) { m_attributes.setPreallocated(name, value); }
31b0f68b
VK
92 void setAttribute(const TCHAR *name, INT32 value);
93 void setAttribute(const TCHAR *name, UINT32 value);
94 void setAttribute(const TCHAR *name, INT64 value);
95 void setAttribute(const TCHAR *name, UINT64 value);
96 void setAttribute(const TCHAR *name, bool value);
8b7ae7eb 97
e6c91aac
VK
98 const TCHAR *getFile() { return m_file; }
99 int getLine() { return m_line; }
100
8a0dffac
VK
101 void setName(const TCHAR *name);
102
203e9d8a 103 ConfigEntry *createEntry(const TCHAR *name);
e6c91aac 104 ConfigEntry *findEntry(const TCHAR *name);
8b7ae7eb
VK
105 ObjectArray<ConfigEntry> *getSubEntries(const TCHAR *mask);
106 ObjectArray<ConfigEntry> *getOrderedSubEntries(const TCHAR *mask);
203e9d8a 107 void unlinkEntry(ConfigEntry *entry);
abf35d58 108
e77b1f4e 109 void print(FILE *file, int level, TCHAR *prefix);
8a0dffac 110 void createXml(String &xml, int level = 0);
e6c91aac
VK
111};
112
9387bc59
VK
113/**
114 * Hierarchical config
115 */
e6c91aac 116class LIBNETXMS_EXPORTABLE Config
8a5ba964
AK
117{
118private:
e6c91aac
VK
119 ConfigEntry *m_root;
120 int m_errorCount;
203e9d8a 121 MUTEX m_mutex;
e6c91aac
VK
122
123protected:
124 virtual void onError(const TCHAR *errorMessage);
d9794cb6 125
e6c91aac 126 void error(const TCHAR *format, ...);
8a0dffac 127 ConfigEntry *createEntry(const TCHAR *path);
8a5ba964
AK
128
129public:
130 Config();
98c0358d 131 virtual ~Config();
8a5ba964 132
c17f6cbc 133 void lock() { MutexLock(m_mutex); }
203e9d8a
VK
134 void unlock() { MutexUnlock(m_mutex); }
135
8a0dffac
VK
136 void setTopLevelTag(const TCHAR *topLevelTag) { m_root->setName(topLevelTag); }
137
a65c1819 138 bool loadXmlConfig(const TCHAR *file, const char *topLevelTag = NULL);
d9794cb6 139 bool loadXmlConfigFromMemory(const char *xml, int xmlSize, const TCHAR *name = NULL, const char *topLevelTag = NULL, bool merge = true);
31e21b08
AK
140 bool loadIniConfig(const TCHAR *file, const TCHAR *defaultIniSection, bool ignoreErrors = true);
141 bool loadConfig(const TCHAR *file, const TCHAR *defaultIniSection, bool ignoreErrors = true);
8a5ba964 142
31e21b08 143 bool loadConfigDirectory(const TCHAR *path, const TCHAR *defaultIniSection, bool ignoreErrors = true);
e6c91aac 144
203e9d8a
VK
145 void deleteEntry(const TCHAR *path);
146
e6c91aac 147 ConfigEntry *getEntry(const TCHAR *path);
ec19c32d 148 const TCHAR *getValue(const TCHAR *path, const TCHAR *defaultValue = NULL);
31b0f68b
VK
149 INT32 getValueAsInt(const TCHAR *path, INT32 defaultValue);
150 UINT32 getValueAsUInt(const TCHAR *path, UINT32 defaultValue);
151 INT64 getValueAsInt64(const TCHAR *path, INT64 defaultValue);
152 UINT64 getValueAsUInt64(const TCHAR *path, UINT64 defaultValue);
153 bool getValueAsBoolean(const TCHAR *path, bool defaultValue);
999945fa 154 uuid getValueAsUUID(const TCHAR *path);
8b7ae7eb
VK
155 ObjectArray<ConfigEntry> *getSubEntries(const TCHAR *path, const TCHAR *mask);
156 ObjectArray<ConfigEntry> *getOrderedSubEntries(const TCHAR *path, const TCHAR *mask);
e6c91aac 157
8a0dffac 158 bool setValue(const TCHAR *path, const TCHAR *value);
967893bb
VK
159 bool setValue(const TCHAR *path, INT32 value);
160 bool setValue(const TCHAR *path, UINT32 value);
8a0dffac 161 bool setValue(const TCHAR *path, INT64 value);
967893bb 162 bool setValue(const TCHAR *path, UINT64 value);
8a0dffac 163 bool setValue(const TCHAR *path, double value);
999945fa 164 bool setValue(const TCHAR *path, const uuid& value);
8a0dffac 165
97a92859 166 bool parseTemplate(const TCHAR *section, NX_CFG_TEMPLATE *cfgTemplate);
e6c91aac
VK
167
168 int getErrorCount() { return m_errorCount; }
abf35d58
VK
169
170 void print(FILE *file);
8a0dffac 171 String createXml();
8a5ba964
AK
172};
173
174
175#endif