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

  1 karl  1.24 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.18 // 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.16 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.18 // 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.21 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.24 // 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            // 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            // 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.21 // 
 21 mike  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // 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            // 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            // 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            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            
 35            ///////////////////////////////////////////////////////////////////////////////
 36 chip  1.20 //
 37 mike  1.2  // This file has implementation for the default property owner class.
 38            //
 39            ///////////////////////////////////////////////////////////////////////////////
 40            
 41            #include "DefaultPropertyOwner.h"
 42 yi.zhou 1.26 #include "ConfigManager.h"
 43              #include <Pegasus/Common/AuditLogger.h>
 44 mike    1.2  
 45              PEGASUS_USING_STD;
 46              
 47              PEGASUS_NAMESPACE_BEGIN
 48              
 49              
 50              ///////////////////////////////////////////////////////////////////////////////
 51              //  DefaultPropertyOwner
 52              //
 53 chip    1.20 //  When a new property is added with the default owner, make sure to add
 54              //  the property name and the default attributes of that property in
 55 mike    1.2  //  the table below.
 56              ///////////////////////////////////////////////////////////////////////////////
 57              
 58              static struct ConfigPropertyRow properties[] =
 59              {
 60 kumpf   1.14 #include "DefaultPropertyTable.h"
 61 mike    1.2  };
 62              
 63              const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 64              
 65              
 66              /** Constructors  */
 67              DefaultPropertyOwner::DefaultPropertyOwner()
 68              {
 69 a.arora 1.17     _configProperties.reset(new ConfigProperty[NUM_PROPERTIES]);
 70 mike    1.2  }
 71              
 72              
 73              /**
 74 kumpf   1.27     Initialize the config properties.
 75 mike    1.2  */
 76              void DefaultPropertyOwner::initialize()
 77              {
 78                  for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
 79                  {
 80 a.arora 1.17         (_configProperties.get())[i].propertyName = properties[i].propertyName;
 81                      (_configProperties.get())[i].defaultValue = properties[i].defaultValue;
 82                      (_configProperties.get())[i].currentValue = properties[i].defaultValue;
 83                      (_configProperties.get())[i].plannedValue = properties[i].defaultValue;
 84                      (_configProperties.get())[i].dynamic = properties[i].dynamic;
 85                      (_configProperties.get())[i].domain = properties[i].domain;
 86                      (_configProperties.get())[i].domainSize = properties[i].domainSize;
 87 kumpf   1.27         (_configProperties.get())[i].externallyVisible =
 88                          properties[i].externallyVisible;
 89 mike    1.2      }
 90              }
 91              
 92              
 93 chip    1.20 /**
 94 kumpf   1.27     Get information about the specified property.
 95 mike    1.2  */
 96              void DefaultPropertyOwner::getPropertyInfo(
 97 chip    1.20     const String& name,
 98 vijay.eli 1.23     Array<String>& propertyInfo) const
 99 mike      1.2  {
100                    propertyInfo.clear();
101                
102                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
103                    {
104 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
105 mike      1.2          {
106 kumpf     1.27             propertyInfo.append(_configProperties.get()[i].propertyName);
107                            propertyInfo.append(_configProperties.get()[i].defaultValue);
108                            propertyInfo.append(_configProperties.get()[i].currentValue);
109                            propertyInfo.append(_configProperties.get()[i].plannedValue);
110                            if (_configProperties.get()[i].dynamic)
111 kumpf     1.15             {
112                                propertyInfo.append(STRING_TRUE);
113                            }
114                            else
115                            {
116                                propertyInfo.append(STRING_FALSE);
117                            }
118 kumpf     1.27             if (_configProperties.get()[i].externallyVisible)
119 mike      1.2              {
120                                propertyInfo.append(STRING_TRUE);
121                            }
122                            else
123                            {
124                                propertyInfo.append(STRING_FALSE);
125                            }
126                            return;
127                        }
128                    }
129                
130                    //
131                    // specified property name is not found
132                    //
133                    throw UnrecognizedConfigProperty(name);
134                }
135                
136 chip      1.20 /**
137 kumpf     1.27     Get default value of the specified property
138 mike      1.2  */
139 vijay.eli 1.23 String DefaultPropertyOwner::getDefaultValue(const String& name) const
140 mike      1.2  {
141                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
142                    {
143 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
144 mike      1.2          {
145 kumpf     1.27             return _configProperties.get()[i].defaultValue;
146 mike      1.2          }
147                    }
148                
149                    //
150                    // Specified property name could not be found
151                    //
152                    throw UnrecognizedConfigProperty(name);
153                }
154                
155 chip      1.20 /**
156 kumpf     1.27     Get current value of the specified property
157 mike      1.2  */
158 vijay.eli 1.23 String DefaultPropertyOwner::getCurrentValue(const String& name) const
159 mike      1.2  {
160                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
161                    {
162 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
163 mike      1.2          {
164 kumpf     1.27             return _configProperties.get()[i].currentValue;
165 mike      1.2          }
166                    }
167                
168                    //
169                    // Specified property name could not be found
170                    //
171                    throw UnrecognizedConfigProperty(name);
172                }
173                
174 chip      1.20 /**
175 kumpf     1.27     Get planned value of the specified property
176 mike      1.2  */
177 vijay.eli 1.23 String DefaultPropertyOwner::getPlannedValue(const String& name) const
178 mike      1.2  {
179                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
180                    {
181 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
182 mike      1.2          {
183 kumpf     1.27             return _configProperties.get()[i].plannedValue;
184 mike      1.2          }
185                    }
186                
187                    //
188                    // Specified property name could not be found
189                    //
190                    throw UnrecognizedConfigProperty(name);
191                }
192                
193 chip      1.20 /**
194 kumpf     1.27     Init current value of the specified property to the specified value
195 mike      1.2  */
196                void DefaultPropertyOwner::initCurrentValue(
197 chip      1.20     const String& name,
198 mike      1.2      const String& value)
199                {
200                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
201                    {
202 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
203 mike      1.2          {
204 kumpf     1.27             _configProperties.get()[i].currentValue = value;
205 mike      1.2              return;
206                        }
207                    }
208                
209                    //
210                    // Specified property name could not be found
211                    //
212                    throw UnrecognizedConfigProperty(name);
213                }
214                
215 chip      1.20 /**
216 kumpf     1.27     Init planned value of the specified property to the specified value
217 mike      1.2  */
218                void DefaultPropertyOwner::initPlannedValue(
219 chip      1.20     const String& name,
220 mike      1.2      const String& value)
221                {
222                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
223                    {
224 kumpf     1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
225 mike      1.2          {
226 kumpf     1.27             _configProperties.get()[i].plannedValue = value;
227 mike      1.2              return;
228                        }
229                    }
230                
231                    //
232                    // Specified property name could not be found
233                    //
234                    throw UnrecognizedConfigProperty(name);
235                }
236                
237 chip      1.20 /**
238 kumpf     1.27     Update current value of the specified property to the specified value
239 mike      1.2  */
240                void DefaultPropertyOwner::updateCurrentValue(
241 chip      1.20     const String& name,
242 mike      1.2      const String& value)
243                {
244                    //
245                    // make sure the property is dynamic before updating the value.
246                    //
247                    if (!isDynamic(name))
248                    {
249 chip      1.20         throw NonDynamicConfigProperty(name);
250 mike      1.2      }
251                
252                    //
253 chip      1.20     // Since the validations done in initCurrrentValue are sufficient and
254                    // no additional validations required for update, we shall call
255 mike      1.2      // initCurrrentValue.
256                    //
257                    initCurrentValue(name, value);
258 yi.zhou   1.26 
259 kumpf     1.28 #ifdef PEGASUS_ENABLE_AUDIT_LOGGER
260 yi.zhou   1.26 
261                    if (String::equal(name, "enableAuditLog") && isValid(name, value))
262                    {
263                        Boolean enableAuditLog = ConfigManager::parseBooleanValue(value);
264                        AuditLogger::setEnabled(enableAuditLog);
265                    }
266                
267                #endif
268                
269 mike      1.2  }
270                
271                
272 chip      1.20 /**
273 kumpf     1.27     Update planned value of the specified property to the specified value
274 mike      1.2  */
275                void DefaultPropertyOwner::updatePlannedValue(
276 chip      1.20     const String& name,
277 mike      1.2      const String& value)
278                {
279                    //
280 chip      1.20     // Since the validations done in initPlannedValue are sufficient and
281                    // no additional validations required for update, we shall call
282 mike      1.2      // initPlannedValue.
283                    //
284                    initPlannedValue(name, value);
285                }
286                
287                
288 chip      1.20 /**
289 mike      1.2  Checks to see if the given value is valid or not.
290                */
291 kumpf     1.27 Boolean DefaultPropertyOwner::isValid(
292                    const String& name,
293                    const String& value) const
294 mike      1.2  {
295                    //
296                    // By default, no validation is done. It can optionally be added here
297                    // per property.
298                    //
299 dave.sudlik 1.29     if (String::equalNoCase(name, "socketWriteTimeout") ||
300                          String::equalNoCase(name, "idleConnectionTimeout"))
301 marek       1.25     {
302                          Uint32 timeoutValue;
303 kumpf       1.27         char dummyChar;
304 marek       1.25         int numConversions =
305                              sscanf(value.getCString(), "%u%c", &timeoutValue, &dummyChar);
306                          return ((timeoutValue != 0) && (numConversions == 1));
307                      }
308 kumpf       1.28 #ifdef PEGASUS_ENABLE_AUDIT_LOGGER
309 yi.zhou     1.26     else if (String::equal(name, "enableAuditLog"))
310                      {
311                          if (!(String::equalNoCase(value, "true")) &&
312                              !(String::equalNoCase(value, "false")))
313                          {
314 kumpf       1.27             return false;
315 yi.zhou     1.26         }
316                      }
317                  #endif
318                  
319 kumpf       1.27     return true;
320 mike        1.2  }
321                  
322 chip        1.20 /**
323 kumpf       1.27     Checks to see if the specified property is dynamic or not.
324 mike        1.2  */
325 vijay.eli   1.23 Boolean DefaultPropertyOwner::isDynamic(const String& name) const
326 mike        1.2  {
327                      for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
328                      {
329 kumpf       1.27         if (String::equalNoCase(_configProperties.get()[i].propertyName, name))
330 mike        1.2          {
331 kumpf       1.27             return (_configProperties.get()[i].dynamic == IS_DYNAMIC);
332 mike        1.2          }
333                      }
334                  
335                      //
336                      // Specified property name could not be found
337                      //
338                      throw UnrecognizedConfigProperty(name);
339                  }
340                  
341                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2