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