1 karl 1.14 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.14 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.2 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.9 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.9 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
|
24 kumpf 1.9 //==============================================================================
|
25 mike 1.2 //
26 // Author: Nag Boranna (nagaraja_boranna@hp.com)
27 //
|
28 kumpf 1.3 // Modified By: Sushma Fernandes, Hewlett-Packard Company
29 // (sushma_fernandes@hp.com)
|
30 kumpf 1.4 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
31 mike 1.2 //
32 //%////////////////////////////////////////////////////////////////////////////
33
34
35 ///////////////////////////////////////////////////////////////////////////////
36 //
37 // This file defines the classes necessary to manage configuration properties
38 // specified on the commandline and configuration files for Pegasus.
39 //
40 ///////////////////////////////////////////////////////////////////////////////
41
42 #ifndef Pegasus_ConfigManager_h
43 #define Pegasus_ConfigManager_h
44
45 #include <cctype>
|
46 mday 1.8 #include <stdlib.h>
|
47 mike 1.2 #include <Pegasus/Common/Config.h>
48 #include <Pegasus/Common/String.h>
|
49 kumpf 1.11 #include <Pegasus/Common/ArrayInternal.h>
|
50 kumpf 1.10 #include <Pegasus/Common/InternalException.h>
|
51 a.arora 1.19 #include <Pegasus/Common/AutoPtr.h>
|
52 david.dillard 1.21 #include <Pegasus/Common/HashTable.h>
|
53 mike 1.2 #include <Pegasus/Config/ConfigPropertyOwner.h>
54 #include <Pegasus/Config/ConfigFileHandler.h>
55
56 #include <Pegasus/Config/TracePropertyOwner.h>
57 #include <Pegasus/Config/LogPropertyOwner.h>
58 #include <Pegasus/Config/DefaultPropertyOwner.h>
59 #include <Pegasus/Config/SecurityPropertyOwner.h>
60 #include <Pegasus/Config/RepositoryPropertyOwner.h>
61 #include <Pegasus/Config/ShutdownPropertyOwner.h>
|
62 kumpf 1.3 #include <Pegasus/Config/FileSystemPropertyOwner.h>
|
63 konrad.r 1.18 #include <Pegasus/Config/ProviderDirPropertyOwner.h>
|
64 mike 1.2
65 PEGASUS_NAMESPACE_BEGIN
66
67 /**
68 This class reads configuration properties from the config file, maps the
69 properties to owners, and implements access methods.
70 */
71
72 class PEGASUS_CONFIG_LINKAGE ConfigManager
73 {
74
75 private:
76
|
77 kumpf 1.20 /**
78 Refers to the singleton ConfigManager instance. If no ConfigManager
79 instance has been constructed, this value is null.
80 */
|
81 mike 1.2 static ConfigManager* _instance;
82
83
84 /** Constructor. */
85 ConfigManager();
86
87
88 /**
89 Initialize config property with the value specified as a
90 command line option.
91
92 @param configOption name and value of the command line option.
93
94 @exception InvalidPropertyValue if property value is not valid.
95 @exception UnrecognizedConfigProperty if property is not defined.
96 */
97 Boolean _initPropertyWithCommandLineOption(
98 const String& configOption);
99 //throw (InvalidPropertyValue, UnrecognizedConfigProperty);
100
101
102 mike 1.2 /**
103 load config properties from the file
104
105 @exception CannotRenameFile if failed to rename the config file.
|
106 kumpf 1.17 @exception CannotOpenFile if failed to set permissions on the config file.
|
107 mike 1.2 @exception ConfigFileSyntaxError if there are synatx error
108 while parsing the config files.
109 */
110 void _loadConfigProperties();
|
111 kumpf 1.17 //throw (CannotRenameFile, ConfigFileSyntaxError, CannotOpenFile);
|
112 mike 1.2
113
114 /**
115 Initialize config property owners and add them to the property owner table
116 */
|
117 kumpf 1.4 void _initPropertyTable();
|
118 mike 1.2
|
119 david.dillard 1.21 /**
120 HashTable used to identify owners.
121 */
122 typedef HashTable<String,
123 ConfigPropertyOwner*,EqualFunc<String>,HashFunc<String> > OwnerTable;
124
125 /**
126 HashTable used to identify fixed values.
127 */
128 typedef HashTable<String,
129 const char*,EqualFunc<String>,HashFunc<String> > FixedValueTable;
130
|
131 david.dillard 1.22 /*
132 friend declaration needed by some compilers to allow OwnerTable and
133 FixedValueTable to be accessible from PropertyTable.
134 */
135 struct PropertyTable;
136 friend struct ConfigManager::PropertyTable;
137
|
138 david.dillard 1.21 /**
139 Structure used to identify properties.
140 */
141 struct PropertyTable
142 {
143 OwnerTable ownerTable;
144 FixedValueTable fixedValueTable;
145 };
|
146 mike 1.2
147 /**
148 HashTable to store the config property names and
149 property owners
150 */
|
151 a.arora 1.19 AutoPtr<PropertyTable> _propertyTable; //PEP101
|
152 mike 1.2
153 /**
154 Handler to access the config files.
155 */
|
156 a.arora 1.19 AutoPtr<ConfigFileHandler> _configFileHandler; //PEP101
|
157 mike 1.2
|
158 kumpf 1.3 /**
159 Pegasus home variable
160 */
161 static String _pegasusHome;
162
|
163 mike 1.2 public:
164
165 /**
|
166 kumpf 1.3 Default location of Pegasus home.
167 */
168 static const String PEGASUS_HOME_DEFAULT;
169
|
170 mike 1.2
171 /**
172 Property Owners
173
174 When a new property owner is created be sure to add static
175 variable pointers for each of the new property owner.
176 */
177 static TracePropertyOwner* traceOwner;
178
179 static LogPropertyOwner* logOwner;
180
181 static DefaultPropertyOwner* defaultOwner;
182
183 static SecurityPropertyOwner* securityOwner;
184
185 static RepositoryPropertyOwner* repositoryOwner;
186
187 static ShutdownPropertyOwner* shutdownOwner;
188
|
189 kumpf 1.3 static FileSystemPropertyOwner* fileSystemOwner;
|
190 mike 1.2
|
191 konrad.r 1.18 static ProviderDirPropertyOwner* providerDirOwner;
|
192 kumpf 1.20
193 /**
194 Boolean indicating whether configuration data should be read from
195 and persisted to configuration files. If true, all operations are
196 functional and updates are written to the configuration files. If
197 false, the ConfigManager does not read to or write from configuration
198 files. In this case, methods that specifically implicate
199 configuration files must not be used. The default value is false.
200 */
201 Boolean useConfigFiles;
202
|
203 mike 1.2 /**
|
204 kumpf 1.20 Get a reference to the singleton ConfigManager instance. If no
205 ConfigManager instance exists, construct one.
|
206 mike 1.2 */
207 static ConfigManager* getInstance();
208
209
210 /**
|
211 kumpf 1.20 Initialize the current value of a config property.
212
213 @param propertyName The name of the property to initialize (e.g.,
214 "httpPort").
215 @param propertyValue The initial value of the property.
216 @return true if the property found and initialized, else false.
217
218 @exception UnrecognizedConfigProperty if property is not defined.
219 @exception InvalidPropertyValue if property value is not valid.
220 */
221 Boolean initCurrentValue(
222 const String& name,
223 const String& value);
224 //throw (InvalidPropertyValue, UnrecognizedConfigProperty);
225
226 /**
|
227 mike 1.2 Update current value of a property.
228
|
229 kumpf 1.7 @param propertyName The name of the property to update (eg. "httpPort").
|
230 mike 1.2 @param propertyValue The new value of the property. If the value is
231 null, the property should be reset to its default
232 value.
|
233 kumpf 1.5 @param unset Specifies whether the property should be updated
234 or unset.
|
235 mike 1.2 @return true if the property found and updated, else false.
236
237 @exception NonDynamicConfigProperty if property is not dynamic.
238 @exception UnrecognizedConfigProperty if property is not defined.
239 @exception InvalidPropertyValue if property value is not valid.
240 */
|
241 kumpf 1.5 Boolean updateCurrentValue(
242 const String& name,
243 const String& value,
244 Boolean unset);
|
245 mike 1.2 //throw (NonDynamicConfigProperty, InvalidPropertyValue,
|
246 kumpf 1.13 // UnrecognizedConfigProperty);
|
247 mike 1.2
248 /**
249 Update planned value of a property.
250
|
251 kumpf 1.7 @param propertyName The name of the property to update (eg. "httpPort").
|
252 mike 1.2 @param propertyValue The new value of the property. If the value is
253 null, the property should be reset to its default
254 value.
|
255 kumpf 1.5 @param unset Specifies whether the property should be updated
256 or unset.
|
257 mike 1.2 @return Boolean True if the property found and updated.
258
259 @exception NonDynamicConfigProperty if property is not dynamic.
260 @exception UnrecognizedConfigProperty if property is not defined.
261 @exception InvalidPropertyValue if property value is not valid.
262 */
|
263 kumpf 1.5 Boolean updatePlannedValue(
264 const String& name,
265 const String& value,
266 Boolean unset);
|
267 mike 1.2 //throw (NonDynamicConfigProperty, InvalidPropertyValue,
|
268 kumpf 1.13 // UnrecognizedConfigProperty);
|
269 mike 1.2
270
271 /**
272 Validate the value of a property.
273
274 @param name The name of the property.
275 @param value The value of the property to be validated.
276 @return true if the value of the property is valid, else false.
277
278 @exception UnrecognizedConfigProperty if property is not defined.
279 */
280 Boolean validatePropertyValue(const String& name, const String& value);
281 //throw (UnrecognizedConfigProperty);
282
283 /**
284 Get default value of the specified property.
285
286 @param name The name of the property.
287 @return string containing the default value of the specified property.
288
289 @exception UnrecognizedConfigProperty if property is not defined.
290 mike 1.2 */
291 String getDefaultValue(const String& name);
292 //throw (UnrecognizedConfigProperty);
293
294
295 /**
296 Get current value of the specified property.
297
298 @param name The name of the property.
299 @return string containing the current value of the specified property.
300
301 @exception UnrecognizedConfigProperty if property is not defined.
302 */
303 String getCurrentValue(const String& name);
304 //throw (UnrecognizedConfigProperty);
305
306
307 /**
308 Get planned value of the specified property.
309
310 @param name The name of the property.
311 mike 1.2 @return string containing the current value of the specified property.
312
313 @exception UnrecognizedConfigProperty if property is not defined.
314 */
315 String getPlannedValue(const String& name);
316 //throw (UnrecognizedConfigProperty);
317
318
319 /**
320 Get all the attributes of the specified property.
321
322 @param name The name of the property.
323 @param propertyInfo List containing the property info.
324
325 @exception UnrecognizedConfigProperty if property is not defined.
326 */
327 void getPropertyInfo(const String& name, Array<String>& propertyInfo);
328 //throw (UnrecognizedConfigProperty);
329
330
331 /**
332 mike 1.2 Get a list of all the property names.
333
334 @param propertyNames List containing all the property names.
|
335 kumpf 1.20 @param includeHiddenProperties Boolean indicating whether hidden
336 properties should be included in the
337 returned list.
338 */
339 void getAllPropertyNames(
340 Array<String>& propertyNames,
341 Boolean includeHiddenProperties);
|
342 mike 1.2
343 /**
344 Merges the config properties from the specified configuration files.
345
346 @param currentFile Name of file that contains current config properties.
347 @param plannedFile Name of file that contains planned config properties.
348
349 @exception NoSuchFile if the specified config file does not exist.
350 @exception FileNotReadable if the specified config file is not readable.
351 @exception CannotRenameFile if failed to rename the config file.
|
352 kumpf 1.17 @exception CannotOpenFile if failed to set permissions on the config file.
|
353 mike 1.2 @exception ConfigFileSyntaxError if there is synatx error
354 while parsing the config files.
355 */
356 void mergeConfigFiles(const String& currentFile, const String& plannedFile);
357 //throw (NoSuchFile, FileNotReadable, CannotRenameFile,
|
358 kumpf 1.17 // ConfigFileSyntaxError, CannotOpenFile);
|
359 mike 1.2
360 /**
361 Merge the config properties from the default planned config file
362 with the properties in the default current config file.
363
364 @exception NoSuchFile if the default config file does not exist.
365 @exception FileNotReadable if the default config file is not readable.
366 @exception CannotRenameFile if failed to rename the config file.
|
367 kumpf 1.17 @exception CannotOpenFile if failed to set permissions on the config file.
|
368 mike 1.2 @exception ConfigFileSyntaxError if there are synatx error
369 while parsing the config files.
370 */
371 void mergeConfigFiles();
372 //throw (NoSuchFile, FileNotReadable, CannotRenameFile,
|
373 kumpf 1.17 // ConfigFileSyntaxError, CannotOpenFile);
|
374 mike 1.2
375
376 /**
377 Merge option values from the command line.
378
379 @param argc number of argument on the command line.
380 @param argv list of command line arguments.
381
382 @exception InvalidPropertyValue if validation fails.
383 @exception UnrecognizedConfigProperty if property is not defined.
384 */
385 void mergeCommandLine(int& argc, char**& argv);
386 //throw (UnrecognizedConfigProperty, InvalidPropertyValue);
|
387 kumpf 1.3
388
389 /**
390 Get Pegasus Home
391 */
392 static String getPegasusHome();
393
394 /**
395 Set Pegasus Home
396 */
397 static void setPegasusHome(String& home);
398
399 /**
400 Get Homed Path
401 This function checks if the argument passed is an absolute path.
402 If true then it returns the same value. Else, it prepends
403 the value of pegasusHome to the value.
404 */
405 static String getHomedPath(const String& value);
|
406 mike 1.2
407 };
408
409 PEGASUS_NAMESPACE_END
410
411 #endif /* Pegasus_ConfigManager_h */
412
|