(file) Return to ConfigManager.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Config

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2