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

  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                        /**
132                        Structure used to identify properties.
133                        */
134                        struct PropertyTable
135                        {
136                            OwnerTable ownerTable;
137                            FixedValueTable fixedValueTable;
138                        };
139 mike          1.2  
140                        /** 
141                        HashTable to store the config property names and 
142                        property owners 
143                        */
144 a.arora       1.19     AutoPtr<PropertyTable> _propertyTable; //PEP101
145 mike          1.2  
146                        /**
147                        Handler to access the config files.
148                        */
149 a.arora       1.19     AutoPtr<ConfigFileHandler>    _configFileHandler; //PEP101
150 mike          1.2  
151 kumpf         1.3      /**
152                        Pegasus home variable
153                        */
154                        static String	  _pegasusHome;
155                    
156 mike          1.2  public:
157                    
158                        /**
159 kumpf         1.3      Default location of Pegasus home.
160                        */
161                        static const String PEGASUS_HOME_DEFAULT;
162                    
163 mike          1.2  
164                        /**
165                        Property Owners
166                    
167                        When a new property owner is created be sure to add static
168                        variable pointers for each of the new property owner.
169                        */
170                        static TracePropertyOwner*      traceOwner;
171                    
172                        static LogPropertyOwner*        logOwner; 
173                    
174                        static DefaultPropertyOwner*    defaultOwner;
175                    
176                        static SecurityPropertyOwner*   securityOwner; 
177                    
178                        static RepositoryPropertyOwner* repositoryOwner; 
179                    
180                        static ShutdownPropertyOwner*   shutdownOwner; 
181                    
182 kumpf         1.3      static FileSystemPropertyOwner*   fileSystemOwner; 
183 mike          1.2  
184 konrad.r      1.18     static ProviderDirPropertyOwner*	providerDirOwner;
185 kumpf         1.20 
186                        /**
187                            Boolean indicating whether configuration data should be read from
188                            and persisted to configuration files.  If true, all operations are
189                            functional and updates are written to the configuration files.  If
190                            false, the ConfigManager does not read to or write from configuration
191                            files.  In this case, methods that specifically implicate
192                            configuration files must not be used.  The default value is false.
193                         */
194                        Boolean useConfigFiles;
195                    
196 mike          1.2      /** 
197 kumpf         1.20         Get a reference to the singleton ConfigManager instance.  If no
198                            ConfigManager instance exists, construct one.
199 mike          1.2      */
200                        static ConfigManager* getInstance();
201                    
202                    
203                        /** 
204 kumpf         1.20     Initialize the current value of a config property.
205                    
206                        @param  propertyName  The name of the property to initialize (e.g.,
207                                              "httpPort").
208                        @param  propertyValue The initial value of the property.
209                        @return true if the property found and initialized, else false.
210                    
211                        @exception UnrecognizedConfigProperty  if property is not defined.
212                        @exception InvalidPropertyValue  if property value is not valid.
213                        */
214                        Boolean initCurrentValue(
215                            const String& name,
216                            const String& value);
217                            //throw (InvalidPropertyValue, UnrecognizedConfigProperty);
218                    
219                        /** 
220 mike          1.2      Update current value of a property.
221                    
222 kumpf         1.7      @param  propertyName  The name of the property to update (eg. "httpPort").
223 mike          1.2      @param  propertyValue The new value of the property.  If the value is
224                                              null, the property should be reset to its default
225                                              value.
226 kumpf         1.5      @param  unset         Specifies whether the property should be updated
227                                              or unset.
228 mike          1.2      @return true if the property found and updated, else false.
229                    
230                        @exception NonDynamicConfigProperty  if property is not dynamic.
231                        @exception UnrecognizedConfigProperty  if property is not defined.
232                        @exception InvalidPropertyValue  if property value is not valid.
233                        */
234 kumpf         1.5      Boolean updateCurrentValue(
235                            const String& name,
236                            const String& value,
237                            Boolean unset);
238 mike          1.2          //throw (NonDynamicConfigProperty, InvalidPropertyValue, 
239 kumpf         1.13         //    UnrecognizedConfigProperty);
240 mike          1.2  
241                        /** 
242                        Update planned value of a property.
243                    
244 kumpf         1.7      @param  propertyName  The name of the property to update (eg. "httpPort").
245 mike          1.2      @param  propertyValue The new value of the property.  If the value is
246                                              null, the property should be reset to its default
247                                              value.
248 kumpf         1.5      @param  unset         Specifies whether the property should be updated
249                                              or unset.
250 mike          1.2      @return Boolean       True if the property found and updated.
251                    
252                        @exception NonDynamicConfigProperty  if property is not dynamic.
253                        @exception UnrecognizedConfigProperty  if property is not defined.
254                        @exception InvalidPropertyValue  if property value is not valid.
255                        */
256 kumpf         1.5      Boolean updatePlannedValue(
257                            const String& name,
258                            const String& value,
259                            Boolean unset);
260 mike          1.2          //throw (NonDynamicConfigProperty, InvalidPropertyValue, 
261 kumpf         1.13         //    UnrecognizedConfigProperty);
262 mike          1.2  
263                    
264                        /** 
265                        Validate the value of a property.
266                    
267                        @param  name    The name of the property.
268                        @param  value   The value of the property to be validated. 
269                        @return true if the value of the property is valid, else false.
270                    
271                        @exception UnrecognizedConfigProperty  if property is not defined.
272                        */
273                        Boolean validatePropertyValue(const String& name, const String& value);
274                            //throw (UnrecognizedConfigProperty);
275                    
276                        /**
277                        Get default value of the specified property.
278                    
279                        @param  name    The name of the property.
280                        @return string containing the default value of the specified property.
281                    
282                        @exception UnrecognizedConfigProperty  if property is not defined.
283 mike          1.2      */
284                        String getDefaultValue(const String& name);
285                            //throw (UnrecognizedConfigProperty);
286                    
287                    
288                        /** 
289                        Get current value of the specified property.
290                    
291                        @param  name    The name of the property.
292                        @return string containing the current value of the specified property.
293                    
294                        @exception UnrecognizedConfigProperty  if property is not defined.
295                        */
296                        String getCurrentValue(const String& name);
297                            //throw (UnrecognizedConfigProperty);
298                    
299                    
300                        /** 
301                        Get planned value of the specified property.
302                    
303                        @param  name    The name of the property.
304 mike          1.2      @return string containing the current value of the specified property.
305                    
306                        @exception UnrecognizedConfigProperty  if property is not defined.
307                        */
308                        String getPlannedValue(const String& name);
309                            //throw (UnrecognizedConfigProperty);
310                    
311                    
312                        /** 
313                        Get all the attributes of the specified property.
314                    
315                        @param name          The name of the property.
316                        @param propertyInfo  List containing the property info.
317                    
318                        @exception UnrecognizedConfigProperty  if property is not defined.
319                        */
320                        void getPropertyInfo(const String& name, Array<String>& propertyInfo);
321                            //throw (UnrecognizedConfigProperty);
322                    
323                    
324                        /** 
325 mike          1.2      Get a list of all the property names.
326                    
327                        @param propertyNames  List containing all the property names.
328 kumpf         1.20     @param includeHiddenProperties  Boolean indicating whether hidden
329                                                        properties should be included in the
330                                                        returned list.
331                        */
332                        void getAllPropertyNames(
333                            Array<String>& propertyNames,
334                            Boolean includeHiddenProperties);
335 mike          1.2  
336                        /** 
337                        Merges the config properties from the specified configuration files.
338                    
339                        @param currentFile   Name of file that contains current config properties.
340                        @param plannedFile   Name of file that contains planned config properties.
341                    
342                        @exception NoSuchFile  if the specified config file does not exist.
343                        @exception FileNotReadable  if the specified config file is not readable.
344                        @exception CannotRenameFile  if failed to rename the config file.
345 kumpf         1.17     @exception CannotOpenFile if failed to set permissions on the config file.
346 mike          1.2      @exception ConfigFileSyntaxError  if there is synatx error 
347                                                while parsing the config files.
348                        */
349                        void mergeConfigFiles(const String& currentFile, const String& plannedFile);
350                            //throw (NoSuchFile, FileNotReadable, CannotRenameFile, 
351 kumpf         1.17         //    ConfigFileSyntaxError, CannotOpenFile);
352 mike          1.2  
353                        /** 
354                        Merge the config properties from the default planned config file
355                        with the properties in the default current config file.
356                    
357                        @exception NoSuchFile  if the default config file does not exist.
358                        @exception FileNotReadable  if the default config file is not readable.
359                        @exception CannotRenameFile  if failed to rename the config file.
360 kumpf         1.17     @exception CannotOpenFile if failed to set permissions on the config file.
361 mike          1.2      @exception ConfigFileSyntaxError  if there are synatx error 
362                                                while parsing the config files.
363                        */
364                        void mergeConfigFiles();
365                            //throw (NoSuchFile, FileNotReadable, CannotRenameFile, 
366 kumpf         1.17         //    ConfigFileSyntaxError, CannotOpenFile);
367 mike          1.2  
368                    
369                        /** 
370                        Merge option values from the command line. 
371                    
372                        @param argc number of argument on the command line.
373                        @param argv list of command line arguments.
374                    
375                        @exception  InvalidPropertyValue if validation fails.
376                        @exception  UnrecognizedConfigProperty  if property is not defined.
377                        */
378                        void mergeCommandLine(int& argc, char**& argv);
379                            //throw (UnrecognizedConfigProperty, InvalidPropertyValue);
380 kumpf         1.3  
381                    
382                        /**
383                        Get Pegasus Home
384                        */
385                        static String getPegasusHome();
386                    
387                        /**
388                        Set Pegasus Home 
389                        */
390                        static void setPegasusHome(String& home);
391                    
392                        /**
393                        Get Homed Path
394                        This function checks if the argument passed is an absolute path. 
395                        If true then it returns the same value. Else, it prepends 
396                        the value of pegasusHome to the value.
397                        */
398                        static String getHomedPath(const String& value);
399 mike          1.2  
400                    };
401                    
402                    PEGASUS_NAMESPACE_END
403                    
404                    #endif /* Pegasus_ConfigManager_h */
405                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2