(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            // Author: Nag Boranna (nagaraja_boranna@hp.com)
 33            //
 34 kumpf 1.3  // Modified By: Sushma Fernandes, Hewlett-Packard Company
 35            //                 (sushma_fernandes@hp.com)
 36 kumpf 1.4  //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 37 aruran.ms 1.27 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3612
 38 aruran.ms 1.30 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3610
 39 david.dillard 1.31 //              David Dillard, VERITAS Software Corp.
 40                    //                  (david.dillard@veritas.com)
 41 mike          1.2  //
 42                    //%////////////////////////////////////////////////////////////////////////////
 43                    
 44                    
 45                    ///////////////////////////////////////////////////////////////////////////////
 46 chip          1.24 //
 47 mike          1.2  // This file defines the classes necessary to manage configuration properties
 48 chip          1.24 // specified on the commandline and configuration files for Pegasus.
 49 mike          1.2  //
 50                    ///////////////////////////////////////////////////////////////////////////////
 51                    
 52                    #ifndef Pegasus_ConfigManager_h
 53                    #define Pegasus_ConfigManager_h
 54                    
 55                    #include <cctype>
 56 mday          1.8  #include <stdlib.h>
 57 mike          1.2  #include <Pegasus/Common/Config.h>
 58                    #include <Pegasus/Common/String.h>
 59 kumpf         1.11 #include <Pegasus/Common/ArrayInternal.h>
 60 kumpf         1.10 #include <Pegasus/Common/InternalException.h>
 61 a.arora       1.19 #include <Pegasus/Common/AutoPtr.h>
 62 david.dillard 1.21 #include <Pegasus/Common/HashTable.h>
 63 mike          1.2  #include <Pegasus/Config/ConfigPropertyOwner.h>
 64                    #include <Pegasus/Config/ConfigFileHandler.h>
 65                    
 66                    #include <Pegasus/Config/TracePropertyOwner.h>
 67                    #include <Pegasus/Config/LogPropertyOwner.h>
 68                    #include <Pegasus/Config/DefaultPropertyOwner.h>
 69                    #include <Pegasus/Config/SecurityPropertyOwner.h>
 70                    #include <Pegasus/Config/RepositoryPropertyOwner.h>
 71                    #include <Pegasus/Config/ShutdownPropertyOwner.h>
 72 kumpf         1.3  #include <Pegasus/Config/FileSystemPropertyOwner.h>
 73 konrad.r      1.18 #include <Pegasus/Config/ProviderDirPropertyOwner.h>
 74 chip          1.24 #include <Pegasus/Config/NormalizationPropertyOwner.h>
 75 mike          1.2  
 76                    PEGASUS_NAMESPACE_BEGIN
 77                    
 78                    /**
 79 chip          1.24   This class reads configuration properties from the config file, maps the
 80 mike          1.2    properties to owners, and implements access methods.
 81                    */
 82                    
 83                    class PEGASUS_CONFIG_LINKAGE ConfigManager
 84                    {
 85                    
 86                    private:
 87                    
 88 kumpf         1.20     /**
 89                            Refers to the singleton ConfigManager instance.  If no ConfigManager
 90                            instance has been constructed, this value is null.
 91                         */
 92 mike          1.2      static ConfigManager* _instance;
 93                    
 94                    
 95                        /** Constructor. */
 96                        ConfigManager();
 97                    
 98                    
 99 chip          1.24     /**
100 mike          1.2      Initialize config property with the value specified as a
101                        command line option.
102                    
103                        @param configOption    name and value of the command line option.
104                    
105                        @exception InvalidPropertyValue  if property value is not valid.
106                        @exception UnrecognizedConfigProperty  if property is not defined.
107                        */
108                        Boolean _initPropertyWithCommandLineOption(
109                            const String& configOption);
110                    
111                    
112 chip          1.24     /**
113                        load config properties from the file
114 mike          1.2  
115                        @exception CannotRenameFile  if failed to rename the config file.
116 kumpf         1.17     @exception CannotOpenFile if failed to set permissions on the config file.
117 chip          1.24     @exception ConfigFileSyntaxError  if there are synatx error
118 mike          1.2                              while parsing the config files.
119                        */
120                        void _loadConfigProperties();
121                    
122                    
123                        /**
124                        Initialize config property owners and add them to the property owner table
125                        */
126 kumpf         1.4      void _initPropertyTable();
127 mike          1.2  
128 david.dillard 1.21     /**
129                        HashTable used to identify owners.
130                        */
131                        typedef HashTable<String,
132                            ConfigPropertyOwner*,EqualFunc<String>,HashFunc<String> > OwnerTable;
133                    
134                        /**
135                        HashTable used to identify fixed values.
136                        */
137                        typedef HashTable<String,
138                            const char*,EqualFunc<String>,HashFunc<String> > FixedValueTable;
139                    
140 david.dillard 1.22     /*
141                        friend declaration needed by some compilers to allow OwnerTable and
142                        FixedValueTable to be accessible from PropertyTable.
143                        */
144                        struct PropertyTable;
145                        friend struct ConfigManager::PropertyTable;
146                    
147 david.dillard 1.21     /**
148                        Structure used to identify properties.
149                        */
150                        struct PropertyTable
151                        {
152                            OwnerTable ownerTable;
153                            FixedValueTable fixedValueTable;
154                        };
155 mike          1.2  
156 chip          1.24     /**
157                        HashTable to store the config property names and
158                        property owners
159 mike          1.2      */
160 a.arora       1.19     AutoPtr<PropertyTable> _propertyTable; //PEP101
161 mike          1.2  
162                        /**
163                        Handler to access the config files.
164                        */
165 a.arora       1.19     AutoPtr<ConfigFileHandler>    _configFileHandler; //PEP101
166 mike          1.2  
167 kumpf         1.3      /**
168                        Pegasus home variable
169                        */
170                        static String	  _pegasusHome;
171                    
172 mike          1.2  public:
173                    
174                        /**
175 kumpf         1.3      Default location of Pegasus home.
176                        */
177                        static const String PEGASUS_HOME_DEFAULT;
178                    
179 mike          1.2  
180                        /**
181                        Property Owners
182                    
183                        When a new property owner is created be sure to add static
184                        variable pointers for each of the new property owner.
185                        */
186                        static TracePropertyOwner*      traceOwner;
187                    
188 chip          1.24     static LogPropertyOwner*        logOwner;
189 mike          1.2  
190                        static DefaultPropertyOwner*    defaultOwner;
191                    
192 chip          1.24     static SecurityPropertyOwner*   securityOwner;
193 mike          1.2  
194 chip          1.24     static RepositoryPropertyOwner* repositoryOwner;
195 mike          1.2  
196 chip          1.24     static ShutdownPropertyOwner*   shutdownOwner;
197 mike          1.2  
198 chip          1.24     static FileSystemPropertyOwner*   fileSystemOwner;
199 mike          1.2  
200 konrad.r      1.18     static ProviderDirPropertyOwner*	providerDirOwner;
201 kumpf         1.20 
202 chip          1.24     static NormalizationPropertyOwner * normalizationOwner;
203                    
204 kumpf         1.20     /**
205                            Boolean indicating whether configuration data should be read from
206 kumpf         1.26         and persisted to configuration files.  If true, this ConfigManager
207                            instance actively manages the configuration data.  All operations
208                            are functional and updates are written to the configuration files.  If
209 kumpf         1.20         false, the ConfigManager does not read to or write from configuration
210 kumpf         1.26         files.  In addition, property values are not validated.  When this
211                            value is false, the behavior of methods that specifically implicate
212                            configuration files is not defined.  The default value is false.
213 kumpf         1.20      */
214                        Boolean useConfigFiles;
215                    
216 chip          1.24     /**
217 kumpf         1.20         Get a reference to the singleton ConfigManager instance.  If no
218                            ConfigManager instance exists, construct one.
219 mike          1.2      */
220                        static ConfigManager* getInstance();
221                    
222                    
223 chip          1.24     /**
224 konrad.r      1.28     Terminate the ConfigManager.
225                        */
226 konrad.r      1.29     static void destroy( void );
227 konrad.r      1.28     /**
228 kumpf         1.20     Initialize the current value of a config property.
229                    
230                        @param  propertyName  The name of the property to initialize (e.g.,
231                                              "httpPort").
232                        @param  propertyValue The initial value of the property.
233                        @return true if the property found and initialized, else false.
234                    
235                        @exception UnrecognizedConfigProperty  if property is not defined.
236                        @exception InvalidPropertyValue  if property value is not valid.
237                        */
238                        Boolean initCurrentValue(
239                            const String& name,
240                            const String& value);
241                    
242 chip          1.24     /**
243 mike          1.2      Update current value of a property.
244                    
245 kumpf         1.7      @param  propertyName  The name of the property to update (eg. "httpPort").
246 mike          1.2      @param  propertyValue The new value of the property.  If the value is
247                                              null, the property should be reset to its default
248                                              value.
249 kumpf         1.5      @param  unset         Specifies whether the property should be updated
250                                              or unset.
251 mike          1.2      @return true if the property found and updated, else false.
252                    
253                        @exception NonDynamicConfigProperty  if property is not dynamic.
254                        @exception UnrecognizedConfigProperty  if property is not defined.
255                        @exception InvalidPropertyValue  if property value is not valid.
256                        */
257 kumpf         1.5      Boolean updateCurrentValue(
258                            const String& name,
259                            const String& value,
260                            Boolean unset);
261 mike          1.2  
262 chip          1.24     /**
263 mike          1.2      Update planned value of a property.
264                    
265 kumpf         1.7      @param  propertyName  The name of the property to update (eg. "httpPort").
266 mike          1.2      @param  propertyValue The new value of the property.  If the value is
267                                              null, the property should be reset to its default
268                                              value.
269 kumpf         1.5      @param  unset         Specifies whether the property should be updated
270                                              or unset.
271 mike          1.2      @return Boolean       True if the property found and updated.
272                    
273                        @exception NonDynamicConfigProperty  if property is not dynamic.
274                        @exception UnrecognizedConfigProperty  if property is not defined.
275                        @exception InvalidPropertyValue  if property value is not valid.
276                        */
277 kumpf         1.5      Boolean updatePlannedValue(
278                            const String& name,
279                            const String& value,
280                            Boolean unset);
281 mike          1.2  
282                    
283 chip          1.24     /**
284 mike          1.2      Validate the value of a property.
285                    
286                        @param  name    The name of the property.
287 chip          1.24     @param  value   The value of the property to be validated.
288 mike          1.2      @return true if the value of the property is valid, else false.
289                    
290                        @exception UnrecognizedConfigProperty  if property is not defined.
291                        */
292                        Boolean validatePropertyValue(const String& name, const String& value);
293                    
294                        /**
295                        Get default value of the specified property.
296                    
297                        @param  name    The name of the property.
298                        @return string containing the default value of the specified property.
299                    
300                        @exception UnrecognizedConfigProperty  if property is not defined.
301                        */
302 aruran.ms     1.30     String getDefaultValue(const String& name) const;
303 mike          1.2  
304                    
305 chip          1.24     /**
306 mike          1.2      Get current value of the specified property.
307                    
308                        @param  name    The name of the property.
309                        @return string containing the current value of the specified property.
310                    
311                        @exception UnrecognizedConfigProperty  if property is not defined.
312                        */
313 aruran.ms     1.30     String getCurrentValue(const String& name) const;
314 mike          1.2  
315                    
316 chip          1.24     /**
317 mike          1.2      Get planned value of the specified property.
318                    
319                        @param  name    The name of the property.
320                        @return string containing the current value of the specified property.
321                    
322                        @exception UnrecognizedConfigProperty  if property is not defined.
323                        */
324 aruran.ms     1.30     String getPlannedValue(const String& name) const;
325 mike          1.2  
326                    
327 chip          1.24     /**
328 mike          1.2      Get all the attributes of the specified property.
329                    
330                        @param name          The name of the property.
331                        @param propertyInfo  List containing the property info.
332                    
333                        @exception UnrecognizedConfigProperty  if property is not defined.
334                        */
335 aruran.ms     1.30     void getPropertyInfo(const String& name, Array<String>& propertyInfo) const;
336 mike          1.2  
337                    
338 chip          1.24     /**
339 mike          1.2      Get a list of all the property names.
340                    
341                        @param propertyNames  List containing all the property names.
342 kumpf         1.20     @param includeHiddenProperties  Boolean indicating whether hidden
343                                                        properties should be included in the
344                                                        returned list.
345                        */
346                        void getAllPropertyNames(
347                            Array<String>& propertyNames,
348 aruran.ms     1.30         Boolean includeHiddenProperties) const;
349 mike          1.2  
350 chip          1.24     /**
351 mike          1.2      Merges the config properties from the specified configuration files.
352                    
353                        @param currentFile   Name of file that contains current config properties.
354                        @param plannedFile   Name of file that contains planned config properties.
355                    
356                        @exception NoSuchFile  if the specified config file does not exist.
357                        @exception FileNotReadable  if the specified config file is not readable.
358                        @exception CannotRenameFile  if failed to rename the config file.
359 kumpf         1.17     @exception CannotOpenFile if failed to set permissions on the config file.
360 chip          1.24     @exception ConfigFileSyntaxError  if there is synatx error
361 mike          1.2                              while parsing the config files.
362 kumpf         1.26     @exception InvalidPropertyValue if validation fails for a config property
363                            in either file.
364                        @exception UnrecognizedConfigProperty if a config property specified in
365                            either file is not defined.
366 mike          1.2      */
367                        void mergeConfigFiles(const String& currentFile, const String& plannedFile);
368                    
369 chip          1.24     /**
370 mike          1.2      Merge the config properties from the default planned config file
371                        with the properties in the default current config file.
372                    
373                        @exception NoSuchFile  if the default config file does not exist.
374                        @exception FileNotReadable  if the default config file is not readable.
375                        @exception CannotRenameFile  if failed to rename the config file.
376 kumpf         1.17     @exception CannotOpenFile if failed to set permissions on the config file.
377 chip          1.24     @exception ConfigFileSyntaxError  if there are synatx error
378 mike          1.2                              while parsing the config files.
379 kumpf         1.26     @exception InvalidPropertyValue if validation fails for a config property
380                            in either file.
381                        @exception UnrecognizedConfigProperty if a config property specified in
382                            either file is not defined.
383 mike          1.2      */
384                        void mergeConfigFiles();
385                    
386                    
387 chip          1.24     /**
388                        Merge option values from the command line.
389 mike          1.2  
390                        @param argc number of argument on the command line.
391                        @param argv list of command line arguments.
392                    
393                        @exception  InvalidPropertyValue if validation fails.
394                        @exception  UnrecognizedConfigProperty  if property is not defined.
395                        */
396                        void mergeCommandLine(int& argc, char**& argv);
397 kumpf         1.3  
398                    
399                        /**
400                        Get Pegasus Home
401                        */
402                        static String getPegasusHome();
403                    
404                        /**
405 chip          1.24     Set Pegasus Home
406 kumpf         1.3      */
407 aruran.ms     1.27     static void setPegasusHome(const String& home);
408 kumpf         1.3  
409                        /**
410                        Get Homed Path
411 chip          1.24     This function checks if the argument passed is an absolute path.
412                        If true then it returns the same value. Else, it prepends
413 kumpf         1.3      the value of pegasusHome to the value.
414                        */
415                        static String getHomedPath(const String& value);
416 mike          1.2  
417 kumpf         1.33     /**
418                            Parses a boolean configuration property value.
419                            @param propertyValue A String containing a boolean configuration
420                                property value.
421                            @return True if the specified configuration property value represents
422                                a boolean value of "true", false otherwise.
423                        */
424                        static Boolean parseBooleanValue(const String& propertyValue);
425 mike          1.2  };
426                    
427                    PEGASUS_NAMESPACE_END
428                    
429                    #endif /* Pegasus_ConfigManager_h */
430                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2