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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2