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

  1 karl  1.28 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.19 // 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.13 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.19 // 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.22 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.28 // 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.13 // 
 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 kumpf 1.29 //
 37 mike  1.2  // This file has implementation for the trace property owner class.
 38            //
 39            ///////////////////////////////////////////////////////////////////////////////
 40            
 41            #include <Pegasus/Common/Tracer.h>
 42            #include <Pegasus/Common/FileSystem.h>
 43 kumpf 1.29 #include <Pegasus/Common/MessageLoader.h>
 44 kumpf 1.3  #include "ConfigManager.h"
 45 mike  1.2  #include "TracePropertyOwner.h"
 46            
 47            
 48            PEGASUS_USING_STD;
 49            
 50            PEGASUS_NAMESPACE_BEGIN
 51            
 52            ///////////////////////////////////////////////////////////////////////////////
 53            //  TracePropertyOwner
 54            //
 55            //  When a new trace property is added, make sure to add the property name
 56            //  and the default attributes of that property in the table below.
 57            ///////////////////////////////////////////////////////////////////////////////
 58            
 59            static struct ConfigPropertyRow properties[] =
 60            {
 61 kumpf 1.12 #ifdef PEGASUS_OS_HPUX
 62 konrad.r 1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 63                   {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 64 kumpf    1.12 #else
 65 david    1.26 #if defined (PEGASUS_USE_RELEASE_CONFIG_OPTIONS) && !defined(PEGASUS_OS_OS400)
 66 konrad.r 1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 67                   {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 68 kumpf    1.15 #else
 69 konrad.r 1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 70                   {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 71 kumpf    1.15 #endif
 72 kumpf    1.12 #endif
 73 david    1.26 #ifdef PEGASUS_OS_OS400
 74 kumpf    1.29     {"traceFilePath", "/qibm/userdata/os400/cim/cimserver.trc",
 75                        IS_DYNAMIC, 0, 0, IS_VISIBLE},
 76               #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && \
 77                   defined(PEGASUS_USE_RELEASE_DIRS)
 78 marek    1.27     {"traceFilePath", "/tmp/cimserver.trc", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 79 david    1.26 #else
 80 konrad.r 1.21     {"traceFilePath", "cimserver.trc", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 81 david    1.26 #endif
 82 mike     1.2  };
 83               
 84               const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 85               
 86               
 87 kumpf    1.29 //
 88 mike     1.2  // Checks if the trace level is valid
 89               //
 90               Boolean isLevelValid(const String& traceLevel)
 91               {
 92                   //
 93                   // Check if the level is valid
 94                   //
 95 kumpf    1.29     if (traceLevel == "1" || traceLevel == "2" ||
 96                       traceLevel == "3" || traceLevel == "4")
 97 mike     1.2      {
 98                       return 1;
 99                   }
100                   else
101                   {
102 kumpf    1.29         return 0;
103 mike     1.2      }
104               }
105               
106               //
107               // Get the appropriate trace level
108               //
109               Uint32 getTraceLevel(const String& traceLevel)
110               {
111                   if ( traceLevel == "1" )
112                   {
113 kumpf    1.29         return Tracer::LEVEL1;
114 mike     1.2      }
115                   else if ( traceLevel == "2" )
116                   {
117 kumpf    1.29         return Tracer::LEVEL2;
118 mike     1.2      }
119                   else if ( traceLevel == "3" )
120                   {
121 kumpf    1.29         return Tracer::LEVEL3;
122 mike     1.2      }
123 kumpf    1.29     else
124 mike     1.2      {
125 kumpf    1.29         return Tracer::LEVEL4;
126 mike     1.2      }
127               }
128               
129               /** Constructors  */
130               TracePropertyOwner::TracePropertyOwner()
131               {
132 a.arora  1.16     _traceLevel.reset(new ConfigProperty);
133                   _traceFilePath.reset(new ConfigProperty);
134                   _traceComponents.reset(new ConfigProperty);
135 mike     1.2  }
136               
137               /**
138 kumpf    1.29     Initialize the config properties.
139 mike     1.2  */
140               void TracePropertyOwner::initialize()
141               {
142                   for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
143                   {
144                       //
145                       // Initialize the properties with default values
146                       //
147                       if (String::equalNoCase(properties[i].propertyName, "traceComponents"))
148                       {
149                           _traceComponents->propertyName = properties[i].propertyName;
150                           _traceComponents->defaultValue = properties[i].defaultValue;
151                           _traceComponents->currentValue = properties[i].defaultValue;
152                           _traceComponents->plannedValue = properties[i].defaultValue;
153                           _traceComponents->dynamic = properties[i].dynamic;
154                           _traceComponents->domain = properties[i].domain;
155                           _traceComponents->domainSize = properties[i].domainSize;
156 kumpf    1.29             _traceComponents->externallyVisible =
157                               properties[i].externallyVisible;
158 mike     1.2          }
159                       else if (String::equalNoCase(properties[i].propertyName, "traceLevel"))
160                       {
161                           _traceLevel->propertyName = properties[i].propertyName;
162                           _traceLevel->defaultValue = properties[i].defaultValue;
163                           _traceLevel->currentValue = properties[i].defaultValue;
164                           _traceLevel->plannedValue = properties[i].defaultValue;
165                           _traceLevel->dynamic = properties[i].dynamic;
166                           _traceLevel->domain = properties[i].domain;
167                           _traceLevel->domainSize = properties[i].domainSize;
168 kumpf    1.29             _traceLevel->externallyVisible =
169                               properties[i].externallyVisible;
170 mike     1.2          }
171 kumpf    1.29         else if (String::equalNoCase(
172                                    properties[i].propertyName, "traceFilePath"))
173 mike     1.2          {
174                           _traceFilePath->propertyName = properties[i].propertyName;
175                           _traceFilePath->defaultValue = properties[i].defaultValue;
176                           _traceFilePath->currentValue = properties[i].defaultValue;
177                           _traceFilePath->plannedValue = properties[i].defaultValue;
178                           _traceFilePath->dynamic = properties[i].dynamic;
179                           _traceFilePath->domain = properties[i].domain;
180                           _traceFilePath->domainSize = properties[i].domainSize;
181 kumpf    1.29             _traceFilePath->externallyVisible =
182                               properties[i].externallyVisible;
183 mike     1.2          }
184                   }
185               
186                   if (_traceLevel->defaultValue != String::EMPTY)
187                   {
188                       if (_traceLevel->defaultValue == "1")
189                       {
190                           Tracer::setTraceLevel(Tracer::LEVEL1);
191                       }
192                       else if (_traceLevel->defaultValue == "2")
193                       {
194                           Tracer::setTraceLevel(Tracer::LEVEL2);
195                       }
196                       else if (_traceLevel->defaultValue == "3")
197                       {
198                           Tracer::setTraceLevel(Tracer::LEVEL3);
199                       }
200                       else if (_traceLevel->defaultValue == "4")
201                       {
202                           Tracer::setTraceLevel(Tracer::LEVEL4);
203                       }
204 mike     1.2      }
205               }
206               
207 kumpf    1.6  struct ConfigProperty* TracePropertyOwner::_lookupConfigProperty(
208 aruran.ms 1.25     const String& name) const
209 mike      1.2  {
210                    if (String::equalNoCase(_traceComponents->propertyName, name))
211                    {
212 a.arora   1.16         return _traceComponents.get();
213 mike      1.2      }
214                    else if (String::equalNoCase(_traceLevel->propertyName, name))
215                    {
216 a.arora   1.16         return _traceLevel.get();
217 mike      1.2      }
218                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
219                    {
220 a.arora   1.16         return _traceFilePath.get();
221 mike      1.2      }
222                    else
223                    {
224                        throw UnrecognizedConfigProperty(name);
225                    }
226                }
227                
228 kumpf     1.29 /**
229                    Get information about the specified property.
230 mike      1.2  */
231 kumpf     1.6  void TracePropertyOwner::getPropertyInfo(
232 kumpf     1.29     const String& name,
233 vijay.eli 1.24     Array<String>& propertyInfo) const
234 mike      1.2  {
235 kumpf     1.6      propertyInfo.clear();
236                
237 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
238 kumpf     1.6  
239                    propertyInfo.append(configProperty->propertyName);
240                    propertyInfo.append(configProperty->defaultValue);
241                    propertyInfo.append(configProperty->currentValue);
242                    propertyInfo.append(configProperty->plannedValue);
243                    if (configProperty->dynamic)
244 kumpf     1.12     {
245                        propertyInfo.append(STRING_TRUE);
246                    }
247                    else
248                    {
249                        propertyInfo.append(STRING_FALSE);
250                    }
251                    if (configProperty->externallyVisible)
252 mike      1.2      {
253 kumpf     1.6          propertyInfo.append(STRING_TRUE);
254 mike      1.2      }
255                    else
256                    {
257 kumpf     1.6          propertyInfo.append(STRING_FALSE);
258 mike      1.2      }
259                }
260                
261 kumpf     1.29 /**
262                    Get default value of the specified property.
263 kumpf     1.6  */
264 vijay.eli 1.24 String TracePropertyOwner::getDefaultValue(const String& name) const
265 kumpf     1.6  {
266 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
267 kumpf     1.6      return configProperty->defaultValue;
268                }
269                
270 kumpf     1.29 /**
271                    Get current value of the specified property.
272 mike      1.2  */
273 vijay.eli 1.24 String TracePropertyOwner::getCurrentValue(const String& name) const
274 mike      1.2  {
275 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
276 kumpf     1.6      return configProperty->currentValue;
277 mike      1.2  }
278                
279 kumpf     1.29 /**
280                    Get planned value of the specified property.
281 mike      1.2  */
282 vijay.eli 1.24 String TracePropertyOwner::getPlannedValue(const String& name) const
283 mike      1.2  {
284 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
285 kumpf     1.6      return configProperty->plannedValue;
286 mike      1.2  }
287                
288 kumpf     1.29 /**
289                    Init current value of the specified property to the specified value.
290 mike      1.2  */
291                void TracePropertyOwner::initCurrentValue(
292 kumpf     1.29     const String& name,
293 mike      1.2      const String& value)
294                {
295                    if (String::equalNoCase(_traceComponents->propertyName, name))
296                    {
297 kumpf     1.29         if (_traceFilePath->currentValue != String::EMPTY &&
298                            value != String::EMPTY)
299 kumpf     1.8          {
300 kumpf     1.17             CString fileName = ConfigManager::getHomedPath(
301                                _traceFilePath->currentValue).getCString();
302 kumpf     1.29             if (Tracer::isValidFileName(fileName))
303                            {
304 kumpf     1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
305 kumpf     1.29                 // Check whether the filepath was set
306                                if ( retCode == 1 )
307                                {
308                                    Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
309                                        Logger::WARNING,
310                                        "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
311                                        "Unable to write to trace file $0",
312                                        (const char*)fileName);
313                                    _traceFilePath->currentValue = "";
314 kumpf     1.8                  }
315                            }
316                        }
317 kumpf     1.14         _traceComponents->currentValue = value;
318 kumpf     1.29         Tracer::setTraceComponents(_traceComponents->currentValue);
319 mike      1.2      }
320                    else if (String::equalNoCase(_traceLevel->propertyName, name))
321                    {
322 kumpf     1.5          _traceLevel->currentValue = value;
323 kumpf     1.29         Uint32 traceLevel = getTraceLevel(_traceLevel->currentValue);
324 mike      1.2          Tracer::setTraceLevel(traceLevel);
325                    }
326                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
327                    {
328 kumpf     1.5          _traceFilePath->currentValue = value;
329 kumpf     1.29         if (_traceFilePath->currentValue != String::EMPTY &&
330 kumpf     1.8              _traceComponents->currentValue != String::EMPTY)
331                        {
332 kumpf     1.17             CString fileName = ConfigManager::getHomedPath(
333                                _traceFilePath->currentValue).getCString();
334 kumpf     1.29             if (Tracer::isValidFileName(fileName))
335                            {
336 kumpf     1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
337 kumpf     1.8  
338 kumpf     1.29                 // Check whether the filepath was set
339                                if ( retCode == 1 )
340                                {
341                                     Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
342                                        Logger::WARNING,
343                                        "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
344                                        "Unable to write to trace file $0",
345                                        (const char*)fileName);
346                                    _traceFilePath->currentValue = "";
347 kumpf     1.8                  }
348                            }
349                        }
350 mike      1.2      }
351                    else
352                    {
353                        throw UnrecognizedConfigProperty(name);
354                    }
355                }
356                
357                
358 kumpf     1.29 /**
359                    Init planned value of the specified property to the specified value.
360 mike      1.2  */
361                void TracePropertyOwner::initPlannedValue(
362 kumpf     1.29     const String& name,
363 mike      1.2      const String& value)
364                {
365 kumpf     1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
366                    configProperty->plannedValue = value;
367 mike      1.2  }
368                
369 kumpf     1.29 /**
370                    Update current value of the specified property to the specified value.
371 mike      1.2  */
372                void TracePropertyOwner::updateCurrentValue(
373 kumpf     1.29     const String& name,
374                    const String& value)
375 mike      1.2  {
376                    //
377                    // make sure the property is dynamic before updating the value.
378                    //
379                    if (!isDynamic(name))
380                    {
381 kumpf     1.29         throw NonDynamicConfigProperty(name);
382 mike      1.2      }
383                
384                    //
385 kumpf     1.6      // Update does the same thing as initialization
386 mike      1.2      //
387 kumpf     1.6      initCurrentValue(name, value);
388 mike      1.2  }
389                
390                
391 kumpf     1.29 /**
392                    Update planned value of the specified property to the specified value.
393 mike      1.2  */
394                void TracePropertyOwner::updatePlannedValue(
395 kumpf     1.29     const String& name,
396 mike      1.2      const String& value)
397                {
398 kumpf     1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
399                    configProperty->plannedValue = value;
400 mike      1.2  }
401                
402 kumpf     1.29 /**
403                    Checks to see if the given value is valid or not.
404 mike      1.2  */
405 kumpf     1.29 Boolean TracePropertyOwner::isValid(
406                    const String& name,
407                    const String& value) const
408 mike      1.2  {
409                    if (String::equalNoCase(_traceComponents->propertyName, name))
410                    {
411 kumpf     1.29         String newValue          = value;
412                        String invalidComponents = String::EMPTY;
413 mike      1.2  
414 kumpf     1.29         //
415                        // Check if the trace components are valid
416                        //
417                        if (!Tracer::isValidComponents(newValue,invalidComponents))
418                        {
419                            throw InvalidPropertyValue(name, invalidComponents);
420 mike      1.2          }
421                
422 kumpf     1.6          return true;
423 mike      1.2      }
424                    else if (String::equalNoCase(_traceLevel->propertyName, name))
425                    {
426 kumpf     1.29         //
427 mike      1.2          // Check if the level is valid
428 kumpf     1.29         //
429 mike      1.2          if ( isLevelValid( value ) )
430                        {
431 kumpf     1.6              return true;
432 mike      1.2          }
433 kumpf     1.29         else
434                        {
435                            throw InvalidPropertyValue(name, value);
436 mike      1.2          }
437                    }
438                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
439                    {
440 kumpf     1.29         //
441 kumpf     1.20         // Check if the file path is valid.  An empty string is currently
442                        // considered a valid value; the traceFilePath is set to the empty
443                        // string when a trace file cannot be opened successfully.
444 kumpf     1.29         //
445 kumpf     1.20         if ((value != String::EMPTY) &&
446                            !Tracer::isValidFileName(value.getCString()))
447 kumpf     1.29         {
448                            throw InvalidPropertyValue(name, value);
449                        }
450 kumpf     1.6          return true;
451 mike      1.2      }
452                    else
453                    {
454                        throw UnrecognizedConfigProperty(name);
455                    }
456                }
457                
458 kumpf     1.29 /**
459                    Checks to see if the specified property is dynamic or not.
460 mike      1.2  */
461 vijay.eli 1.24 Boolean TracePropertyOwner::isDynamic(const String& name) const
462 mike      1.2  {
463 kumpf     1.29     struct ConfigProperty* configProperty = _lookupConfigProperty(name);
464                    return (configProperty->dynamic == IS_DYNAMIC);
465 mike      1.2  }
466                
467                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2