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

  1 karl  1.13 //%2003////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.13 // 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            // 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            // 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 karl  1.13 // 
 15 mike  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16            // 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            // 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            // 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            //==============================================================================
 25            //
 26            // Author: Nag Boranna (nagaraja_boranna@hp.com)
 27            //
 28            // Modified By: Yi Zhou (yi_zhou@hp.com)
 29            //              Sushma Fernandes (sushma_fernandes@hp.com)
 30            //
 31            //%/////////////////////////////////////////////////////////////////////////////
 32            
 33            
 34            ///////////////////////////////////////////////////////////////////////////////
 35            // 
 36 mike  1.2  // This file has implementation for the trace property owner class.
 37            //
 38            ///////////////////////////////////////////////////////////////////////////////
 39            
 40            #include <Pegasus/Common/Tracer.h>
 41            #include <Pegasus/Common/FileSystem.h>
 42            #include <Pegasus/Common/Destroyer.h>
 43 humberto 1.11 #include <Pegasus/Common/MessageLoader.h> //l10n
 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                   {"traceLevel", "1", 1, 0, 0, 0},
 63                   {"traceComponents", "", 1, 0, 0, 0},
 64               #else
 65                   {"traceLevel", "1", 1, 0, 0, 1},
 66                   {"traceComponents", "", 1, 0, 0, 1},
 67               #endif
 68                   {"traceFilePath", "cimserver.trc", 1, 0, 0, 1},
 69 mike     1.2  };
 70               
 71               const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 72               
 73               
 74               // 
 75               // Checks if the trace level is valid
 76               //
 77               Boolean isLevelValid(const String& traceLevel)
 78               {
 79                   //
 80                   // Check if the level is valid
 81                   //
 82                   if ( traceLevel == "1" || traceLevel == "2" || 
 83               	 traceLevel == "3" || traceLevel == "4")
 84                   {
 85                       return 1;
 86                   }
 87                   else
 88                   {
 89                       return 0; 
 90 mike     1.2      }
 91               }
 92               
 93               //
 94               // Get the appropriate trace level
 95               //
 96               Uint32 getTraceLevel(const String& traceLevel)
 97               {
 98                   if ( traceLevel == "1" )
 99                   {
100                       return (Tracer::LEVEL1);
101                   }
102                   else if ( traceLevel == "2" )
103                   {
104                       return (Tracer::LEVEL2);
105                   }
106                   else if ( traceLevel == "3" )
107                   {
108                       return (Tracer::LEVEL3);
109                   }
110                   else 
111 mike     1.2      {
112                       return (Tracer::LEVEL4);
113                   }
114               }
115               
116               /** Constructors  */
117               TracePropertyOwner::TracePropertyOwner()
118               {
119                   _traceLevel = new ConfigProperty;
120                   _traceFilePath = new ConfigProperty;
121                   _traceComponents = new ConfigProperty;
122               }
123               
124               /** Destructor  */
125               TracePropertyOwner::~TracePropertyOwner()
126               {
127                   delete _traceLevel;
128                   delete _traceFilePath;
129                   delete _traceComponents;
130               }
131               
132 mike     1.2  /**
133               Initialize the config properties.
134               */
135               void TracePropertyOwner::initialize()
136               {
137                   for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
138                   {
139                       //
140                       // Initialize the properties with default values
141                       //
142                       if (String::equalNoCase(properties[i].propertyName, "traceComponents"))
143                       {
144                           _traceComponents->propertyName = properties[i].propertyName;
145                           _traceComponents->defaultValue = properties[i].defaultValue;
146                           _traceComponents->currentValue = properties[i].defaultValue;
147                           _traceComponents->plannedValue = properties[i].defaultValue;
148                           _traceComponents->dynamic = properties[i].dynamic;
149                           _traceComponents->domain = properties[i].domain;
150                           _traceComponents->domainSize = properties[i].domainSize;
151 kumpf    1.12             _traceComponents->externallyVisible = properties[i].externallyVisible;
152 mike     1.2          }
153                       else if (String::equalNoCase(properties[i].propertyName, "traceLevel"))
154                       {
155                           _traceLevel->propertyName = properties[i].propertyName;
156                           _traceLevel->defaultValue = properties[i].defaultValue;
157                           _traceLevel->currentValue = properties[i].defaultValue;
158                           _traceLevel->plannedValue = properties[i].defaultValue;
159                           _traceLevel->dynamic = properties[i].dynamic;
160                           _traceLevel->domain = properties[i].domain;
161                           _traceLevel->domainSize = properties[i].domainSize;
162 kumpf    1.12             _traceLevel->externallyVisible = properties[i].externallyVisible;
163 mike     1.2          }
164                       else if (String::equalNoCase(properties[i].propertyName, "traceFilePath"))
165                       {
166                           _traceFilePath->propertyName = properties[i].propertyName;
167                           _traceFilePath->defaultValue = properties[i].defaultValue;
168                           _traceFilePath->currentValue = properties[i].defaultValue;
169                           _traceFilePath->plannedValue = properties[i].defaultValue;
170                           _traceFilePath->dynamic = properties[i].dynamic;
171                           _traceFilePath->domain = properties[i].domain;
172                           _traceFilePath->domainSize = properties[i].domainSize;
173 kumpf    1.12             _traceFilePath->externallyVisible = properties[i].externallyVisible;
174 mike     1.2          }
175                   }
176                   if (_traceFilePath->defaultValue != String::EMPTY)
177                   {
178 kumpf    1.8          String pegasusHome = ConfigManager::getPegasusHome();
179 mike     1.2  
180 kumpf    1.8  	// Set the file path to  $PEGASUS_HOME directory 
181                       _traceFilePath->defaultValue = pegasusHome + String("/") + 
182                                                         _traceFilePath->defaultValue;
183                       _traceFilePath->currentValue = _traceFilePath->defaultValue;
184                       _traceFilePath->plannedValue = _traceFilePath->defaultValue;
185                   }
186 mike     1.2  
187                   if (_traceLevel->defaultValue != String::EMPTY)
188                   {
189                       if (_traceLevel->defaultValue == "1")
190                       {
191                           Tracer::setTraceLevel(Tracer::LEVEL1);
192                       }
193                       else if (_traceLevel->defaultValue == "2")
194                       {
195                           Tracer::setTraceLevel(Tracer::LEVEL2);
196                       }
197                       else if (_traceLevel->defaultValue == "3")
198                       {
199                           Tracer::setTraceLevel(Tracer::LEVEL3);
200                       }
201                       else if (_traceLevel->defaultValue == "4")
202                       {
203                           Tracer::setTraceLevel(Tracer::LEVEL4);
204                       }
205                   }
206               }
207 mike     1.2  
208 kumpf    1.6  struct ConfigProperty* TracePropertyOwner::_lookupConfigProperty(
209                   const String& name)
210 mike     1.2  {
211                   if (String::equalNoCase(_traceComponents->propertyName, name))
212                   {
213 kumpf    1.6          return _traceComponents;
214 mike     1.2      }
215                   else if (String::equalNoCase(_traceLevel->propertyName, name))
216                   {
217 kumpf    1.6          return _traceLevel;
218 mike     1.2      }
219                   else if (String::equalNoCase(_traceFilePath->propertyName, name))
220                   {
221 kumpf    1.6          return _traceFilePath;
222 mike     1.2      }
223                   else
224                   {
225                       throw UnrecognizedConfigProperty(name);
226                   }
227               }
228               
229               /** 
230 kumpf    1.6  Get information about the specified property.
231 mike     1.2  */
232 kumpf    1.6  void TracePropertyOwner::getPropertyInfo(
233                   const String& name, 
234                   Array<String>& propertyInfo)
235 mike     1.2  {
236 kumpf    1.6      propertyInfo.clear();
237               
238                   struct ConfigProperty* configProperty = _lookupConfigProperty(name);
239               
240                   propertyInfo.append(configProperty->propertyName);
241                   propertyInfo.append(configProperty->defaultValue);
242                   propertyInfo.append(configProperty->currentValue);
243                   propertyInfo.append(configProperty->plannedValue);
244                   if (configProperty->dynamic)
245 kumpf    1.12     {
246                       propertyInfo.append(STRING_TRUE);
247                   }
248                   else
249                   {
250                       propertyInfo.append(STRING_FALSE);
251                   }
252                   if (configProperty->externallyVisible)
253 mike     1.2      {
254 kumpf    1.6          propertyInfo.append(STRING_TRUE);
255 mike     1.2      }
256                   else
257                   {
258 kumpf    1.6          propertyInfo.append(STRING_FALSE);
259 mike     1.2      }
260               }
261               
262               /** 
263 kumpf    1.6  Get default value of the specified property.
264               */
265               const String TracePropertyOwner::getDefaultValue(const String& name)
266               {
267                   struct ConfigProperty* configProperty = _lookupConfigProperty(name);
268                   return configProperty->defaultValue;
269               }
270               
271               /** 
272 mike     1.2  Get current value of the specified property.
273               */
274               const String TracePropertyOwner::getCurrentValue(const String& name)
275               {
276 kumpf    1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
277                   return configProperty->currentValue;
278 mike     1.2  }
279               
280               /** 
281               Get planned value of the specified property.
282               */
283               const String TracePropertyOwner::getPlannedValue(const String& name)
284               {
285 kumpf    1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
286                   return configProperty->plannedValue;
287 mike     1.2  }
288               
289               /** 
290               Init current value of the specified property to the specified value.
291               */
292               void TracePropertyOwner::initCurrentValue(
293                   const String& name, 
294                   const String& value)
295               {
296                   if (String::equalNoCase(_traceComponents->propertyName, name))
297                   {
298 kumpf    1.14         if (_traceFilePath->currentValue != String::EMPTY && value != String::EMPTY)
299 kumpf    1.8          {
300 kumpf    1.9              CString fileName = _traceFilePath->currentValue.getCString();
301               	    if (Tracer::isValidFileName(fileName))
302 kumpf    1.8  	    { 
303 kumpf    1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
304 kumpf    1.8  	        // Check whether the filepath was set
305               	        if ( retCode == 1 )
306               	        {
307 humberto 1.11 	        	//l10n
308               	            //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,
309               	              //  Logger::WARNING,
310               	                //"Unable to write to trace file $0",
311               	                //(const char*)fileName);
312               				Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
313 kumpf    1.8  	                Logger::WARNING,
314 humberto 1.11 	                "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
315 kumpf    1.9  	                "Unable to write to trace file $0",
316               	                (const char*)fileName);
317 kumpf    1.8  	            _traceFilePath->currentValue = "";
318                               }
319                           }
320                       }
321 kumpf    1.14         _traceComponents->currentValue = value;
322               	Tracer::setTraceComponents(_traceComponents->currentValue);
323 mike     1.2      }
324                   else if (String::equalNoCase(_traceLevel->propertyName, name))
325                   {
326 kumpf    1.5          _traceLevel->currentValue = value;
327 mike     1.2  	Uint32 traceLevel = getTraceLevel( _traceLevel->currentValue );
328                       Tracer::setTraceLevel(traceLevel);
329                   }
330                   else if (String::equalNoCase(_traceFilePath->propertyName, name))
331                   {
332 kumpf    1.5          _traceFilePath->currentValue = value;
333 kumpf    1.8          if (_traceFilePath->currentValue != String::EMPTY && 
334                           _traceComponents->currentValue != String::EMPTY)
335                       {
336 kumpf    1.9              CString fileName = _traceFilePath->currentValue.getCString();
337               	    if (Tracer::isValidFileName(fileName))
338 kumpf    1.8  	    { 
339 kumpf    1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
340 kumpf    1.8  
341               	        // Check whether the filepath was set
342               	        if ( retCode == 1 )
343               	        {
344 humberto 1.11 	        	//l10n
345               	            //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,
346               	             //Logger::WARNING,
347               	             //"Unable to write to trace file $0",
348               	             //(const char*)fileName);
349               	             Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
350               	                Logger::WARNING,
351               	                "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
352               	                "Unable to write to trace file $0",
353               	                (const char*)fileName);
354 kumpf    1.8  	            _traceFilePath->currentValue = "";
355                               }
356                           }
357                       }
358 mike     1.2      }
359                   else
360                   {
361                       throw UnrecognizedConfigProperty(name);
362                   }
363               }
364               
365               
366               /** 
367               Init planned value of the specified property to the specified value.
368               */
369               void TracePropertyOwner::initPlannedValue(
370                   const String& name, 
371                   const String& value)
372               {
373 kumpf    1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
374                   configProperty->plannedValue = value;
375 mike     1.2  }
376               
377               /** 
378               Update current value of the specified property to the specified value.
379               */
380               void TracePropertyOwner::updateCurrentValue(
381                   const String& name, 
382                   const String& value) 
383               {
384                   //
385                   // make sure the property is dynamic before updating the value.
386                   //
387                   if (!isDynamic(name))
388                   {
389                       throw NonDynamicConfigProperty(name); 
390                   }
391               
392                   //
393 kumpf    1.6      // Update does the same thing as initialization
394 mike     1.2      //
395 kumpf    1.6      initCurrentValue(name, value);
396 mike     1.2  }
397               
398               
399               /** 
400               Update planned value of the specified property to the specified value.
401               */
402               void TracePropertyOwner::updatePlannedValue(
403                   const String& name, 
404                   const String& value)
405               {
406 kumpf    1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
407                   configProperty->plannedValue = value;
408 mike     1.2  }
409               
410               /** 
411               Checks to see if the given value is valid or not.
412               */
413               Boolean TracePropertyOwner::isValid(const String& name, const String& value)
414               {
415                   if (String::equalNoCase(_traceComponents->propertyName, name))
416                   {
417               	String newValue          = value;
418               	String invalidComponents = String::EMPTY;
419               
420               	//
421               	// Check if the trace components are valid
422               	//
423 kumpf    1.4  	if (!Tracer::isValidComponents(newValue,invalidComponents))
424 mike     1.2  	{
425               	    throw InvalidPropertyValue(name, invalidComponents);
426                       }
427               
428 kumpf    1.6          return true;
429 mike     1.2      }
430                   else if (String::equalNoCase(_traceLevel->propertyName, name))
431                   {
432               	//
433                       // Check if the level is valid
434               	//
435                       if ( isLevelValid( value ) )
436                       {
437 kumpf    1.6              return true;
438 mike     1.2          }
439               	else
440               	{
441               	    throw InvalidPropertyValue(name, value);
442                       }
443                   }
444                   else if (String::equalNoCase(_traceFilePath->propertyName, name))
445                   {
446               	//
447                       // Check if the file path is valid
448               	//
449 kumpf    1.8          if ( value == String::EMPTY ) 
450                       {
451                           throw InvalidPropertyValue(name, value);
452                       }
453 kumpf    1.9  	if (!Tracer::isValidFileName(value.getCString()))
454 mike     1.2  	{
455               	    throw InvalidPropertyValue(name, value);
456               	}
457 kumpf    1.6          return true;
458 mike     1.2      }
459                   else
460                   {
461                       throw UnrecognizedConfigProperty(name);
462                   }
463               }
464               
465               /** 
466               Checks to see if the specified property is dynamic or not.
467               */
468               Boolean TracePropertyOwner::isDynamic(const String& name)
469               {
470 kumpf    1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
471                   return configProperty->dynamic;
472 mike     1.2  }
473               
474               
475               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2