1 karl 1.34 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.24 // 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.21 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.24 // 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.27 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.34 // 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.34 //
|
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: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
33 //
|
34 kumpf 1.5 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
|
35 a.arora 1.22 // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
|
36 kumpf 1.23 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
37 joyce.j 1.26 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2498
|
38 gs.keenan 1.28 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
|
39 david.dillard 1.32 // David Dillard, Symantec Corp. (david_dillard@symantec.com)
|
40 aruran.ms 1.33 // Aruran, IBM (ashanmug@in.ibm.com) for Bug# 4547
|
41 mike 1.2 //
42 //%/////////////////////////////////////////////////////////////////////////////
43
|
44 sage 1.4 #include <Pegasus/Common/Config.h>
|
45 mike 1.2 #include <Pegasus/Common/Tracer.h>
|
46 kumpf 1.3 #include <Pegasus/Common/Thread.h>
47 #include <Pegasus/Common/System.h>
|
48 mike 1.2
49 PEGASUS_USING_STD;
50
51 PEGASUS_NAMESPACE_BEGIN
52
53 // Set the trace levels
54 // These levels will be compared against a trace level mask to determine
|
55 chip 1.20 // if a specific trace level is enabled
|
56 mike 1.2
57 const Uint32 Tracer::LEVEL1 = (1 << 0);
58 const Uint32 Tracer::LEVEL2 = (1 << 1);
59 const Uint32 Tracer::LEVEL3 = (1 << 2);
60 const Uint32 Tracer::LEVEL4 = (1 << 3);
61
62 // Set the return codes
63 const Boolean Tracer::_SUCCESS = 1;
64 const Boolean Tracer::_FAILURE = 0;
65
66 // Set the Enter and Exit messages
|
67 kumpf 1.13 const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
68 const char Tracer::_METHOD_EXIT_MSG[] = "Exiting method";
|
69 mike 1.2
70 // Set Log messages
|
71 kumpf 1.13 const char Tracer::_LOG_MSG[] = "LEVEL1 may only be used with trace macros PEG_METHOD_ENTER/PEG_METHOD_EXIT.";
|
72 mike 1.2
73 // Initialize singleton instance of Tracer
74 Tracer* Tracer::_tracerInstance = 0;
|
75 chip 1.20
|
76 mike 1.2 // Set component separator
77 const char Tracer::_COMPONENT_SEPARATOR = ',';
78
79 // Set the number of defined components
|
80 chip 1.20 const Uint32 Tracer::_NUM_COMPONENTS =
|
81 mike 1.2 sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]);
82
83 // Set the line maximum
84 const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
85
|
86 kumpf 1.3 // Set the max PID and Thread ID Length
87 const Uint32 Tracer::_STRLEN_MAX_PID_TID = 20;
88
|
89 r.kieninger 1.30 // Initialize public indicator of trace state
|
90 david.dillard 1.32 Boolean Tracer::_traceOn = false;
|
91 r.kieninger 1.30
|
92 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
93 // Tracer constructor
94 // Constructor is private to preclude construction of Tracer objects
95 // Single Instance of Tracer is maintained for each process.
96 ////////////////////////////////////////////////////////////////////////////////
97 Tracer::Tracer()
|
98 aruran.ms 1.33 : _traceComponentMask(new Boolean[_NUM_COMPONENTS]),
99 _traceLevelMask(0),
100 _traceHandler(new TraceFileHandler())
|
101 mike 1.2 {
102 // Initialize ComponentMask array to false
|
103 chip 1.20 for (Uint32 index=0;index < _NUM_COMPONENTS;
|
104 david.dillard 1.32 (_traceComponentMask.get())[index++]=false);
|
105 mike 1.2 }
|
106 chip 1.20
|
107 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
108 //Tracer destructor
109 ////////////////////////////////////////////////////////////////////////////////
110 Tracer::~Tracer()
111 {
112 delete _tracerInstance;
113 }
114
115
116 ////////////////////////////////////////////////////////////////////////////////
117 //Traces the given message
118 ////////////////////////////////////////////////////////////////////////////////
119 void Tracer::_trace(
120 const Uint32 traceComponent,
121 const Uint32 traceLevel,
122 const char* fmt,
123 va_list argList)
124 {
125 if ( traceLevel == LEVEL1 )
126 {
|
127 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
128 mike 1.2 }
129 else
130 {
131 if (_isTraceEnabled(traceComponent,traceLevel))
132 {
|
133 chip 1.20 _trace(traceComponent,"",fmt,argList);
|
134 david.dillard 1.32 }
|
135 mike 1.2 }
136 }
137
138 ////////////////////////////////////////////////////////////////////////////////
139 //Traces the given message - Overloaded for including FileName and Line number
140 ////////////////////////////////////////////////////////////////////////////////
141 void Tracer::_trace(
142 const char* fileName,
143 const Uint32 lineNum,
144 const Uint32 traceComponent,
145 const Uint32 traceLevel,
146 const char* fmt,
147 va_list argList)
148 {
149 char* message;
150
151 if ( traceLevel == LEVEL1 )
152 {
|
153 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
154 mike 1.2 }
155 else
156 {
157 if (_isTraceEnabled(traceComponent,traceLevel))
158 {
|
159 kumpf 1.3 //
160 // Allocate memory for the message string
161 // Needs to be updated if additional info is added
162 //
|
163 david.dillard 1.32 message = new char[ strlen(fileName) +
164 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
|
165 kumpf 1.3 sprintf(
166 message,
|
167 gs.keenan 1.28 #if defined(PEGASUS_OS_VMS)
168 //
|
169 mike 1.36 // Threads::self returns long-long-unsigned.
|
170 gs.keenan 1.28 //
|
171 gs.keenan 1.29 "[%d:%llu:%s:%u]: ",
172 // "[%x:%llx:%s:%u]: ",
|
173 gs.keenan 1.28 System::getPID(),
|
174 mike 1.36 Threads::self(),
|
175 gs.keenan 1.28 #else
|
176 kumpf 1.9 "[%d:%u:%s:%u]: ",
|
177 kumpf 1.3 System::getPID(),
|
178 mike 1.36 Uint32(Threads::id()),
|
179 gs.keenan 1.28 #endif
|
180 kumpf 1.3 fileName,
181 lineNum);
|
182 mike 1.2
|
183 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
184 david.dillard 1.32 delete []message;
|
185 mike 1.2 }
186 }
187 }
188
189 ////////////////////////////////////////////////////////////////////////////////
190 //Traces the given buffer
191 ////////////////////////////////////////////////////////////////////////////////
192 void Tracer::_traceBuffer(
193 const Uint32 traceComponent,
194 const Uint32 traceLevel,
195 const char* data,
196 const Uint32 size)
197 {
198 if ( traceLevel == LEVEL1 )
199 {
|
200 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
201 mike 1.2 }
202 else
203 {
204 if (_isTraceEnabled(traceComponent,traceLevel))
205 {
206 char* tmpBuf = new char[size+1];
207
208 strncpy( tmpBuf, data, size );
209 tmpBuf[size] = '\0';
210 trace(traceComponent,traceLevel,"%s",tmpBuf);
211
212 delete []tmpBuf;
213 }
214 }
215 }
216 ////////////////////////////////////////////////////////////////////////////////
217 //Traces the given buffer - Overloaded for including FileName and Line number
218 ////////////////////////////////////////////////////////////////////////////////
219 void Tracer::_traceBuffer(
220 const char* fileName,
221 const Uint32 lineNum,
222 mike 1.2 const Uint32 traceComponent,
223 const Uint32 traceLevel,
224 const char* data,
225 const Uint32 size)
226 {
227 if ( traceLevel == LEVEL1 )
228 {
|
229 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
230 mike 1.2 }
231 else
232 {
233 if ( _isTraceEnabled( traceComponent, traceLevel ) )
234 {
235 char* tmpBuf = new char[size+1];
236
237 strncpy( tmpBuf, data, size );
238 tmpBuf[size] = '\0';
239 trace(fileName,lineNum,traceComponent,traceLevel,"%s",tmpBuf);
240
241 delete []tmpBuf;
|
242 kumpf 1.5 }
243 }
244 }
245
246 ////////////////////////////////////////////////////////////////////////////////
247 //Traces the given string
248 ////////////////////////////////////////////////////////////////////////////////
249 void Tracer::_traceString(
250 const Uint32 traceComponent,
251 const Uint32 traceLevel,
252 const String& traceString)
253 {
254 if ( traceLevel == LEVEL1 )
255 {
|
256 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
257 kumpf 1.5 }
258 else
259 {
260 if (_isTraceEnabled(traceComponent,traceLevel))
261 {
|
262 kumpf 1.18 trace(traceComponent,traceLevel,"%s",
263 (const char *)traceString.getCString());
|
264 kumpf 1.5 }
265 }
266 }
267
268 ////////////////////////////////////////////////////////////////////////////////
269 //Traces the given string - Overloaded to include the fileName and line number
270 //of trace origin.
271 ////////////////////////////////////////////////////////////////////////////////
272 void Tracer::_traceString(
273 const char* fileName,
274 const Uint32 lineNum,
275 const Uint32 traceComponent,
276 const Uint32 traceLevel,
277 const String& traceString)
278 {
279 if ( traceLevel == LEVEL1 )
280 {
|
281 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
282 kumpf 1.5 }
283 else
284 {
285 if ( _isTraceEnabled( traceComponent, traceLevel ) )
286 {
|
287 kumpf 1.18 trace(fileName,lineNum,traceComponent,traceLevel,"%s",
288 (const char *)traceString.getCString());
|
289 kumpf 1.5 }
290 }
291 }
292
293 ////////////////////////////////////////////////////////////////////////////////
294 //Traces the message in the given CIMException object.
295 ////////////////////////////////////////////////////////////////////////////////
296 void Tracer::_traceCIMException(
297 const Uint32 traceComponent,
298 const Uint32 traceLevel,
299 CIMException cimException)
300 {
301 if ( traceLevel == LEVEL1 )
302 {
|
303 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
304 kumpf 1.5 }
305 else
306 {
307 if ( _isTraceEnabled( traceComponent, traceLevel ) )
308 {
309 // get the CIMException trace message string
|
310 kumpf 1.15 String traceMsg =
311 TraceableCIMException(cimException).getTraceDescription();
|
312 kumpf 1.5
313 // trace the string
314 _traceString(traceComponent, traceLevel, traceMsg);
|
315 mike 1.2 }
316 }
317 }
318
319 ////////////////////////////////////////////////////////////////////////////////
320 //Traces method entry
321 ////////////////////////////////////////////////////////////////////////////////
322 void Tracer::_traceEnter(
323 const char* fileName,
324 const Uint32 lineNum,
325 const Uint32 traceComponent,
326 const char* fmt,
327 ...)
328 {
329 va_list argList;
330 char* message;
331
332 if (_isTraceEnabled(traceComponent,LEVEL1))
333 {
|
334 kumpf 1.3
|
335 mike 1.2 va_start(argList,fmt);
336
|
337 kumpf 1.3 //
338 // Allocate memory for the message string
339 // Needs to be updated if additional info is added
340 //
|
341 david.dillard 1.32 message = new char[ strlen(fileName) +
342 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
|
343 r.kieninger 1.30
|
344 gs.keenan 1.28 #if defined(PEGASUS_OS_VMS)
345 //
|
346 mike 1.36 // Threads::self returns long-long-unsigned.
|
347 gs.keenan 1.28 //
348 sprintf(
349 message,
350 "[%d:%llu:%s:%u]: ",
351 System::getPID(),
|
352 mike 1.36 Threads::self(),
|
353 gs.keenan 1.28 fileName,
354 lineNum);
355 #else
|
356 kumpf 1.3 sprintf(
357 message,
|
358 kumpf 1.9 "[%d:%u:%s:%u]: ",
|
359 kumpf 1.3 System::getPID(),
|
360 mike 1.36 Uint32(Threads::id()),
|
361 kumpf 1.3 fileName,
362 lineNum);
|
363 gs.keenan 1.28 #endif
|
364 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
365 mike 1.2
366 va_end(argList);
367 delete []message;
368 }
369 }
370
371 ////////////////////////////////////////////////////////////////////////////////
372 //Traces method exit
373 ////////////////////////////////////////////////////////////////////////////////
374 void Tracer::_traceExit(
375 const char* fileName,
376 const Uint32 lineNum,
377 const Uint32 traceComponent,
378 const char* fmt
379 ...)
380 {
381 va_list argList;
382 char* message;
383
384 if (_isTraceEnabled(traceComponent,LEVEL1))
385 {
386 mike 1.2 va_start(argList,fmt);
|
387 chip 1.20
|
388 kumpf 1.3 //
389 // Allocate memory for the message string
390 // Needs to be updated if additional info is added
391 //
|
392 david.dillard 1.32 message = new char[ strlen(fileName) +
393 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
|
394 r.kieninger 1.30
|
395 gs.keenan 1.28 #if defined(PEGASUS_OS_VMS)
396 //
|
397 mike 1.36 // Threads::self returns long-long-unsigned.
|
398 gs.keenan 1.28 //
399 sprintf(
400 message,
401 "[%d:%llu:%s:%u]: ",
402 System::getPID(),
|
403 mike 1.36 Threads::self(),
|
404 gs.keenan 1.28 fileName,
405 lineNum);
406 #else
|
407 kumpf 1.3 sprintf(
408 message,
|
409 kumpf 1.9 "[%d:%u:%s:%u]: ",
|
410 kumpf 1.3 System::getPID(),
|
411 mike 1.36 Uint32(Threads::id()),
|
412 kumpf 1.3 fileName,
413 lineNum);
|
414 gs.keenan 1.28 #endif
|
415 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
416 mike 1.2 va_end(argList);
417
418 delete []message;
419 }
420 }
421
422 ////////////////////////////////////////////////////////////////////////////////
423 //Checks if trace is enabled for the given component and level
424 ////////////////////////////////////////////////////////////////////////////////
425 Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,
426 const Uint32 traceLevel)
427 {
428 Tracer* instance = _getInstance();
429 if (traceComponent >= _NUM_COMPONENTS)
430 {
|
431 david.dillard 1.32 return false;
|
432 mike 1.2 }
|
433 a.arora 1.22 return (((instance->_traceComponentMask.get())[traceComponent]) &&
|
434 david.dillard 1.32 (traceLevel & instance->_traceLevelMask));
|
435 mike 1.2 }
436
437 ////////////////////////////////////////////////////////////////////////////////
438 //Called by all trace interfaces to log message to trace file
439 ////////////////////////////////////////////////////////////////////////////////
440 void Tracer::_trace(
441 const Uint32 traceComponent,
442 const char* message,
443 const char* fmt,
444 va_list argList)
445 {
446 char* msgHeader;
447
448 // Get the current system time and prepend to message
449 String currentTime = System::getCurrentASCIITime();
|
450 kumpf 1.17 CString timeStamp = currentTime.getCString();
|
451 mike 1.2
|
452 kumpf 1.3 //
|
453 chip 1.20 // Allocate messageHeader.
|
454 kumpf 1.3 // Needs to be updated if additional info is added
455 //
|
456 mday 1.19
457
|
458 mike 1.2
459 // Construct the message header
|
460 chip 1.20 // The message header is in the following format
|
461 mike 1.2 // timestamp: <component name> [file name:line number]
|
462 joyce.j 1.26 if (*message != '\0')
|
463 mike 1.2 {
|
464 mday 1.19 // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used in this format string
465 msgHeader = new char [strlen(message)
|
466 david.dillard 1.32 + strlen(TRACE_COMPONENT_LIST[traceComponent])
467 + strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
|
468 chip 1.20
|
469 kumpf 1.17 sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,
|
470 mike 1.2 TRACE_COMPONENT_LIST[traceComponent] ,message);
|
471 chip 1.20 //delete [] msgHeader;
|
472 mike 1.2 }
473 else
474 {
|
475 kumpf 1.3 //
476 // Since the message is blank form a string using the pid and tid
477 //
478 char* tmpBuffer;
479
480 //
|
481 chip 1.20 // Allocate messageHeader.
|
482 kumpf 1.3 // Needs to be updated if additional info is added
483 //
|
484 david.dillard 1.32 tmpBuffer = new char[_STRLEN_MAX_PID_TID + 6];
|
485 gs.keenan 1.28 #if defined(PEGASUS_OS_VMS)
486 //
|
487 mike 1.36 // Threads::self returns long-long-unsigned.
|
488 gs.keenan 1.28 //
489 sprintf(tmpBuffer, "[%u:%llu]: ", System::getPID(),
|
490 mike 1.36 Threads::self());
|
491 gs.keenan 1.28 #else
|
492 kumpf 1.9 sprintf(tmpBuffer, "[%u:%u]: ", System::getPID(),
|
493 mike 1.36 Uint32(Threads::id()));
|
494 gs.keenan 1.28 #endif
|
495 david.dillard 1.32 msgHeader = new char [ strlen(timeStamp) + strlen(TRACE_COMPONENT_LIST[traceComponent]) +
496 strlen(tmpBuffer) + 1 + 5 ];
|
497 r.kieninger 1.30
|
498 kumpf 1.17 sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,
|
499 kumpf 1.3 TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );
500 delete []tmpBuffer;
|
501 chip 1.20 //delete [] msgHeader;
|
502 r.kieninger 1.30
|
503 mike 1.2 }
504
505 // Call trace file handler to write message
506 _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);
|
507 chip 1.20
508 delete [] msgHeader;
|
509 mike 1.2 }
510
511 ////////////////////////////////////////////////////////////////////////////////
512 //Validate the trace file
513 ////////////////////////////////////////////////////////////////////////////////
|
514 kumpf 1.10 Boolean Tracer::isValidFileName(const char* filePath)
|
515 mike 1.2 {
|
516 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
517 if (moduleName == String::EMPTY)
518 {
519 return (_getInstance()->_traceHandler->isValidFilePath(filePath));
520 }
521 else
522 {
523 String extendedFilePath = String(filePath) + "." + moduleName;
524 return (_getInstance()->_traceHandler->isValidFilePath(
525 extendedFilePath.getCString()));
526 }
|
527 mike 1.2 }
528
529 ////////////////////////////////////////////////////////////////////////////////
530 //Validate the trace components
531 ////////////////////////////////////////////////////////////////////////////////
|
532 kumpf 1.23 Boolean Tracer::isValidComponents(const String& traceComponents)
|
533 kumpf 1.10 {
534 String invalidComponents;
535 return isValidComponents(traceComponents, invalidComponents);
536 }
537
538 Boolean Tracer::isValidComponents(
|
539 kumpf 1.23 const String& traceComponents, String& invalidComponents)
|
540 mike 1.2 {
541 // Validate the trace components and modify the traceComponents argument
542 // to reflect the invalid components
543
544 Uint32 position=0;
545 Uint32 index=0;
546 String componentName = String::EMPTY;
547 String componentStr = String::EMPTY;
548 Boolean validComponent=false;
549 Boolean retCode=true;
550
551 componentStr = traceComponents;
552 invalidComponents = String::EMPTY;
553
554 if (componentStr != String::EMPTY)
555 {
556 // Check if ALL is specified
557 if (String::equalNoCase(componentStr,"ALL"))
558 {
559 return _SUCCESS;
560 }
561 mike 1.2
562 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
563 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
564 mike 1.2
565 while (componentStr != String::EMPTY)
566 {
|
567 david.dillard 1.32 //
|
568 mike 1.2 // Get the Component name from traceComponents.
569 // Components are separated by _COMPONENT_SEPARATOR
|
570 david.dillard 1.32 //
|
571 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
572 componentName = componentStr.subString(0,(position));
573
574 // Lookup the index for Component name in TRACE_COMPONENT_LIST
575 index = 0;
576 validComponent = false;
577
578 while (index < _NUM_COMPONENTS)
579 {
|
580 chip 1.20 if (String::equalNoCase(
|
581 david.dillard 1.32 componentName, TRACE_COMPONENT_LIST[index]))
|
582 mike 1.2 {
583 // Found component, break from the loop
|
584 david.dillard 1.32 validComponent = true;
|
585 mike 1.2 break;
586 }
587 else
588 {
589 index++;
590 }
591 }
592
593 // Remove the searched componentname from the traceComponents
594 componentStr.remove(0,position+1);
595
|
596 david.dillard 1.32 if ( !validComponent )
597 {
598 invalidComponents.append(componentName);
599 invalidComponents.append(_COMPONENT_SEPARATOR);
|
600 mike 1.2 }
601 }
602 }
603 else
604 {
|
605 david.dillard 1.32 // trace components is empty, it is a valid value so return true
606 return _SUCCESS;
|
607 mike 1.2 }
608 if ( invalidComponents != String::EMPTY )
609 {
|
610 david.dillard 1.32 retCode = false;
611 //
612 // Remove the extra ',' at the end
613 //
614 invalidComponents.remove(
615 invalidComponents.reverseFind(_COMPONENT_SEPARATOR));
|
616 mike 1.2 }
617 return retCode;
618 }
|
619 chip 1.20
|
620 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
621 kumpf 1.23 //Set the name of the module being traced
622 ////////////////////////////////////////////////////////////////////////////////
623 void Tracer::setModuleName(const String& moduleName)
624 {
625 _getInstance()->_moduleName = moduleName;
626 }
627
628 ////////////////////////////////////////////////////////////////////////////////
|
629 mike 1.2 //Returns the Singleton instance of the Tracer
630 ////////////////////////////////////////////////////////////////////////////////
631 Tracer* Tracer::_getInstance()
632 {
633 if (_tracerInstance == 0)
634 {
635 _tracerInstance = new Tracer();
636 }
637 return _tracerInstance;
638 }
639
|
640 chip 1.20 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
|
641 karl 1.35 // interfaces. This section defines the trace functions IF the remove
642 // trace flag is NOT set. If it is set, they are defined as empty functions
643 // in the header file.
|
644 mike 1.2
645 #ifndef PEGASUS_REMOVE_TRACE
646
647 ////////////////////////////////////////////////////////////////////////////////
648 //Set the trace file
649 ////////////////////////////////////////////////////////////////////////////////
650 Uint32 Tracer::setTraceFile(const char* traceFile)
651 {
|
652 kumpf 1.25 if (*traceFile == 0)
653 {
654 return 1;
655 }
656
|
657 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
658 if (moduleName == String::EMPTY)
659 {
660 return (_getInstance()->_traceHandler->setFileName(traceFile));
661 }
662 else
663 {
664 String extendedTraceFile = String(traceFile) + "." + moduleName;
665 return (_getInstance()->_traceHandler->setFileName(
666 extendedTraceFile.getCString()));
667 }
|
668 chip 1.20 }
|
669 mike 1.2
670 ////////////////////////////////////////////////////////////////////////////////
671 //Set the trace level
672 ////////////////////////////////////////////////////////////////////////////////
673 Uint32 Tracer::setTraceLevel(const Uint32 traceLevel)
674 {
675 Uint32 retCode = 0;
676
677 switch (traceLevel)
678 {
|
679 david.dillard 1.32 case LEVEL1:
|
680 mike 1.2 _getInstance()->_traceLevelMask = 0x01;
|
681 david.dillard 1.32 break;
|
682 chip 1.20
|
683 mike 1.2 case LEVEL2:
684 _getInstance()->_traceLevelMask = 0x03;
|
685 david.dillard 1.32 break;
|
686 mike 1.2
687 case LEVEL3:
688 _getInstance()->_traceLevelMask = 0x07;
|
689 david.dillard 1.32 break;
|
690 mike 1.2
691 case LEVEL4:
692 _getInstance()->_traceLevelMask = 0x0F;
|
693 david.dillard 1.32 break;
|
694 mike 1.2
695 default:
696 _getInstance()->_traceLevelMask = 0;
697 retCode = 1;
698 }
699 return retCode;
700 }
701
702 ////////////////////////////////////////////////////////////////////////////////
|
703 chip 1.20 // Set components to be traced.
|
704 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
705 kumpf 1.23 void Tracer::setTraceComponents(const String& traceComponents)
|
706 mike 1.2 {
707 Uint32 position = 0;
708 Uint32 index = 0;
709 String componentName = String::EMPTY;
710 String componentStr = traceComponents;
711 String invalidComponents = String::EMPTY;
|
712 chip 1.20
|
713 mike 1.2 if (componentStr != String::EMPTY)
714 {
715 // Check if ALL is specified
716 if (String::equalNoCase(componentStr,"ALL"))
717 {
718 for (index=0; index < _NUM_COMPONENTS;
|
719 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index++] = true);
|
720 david.dillard 1.32 _traceOn = true;
|
721 chip 1.20 return ;
|
722 mike 1.2 }
723
724 // initialise ComponentMask array to False
|
725 chip 1.20 for (index = 0;index < _NUM_COMPONENTS;
|
726 r.kieninger 1.30 (_getInstance()->_traceComponentMask.get())[index++] = false);
|
727 david.dillard 1.32 _traceOn = false;
|
728 mike 1.2
|
729 r.kieninger 1.30 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
730 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
731 mike 1.2
732 while (componentStr != String::EMPTY)
733 {
|
734 chip 1.20 // Get the Component name from traceComponents.
|
735 r.kieninger 1.30 // Components are separated by _COMPONENT_SEPARATOR
|
736 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
|
737 r.kieninger 1.30 componentName = componentStr.subString(0,(position));
|
738 mike 1.2
|
739 r.kieninger 1.30 // Lookup the index for Component name in TRACE_COMPONENT_LIST
|
740 mike 1.2 index = 0;
|
741 r.kieninger 1.30 while (index < _NUM_COMPONENTS)
742 {
743 if (String::equalNoCase(
744 componentName,TRACE_COMPONENT_LIST[index]))
745 {
|
746 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index]=true;
|
747 david.dillard 1.32 _traceOn = true;
|
748 mike 1.2
749 // Found component, break from the loop
750 break;
|
751 r.kieninger 1.30 }
752 else
753 {
754 index++;
|
755 mike 1.2 }
|
756 chip 1.20 }
|
757 mike 1.2
758 // Remove the searched componentname from the traceComponents
759 componentStr.remove(0,position+1);
760 }
761 }
762 else
763 {
764 // initialise ComponentMask array to False
|
765 chip 1.20 for (Uint32 index = 0;index < _NUM_COMPONENTS;
|
766 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index++] = false);
|
767 r.kieninger 1.31 _traceOn = 0;
|
768 mike 1.2 }
769 return ;
770 }
771
|
772 karl 1.35 void Tracer::traceEnter(TracerToken& token, Uint32 traceComponent, const char* method)
773 {
774 if (_traceOn)
775 {
776 token.component = traceComponent;
777 token.method = method;
778
779 //Tracer::traceEnter("unknown", 0, component, method);
780 _traceEnter( "unknown", 0, traceComponent, "%s %s",
781 _METHOD_ENTER_MSG, method);
782 }
783 }
784
785 void Tracer::traceExit(TracerToken& token)
786 {
787 if (_traceOn)
788
789 // KS Tracer::traceExit("unknown", 0, token.component, token.method);
790 _traceExit( "unknown",0, token.component, "%s %s",
791 _METHOD_EXIT_MSG, token.method);
792 }
793 karl 1.35
794 void Tracer::traceEnter(
795 TracerToken& token,
796 const char* file,
797 size_t line,
798 Uint32 traceComponent,
799 const char* method)
800 {
801 if (_traceOn)
802 {
803 token.component = traceComponent;
804 token.method = method;
805
806 //Tracer::traceEnter(file, line, component, method);
807 _traceEnter( file, line, traceComponent, "%s %s",
808 _METHOD_ENTER_MSG, method);
809 }
810 }
811
812 void Tracer::traceExit(
813 TracerToken& token,
814 karl 1.35 const char* file,
815 size_t line)
816 {
817 if (_traceOn)
818 //Tracer::traceExit(file, line, token.component, token.method);
819 _traceExit( file, line, token.component, "%s %s",
820 _METHOD_EXIT_MSG, token.method);
821 }
822
823 void Tracer::traceBuffer(
824 const Uint32 traceComponent,
825 const Uint32 traceLevel,
826 const char* data,
827 const Uint32 size)
828 {
829 if (_traceOn)
830 _traceBuffer( traceComponent, traceLevel, data, size );
831 }
832
833 void Tracer::traceBuffer(
834 const char* fileName,
835 karl 1.35 const Uint32 lineNum,
836 const Uint32 traceComponent,
837 const Uint32 traceLevel,
838 const char* data,
839 const Uint32 size)
840 {
841 if (_traceOn)
842 {
843 _traceBuffer( fileName, lineNum,
844 traceComponent, traceLevel, data, size );
845 }
846 }
847
848 void Tracer::trace(
849 const Uint32 traceComponent,
850 const Uint32 traceLevel,
851 const char *fmt,
852 ...)
853 {
854 if (_traceOn)
855 {
856 karl 1.35 va_list argList;
857
858 va_start(argList,fmt);
859 _trace(traceComponent,traceLevel,fmt,argList);
860 va_end(argList);
861 }
862 }
863
864 void Tracer::trace(
865 const char* fileName,
866 const Uint32 lineNum,
867 const Uint32 traceComponent,
868 const Uint32 traceLevel,
869 const char* fmt,
870 ...)
871 {
872 if (_traceOn)
873 {
874 va_list argList;
875
876 va_start(argList,fmt);
877 karl 1.35 _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);
878 va_end(argList);
879 }
880 }
881
882 void Tracer::trace(
883 const char* fileName,
884 const Uint32 lineNum,
885 const Uint32 traceComponent,
886 const Uint32 traceLevel,
887 const String& traceString)
888 {
889 if (_traceOn)
890 {
891 _traceString( fileName, lineNum, traceComponent, traceLevel,
892 traceString );
893 }
894 }
895
896 void Tracer::traceCIMException(
897 const Uint32 traceComponent,
898 karl 1.35 const Uint32 traceLevel,
899 CIMException cimException)
900 {
901 if (_traceOn)
902 {
903 _traceCIMException( traceComponent, traceLevel, cimException );
904 }
905 }
906
907 void Tracer::trace(
908 const Uint32 traceComponent,
909 const Uint32 level,
910 const String& string)
911 {
912 trace("unknown", 0, traceComponent, level, string);
913 }
914
915 #endif /* !PEGASUS_REMOVE_TRACE */
|
916 mike 1.2
917 PEGASUS_NAMESPACE_END
|