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