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

  1 karl  1.22 //%2005////////////////////////////////////////////////////////////////////////
  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 mike  1.2  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13            // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16            // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 karl  1.13 // 
 19 mike  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Nag Boranna (nagaraja_boranna@hp.com)
 31            //
 32            // Modified By: Yi Zhou (yi_zhou@hp.com)
 33            //              Sushma Fernandes (sushma_fernandes@hp.com)
 34 aruran.ms 1.23 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3614
 35 vijay.eli 1.24 //              Vijay Eli, IBM, (vijayeli@in.ibm.com) for Bug# 3613
 36 aruran.ms 1.25 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3613
 37 mike      1.2  //
 38                //%/////////////////////////////////////////////////////////////////////////////
 39                
 40                
 41                ///////////////////////////////////////////////////////////////////////////////
 42                // 
 43                // This file has implementation for the trace property owner class.
 44                //
 45                ///////////////////////////////////////////////////////////////////////////////
 46                
 47                #include <Pegasus/Common/Tracer.h>
 48                #include <Pegasus/Common/FileSystem.h>
 49 humberto  1.11 #include <Pegasus/Common/MessageLoader.h> //l10n
 50 kumpf     1.3  #include "ConfigManager.h"
 51 mike      1.2  #include "TracePropertyOwner.h"
 52                
 53                
 54                PEGASUS_USING_STD;
 55                
 56                PEGASUS_NAMESPACE_BEGIN
 57                
 58                ///////////////////////////////////////////////////////////////////////////////
 59                //  TracePropertyOwner
 60                //
 61                //  When a new trace property is added, make sure to add the property name
 62                //  and the default attributes of that property in the table below.
 63                ///////////////////////////////////////////////////////////////////////////////
 64                
 65                static struct ConfigPropertyRow properties[] =
 66                {
 67 kumpf     1.12 #ifdef PEGASUS_OS_HPUX
 68 konrad.r  1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 69                    {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 70 kumpf     1.12 #else
 71 kumpf     1.15 #ifdef PEGASUS_USE_RELEASE_CONFIG_OPTIONS
 72 konrad.r  1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 73                    {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_HIDDEN},
 74 kumpf     1.15 #else
 75 konrad.r  1.21     {"traceLevel", "1", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 76                    {"traceComponents", "", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 77 kumpf     1.15 #endif
 78 kumpf     1.12 #endif
 79 konrad.r  1.21     {"traceFilePath", "cimserver.trc", IS_DYNAMIC, 0, 0, IS_VISIBLE},
 80 mike      1.2  };
 81                
 82                const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
 83                
 84                
 85                // 
 86                // Checks if the trace level is valid
 87                //
 88                Boolean isLevelValid(const String& traceLevel)
 89                {
 90                    //
 91                    // Check if the level is valid
 92                    //
 93                    if ( traceLevel == "1" || traceLevel == "2" || 
 94                	 traceLevel == "3" || traceLevel == "4")
 95                    {
 96                        return 1;
 97                    }
 98                    else
 99                    {
100                        return 0; 
101 mike      1.2      }
102                }
103                
104                //
105                // Get the appropriate trace level
106                //
107                Uint32 getTraceLevel(const String& traceLevel)
108                {
109                    if ( traceLevel == "1" )
110                    {
111                        return (Tracer::LEVEL1);
112                    }
113                    else if ( traceLevel == "2" )
114                    {
115                        return (Tracer::LEVEL2);
116                    }
117                    else if ( traceLevel == "3" )
118                    {
119                        return (Tracer::LEVEL3);
120                    }
121                    else 
122 mike      1.2      {
123                        return (Tracer::LEVEL4);
124                    }
125                }
126                
127                /** Constructors  */
128                TracePropertyOwner::TracePropertyOwner()
129                {
130 a.arora   1.16     _traceLevel.reset(new ConfigProperty);
131                    _traceFilePath.reset(new ConfigProperty);
132                    _traceComponents.reset(new ConfigProperty);
133 mike      1.2  }
134                
135                /**
136                Initialize the config properties.
137                */
138                void TracePropertyOwner::initialize()
139                {
140                    for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
141                    {
142                        //
143                        // Initialize the properties with default values
144                        //
145                        if (String::equalNoCase(properties[i].propertyName, "traceComponents"))
146                        {
147                            _traceComponents->propertyName = properties[i].propertyName;
148                            _traceComponents->defaultValue = properties[i].defaultValue;
149                            _traceComponents->currentValue = properties[i].defaultValue;
150                            _traceComponents->plannedValue = properties[i].defaultValue;
151                            _traceComponents->dynamic = properties[i].dynamic;
152                            _traceComponents->domain = properties[i].domain;
153                            _traceComponents->domainSize = properties[i].domainSize;
154 kumpf     1.12             _traceComponents->externallyVisible = properties[i].externallyVisible;
155 mike      1.2          }
156                        else if (String::equalNoCase(properties[i].propertyName, "traceLevel"))
157                        {
158                            _traceLevel->propertyName = properties[i].propertyName;
159                            _traceLevel->defaultValue = properties[i].defaultValue;
160                            _traceLevel->currentValue = properties[i].defaultValue;
161                            _traceLevel->plannedValue = properties[i].defaultValue;
162                            _traceLevel->dynamic = properties[i].dynamic;
163                            _traceLevel->domain = properties[i].domain;
164                            _traceLevel->domainSize = properties[i].domainSize;
165 kumpf     1.12             _traceLevel->externallyVisible = properties[i].externallyVisible;
166 mike      1.2          }
167                        else if (String::equalNoCase(properties[i].propertyName, "traceFilePath"))
168                        {
169                            _traceFilePath->propertyName = properties[i].propertyName;
170                            _traceFilePath->defaultValue = properties[i].defaultValue;
171                            _traceFilePath->currentValue = properties[i].defaultValue;
172                            _traceFilePath->plannedValue = properties[i].defaultValue;
173                            _traceFilePath->dynamic = properties[i].dynamic;
174                            _traceFilePath->domain = properties[i].domain;
175                            _traceFilePath->domainSize = properties[i].domainSize;
176 kumpf     1.12             _traceFilePath->externallyVisible = properties[i].externallyVisible;
177 mike      1.2          }
178                    }
179                
180                    if (_traceLevel->defaultValue != String::EMPTY)
181                    {
182                        if (_traceLevel->defaultValue == "1")
183                        {
184                            Tracer::setTraceLevel(Tracer::LEVEL1);
185                        }
186                        else if (_traceLevel->defaultValue == "2")
187                        {
188                            Tracer::setTraceLevel(Tracer::LEVEL2);
189                        }
190                        else if (_traceLevel->defaultValue == "3")
191                        {
192                            Tracer::setTraceLevel(Tracer::LEVEL3);
193                        }
194                        else if (_traceLevel->defaultValue == "4")
195                        {
196                            Tracer::setTraceLevel(Tracer::LEVEL4);
197                        }
198 mike      1.2      }
199                }
200                
201 kumpf     1.6  struct ConfigProperty* TracePropertyOwner::_lookupConfigProperty(
202 aruran.ms 1.25     const String& name) const
203 mike      1.2  {
204                    if (String::equalNoCase(_traceComponents->propertyName, name))
205                    {
206 a.arora   1.16         return _traceComponents.get();
207 mike      1.2      }
208                    else if (String::equalNoCase(_traceLevel->propertyName, name))
209                    {
210 a.arora   1.16         return _traceLevel.get();
211 mike      1.2      }
212                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
213                    {
214 a.arora   1.16         return _traceFilePath.get();
215 mike      1.2      }
216                    else
217                    {
218                        throw UnrecognizedConfigProperty(name);
219                    }
220                }
221                
222                /** 
223 kumpf     1.6  Get information about the specified property.
224 mike      1.2  */
225 kumpf     1.6  void TracePropertyOwner::getPropertyInfo(
226                    const String& name, 
227 vijay.eli 1.24     Array<String>& propertyInfo) const
228 mike      1.2  {
229 kumpf     1.6      propertyInfo.clear();
230                
231 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
232 kumpf     1.6  
233                    propertyInfo.append(configProperty->propertyName);
234                    propertyInfo.append(configProperty->defaultValue);
235                    propertyInfo.append(configProperty->currentValue);
236                    propertyInfo.append(configProperty->plannedValue);
237                    if (configProperty->dynamic)
238 kumpf     1.12     {
239                        propertyInfo.append(STRING_TRUE);
240                    }
241                    else
242                    {
243                        propertyInfo.append(STRING_FALSE);
244                    }
245                    if (configProperty->externallyVisible)
246 mike      1.2      {
247 kumpf     1.6          propertyInfo.append(STRING_TRUE);
248 mike      1.2      }
249                    else
250                    {
251 kumpf     1.6          propertyInfo.append(STRING_FALSE);
252 mike      1.2      }
253                }
254                
255                /** 
256 kumpf     1.6  Get default value of the specified property.
257                */
258 vijay.eli 1.24 String TracePropertyOwner::getDefaultValue(const String& name) const
259 kumpf     1.6  {
260 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
261 kumpf     1.6      return configProperty->defaultValue;
262                }
263                
264                /** 
265 mike      1.2  Get current value of the specified property.
266                */
267 vijay.eli 1.24 String TracePropertyOwner::getCurrentValue(const String& name) const
268 mike      1.2  {
269 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
270 kumpf     1.6      return configProperty->currentValue;
271 mike      1.2  }
272                
273                /** 
274                Get planned value of the specified property.
275                */
276 vijay.eli 1.24 String TracePropertyOwner::getPlannedValue(const String& name) const
277 mike      1.2  {
278 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
279 kumpf     1.6      return configProperty->plannedValue;
280 mike      1.2  }
281                
282                /** 
283                Init current value of the specified property to the specified value.
284                */
285                void TracePropertyOwner::initCurrentValue(
286                    const String& name, 
287                    const String& value)
288                {
289                    if (String::equalNoCase(_traceComponents->propertyName, name))
290                    {
291 kumpf     1.14         if (_traceFilePath->currentValue != String::EMPTY && value != String::EMPTY)
292 kumpf     1.8          {
293 kumpf     1.17             CString fileName = ConfigManager::getHomedPath(
294                                _traceFilePath->currentValue).getCString();
295 kumpf     1.9  	    if (Tracer::isValidFileName(fileName))
296 kumpf     1.8  	    { 
297 kumpf     1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
298 kumpf     1.8  	        // Check whether the filepath was set
299                	        if ( retCode == 1 )
300                	        {
301 humberto  1.11 	        	//l10n
302                	            //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,
303                	              //  Logger::WARNING,
304                	                //"Unable to write to trace file $0",
305                	                //(const char*)fileName);
306                				Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
307 kumpf     1.8  	                Logger::WARNING,
308 humberto  1.11 	                "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
309 kumpf     1.9  	                "Unable to write to trace file $0",
310                	                (const char*)fileName);
311 kumpf     1.8  	            _traceFilePath->currentValue = "";
312                                }
313                            }
314                        }
315 kumpf     1.14         _traceComponents->currentValue = value;
316                	Tracer::setTraceComponents(_traceComponents->currentValue);
317 mike      1.2      }
318                    else if (String::equalNoCase(_traceLevel->propertyName, name))
319                    {
320 kumpf     1.5          _traceLevel->currentValue = value;
321 mike      1.2  	Uint32 traceLevel = getTraceLevel( _traceLevel->currentValue );
322                        Tracer::setTraceLevel(traceLevel);
323                    }
324                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
325                    {
326 kumpf     1.5          _traceFilePath->currentValue = value;
327 kumpf     1.8          if (_traceFilePath->currentValue != String::EMPTY && 
328                            _traceComponents->currentValue != String::EMPTY)
329                        {
330 kumpf     1.17             CString fileName = ConfigManager::getHomedPath(
331                                _traceFilePath->currentValue).getCString();
332 kumpf     1.9  	    if (Tracer::isValidFileName(fileName))
333 kumpf     1.8  	    { 
334 kumpf     1.9                  Uint32 retCode = Tracer::setTraceFile(fileName);
335 kumpf     1.8  
336                	        // Check whether the filepath was set
337                	        if ( retCode == 1 )
338                	        {
339 humberto  1.11 	        	//l10n
340                	            //Logger::put(Logger::DEBUG_LOG,System::CIMSERVER,
341                	             //Logger::WARNING,
342                	             //"Unable to write to trace file $0",
343                	             //(const char*)fileName);
344                	             Logger::put_l(Logger::DEBUG_LOG,System::CIMSERVER,
345                	                Logger::WARNING,
346                	                "Config.TracePropertyOwner.UNABLE_TO_WRITE_TRACE_FILE",
347                	                "Unable to write to trace file $0",
348                	                (const char*)fileName);
349 kumpf     1.8  	            _traceFilePath->currentValue = "";
350                                }
351                            }
352                        }
353 mike      1.2      }
354                    else
355                    {
356                        throw UnrecognizedConfigProperty(name);
357                    }
358                }
359                
360                
361                /** 
362                Init planned value of the specified property to the specified value.
363                */
364                void TracePropertyOwner::initPlannedValue(
365                    const String& name, 
366                    const String& value)
367                {
368 kumpf     1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
369                    configProperty->plannedValue = value;
370 mike      1.2  }
371                
372                /** 
373                Update current value of the specified property to the specified value.
374                */
375                void TracePropertyOwner::updateCurrentValue(
376                    const String& name, 
377                    const String& value) 
378                {
379                    //
380                    // make sure the property is dynamic before updating the value.
381                    //
382                    if (!isDynamic(name))
383                    {
384                        throw NonDynamicConfigProperty(name); 
385                    }
386                
387                    //
388 kumpf     1.6      // Update does the same thing as initialization
389 mike      1.2      //
390 kumpf     1.6      initCurrentValue(name, value);
391 mike      1.2  }
392                
393                
394                /** 
395                Update planned value of the specified property to the specified value.
396                */
397                void TracePropertyOwner::updatePlannedValue(
398                    const String& name, 
399                    const String& value)
400                {
401 kumpf     1.6      struct ConfigProperty* configProperty = _lookupConfigProperty(name);
402                    configProperty->plannedValue = value;
403 mike      1.2  }
404                
405                /** 
406                Checks to see if the given value is valid or not.
407                */
408 vijay.eli 1.24 Boolean TracePropertyOwner::isValid(const String& name, const String& value) const
409 mike      1.2  {
410                    if (String::equalNoCase(_traceComponents->propertyName, name))
411                    {
412                	String newValue          = value;
413                	String invalidComponents = String::EMPTY;
414                
415                	//
416                	// Check if the trace components are valid
417                	//
418 kumpf     1.4  	if (!Tracer::isValidComponents(newValue,invalidComponents))
419 mike      1.2  	{
420                	    throw InvalidPropertyValue(name, invalidComponents);
421                        }
422                
423 kumpf     1.6          return true;
424 mike      1.2      }
425                    else if (String::equalNoCase(_traceLevel->propertyName, name))
426                    {
427                	//
428                        // Check if the level is valid
429                	//
430                        if ( isLevelValid( value ) )
431                        {
432 kumpf     1.6              return true;
433 mike      1.2          }
434                	else
435                	{
436                	    throw InvalidPropertyValue(name, value);
437                        }
438                    }
439                    else if (String::equalNoCase(_traceFilePath->propertyName, name))
440                    {
441                	//
442 kumpf     1.20         // Check if the file path is valid.  An empty string is currently
443                        // considered a valid value; the traceFilePath is set to the empty
444                        // string when a trace file cannot be opened successfully.
445 mike      1.2  	//
446 kumpf     1.20         if ((value != String::EMPTY) &&
447                            !Tracer::isValidFileName(value.getCString()))
448 mike      1.2  	{
449                	    throw InvalidPropertyValue(name, value);
450                	}
451 kumpf     1.6          return true;
452 mike      1.2      }
453                    else
454                    {
455                        throw UnrecognizedConfigProperty(name);
456                    }
457                }
458                
459                /** 
460                Checks to see if the specified property is dynamic or not.
461                */
462 vijay.eli 1.24 Boolean TracePropertyOwner::isDynamic(const String& name) const
463 mike      1.2  {
464 aruran.ms 1.25     struct ConfigProperty * configProperty = _lookupConfigProperty(name);
465 konrad.r  1.21     return (configProperty->dynamic==IS_DYNAMIC);
466 mike      1.2  }
467                
468                
469                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2