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 mike 1.39 const Uint32 Tracer::_STRLEN_MAX_PID_TID = 21;
|
88 kumpf 1.3
|
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 mike 1.38 "[%d:%s:%s:%u]: ",
|
168 kumpf 1.3 System::getPID(),
|
169 mike 1.38 Threads::id().buffer,
|
170 kumpf 1.3 fileName,
171 lineNum);
|
172 mike 1.2
|
173 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
174 david.dillard 1.32 delete []message;
|
175 mike 1.2 }
176 }
177 }
178
179 ////////////////////////////////////////////////////////////////////////////////
180 //Traces the given buffer
181 ////////////////////////////////////////////////////////////////////////////////
182 void Tracer::_traceBuffer(
183 const Uint32 traceComponent,
184 const Uint32 traceLevel,
185 const char* data,
186 const Uint32 size)
187 {
188 if ( traceLevel == LEVEL1 )
189 {
|
190 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
191 mike 1.2 }
192 else
193 {
194 if (_isTraceEnabled(traceComponent,traceLevel))
195 {
196 char* tmpBuf = new char[size+1];
197
198 strncpy( tmpBuf, data, size );
199 tmpBuf[size] = '\0';
200 trace(traceComponent,traceLevel,"%s",tmpBuf);
201
202 delete []tmpBuf;
203 }
204 }
205 }
206 ////////////////////////////////////////////////////////////////////////////////
207 //Traces the given buffer - Overloaded for including FileName and Line number
208 ////////////////////////////////////////////////////////////////////////////////
209 void Tracer::_traceBuffer(
210 const char* fileName,
211 const Uint32 lineNum,
212 mike 1.2 const Uint32 traceComponent,
213 const Uint32 traceLevel,
214 const char* data,
215 const Uint32 size)
216 {
217 if ( traceLevel == LEVEL1 )
218 {
|
219 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
220 mike 1.2 }
221 else
222 {
223 if ( _isTraceEnabled( traceComponent, traceLevel ) )
224 {
225 char* tmpBuf = new char[size+1];
226
227 strncpy( tmpBuf, data, size );
228 tmpBuf[size] = '\0';
229 trace(fileName,lineNum,traceComponent,traceLevel,"%s",tmpBuf);
230
231 delete []tmpBuf;
|
232 kumpf 1.5 }
233 }
234 }
235
236 ////////////////////////////////////////////////////////////////////////////////
237 //Traces the given string
238 ////////////////////////////////////////////////////////////////////////////////
239 void Tracer::_traceString(
240 const Uint32 traceComponent,
241 const Uint32 traceLevel,
242 const String& traceString)
243 {
244 if ( traceLevel == LEVEL1 )
245 {
|
246 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
247 kumpf 1.5 }
248 else
249 {
250 if (_isTraceEnabled(traceComponent,traceLevel))
251 {
|
252 kumpf 1.18 trace(traceComponent,traceLevel,"%s",
253 (const char *)traceString.getCString());
|
254 kumpf 1.5 }
255 }
256 }
257
258 ////////////////////////////////////////////////////////////////////////////////
259 //Traces the given string - Overloaded to include the fileName and line number
260 //of trace origin.
261 ////////////////////////////////////////////////////////////////////////////////
262 void Tracer::_traceString(
263 const char* fileName,
264 const Uint32 lineNum,
265 const Uint32 traceComponent,
266 const Uint32 traceLevel,
267 const String& traceString)
268 {
269 if ( traceLevel == LEVEL1 )
270 {
|
271 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
272 kumpf 1.5 }
273 else
274 {
275 if ( _isTraceEnabled( traceComponent, traceLevel ) )
276 {
|
277 kumpf 1.18 trace(fileName,lineNum,traceComponent,traceLevel,"%s",
278 (const char *)traceString.getCString());
|
279 kumpf 1.5 }
280 }
281 }
282
283 ////////////////////////////////////////////////////////////////////////////////
284 //Traces the message in the given CIMException object.
285 ////////////////////////////////////////////////////////////////////////////////
286 void Tracer::_traceCIMException(
287 const Uint32 traceComponent,
288 const Uint32 traceLevel,
289 CIMException cimException)
290 {
291 if ( traceLevel == LEVEL1 )
292 {
|
293 kumpf 1.14 trace( traceComponent, Tracer::LEVEL4, "%s", _LOG_MSG );
|
294 kumpf 1.5 }
295 else
296 {
297 if ( _isTraceEnabled( traceComponent, traceLevel ) )
298 {
299 // get the CIMException trace message string
|
300 kumpf 1.15 String traceMsg =
301 TraceableCIMException(cimException).getTraceDescription();
|
302 kumpf 1.5
303 // trace the string
304 _traceString(traceComponent, traceLevel, traceMsg);
|
305 mike 1.2 }
306 }
307 }
308
309 ////////////////////////////////////////////////////////////////////////////////
310 //Traces method entry
311 ////////////////////////////////////////////////////////////////////////////////
312 void Tracer::_traceEnter(
313 const char* fileName,
314 const Uint32 lineNum,
315 const Uint32 traceComponent,
316 const char* fmt,
317 ...)
318 {
319 va_list argList;
320 char* message;
321
322 if (_isTraceEnabled(traceComponent,LEVEL1))
323 {
|
324 kumpf 1.3
|
325 mike 1.2 va_start(argList,fmt);
326
|
327 kumpf 1.3 //
328 // Allocate memory for the message string
329 // Needs to be updated if additional info is added
330 //
|
331 david.dillard 1.32 message = new char[ strlen(fileName) +
|
332 mike 1.39 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
|
333 r.kieninger 1.30
|
334 kumpf 1.3 sprintf(
335 message,
|
336 mike 1.38 "[%d:%s:%s:%u]: ",
|
337 kumpf 1.3 System::getPID(),
|
338 mike 1.38 Threads::id().buffer,
|
339 kumpf 1.3 fileName,
340 lineNum);
|
341 carson.hovey 1.37
|
342 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
343 mike 1.2
344 va_end(argList);
345 delete []message;
346 }
347 }
348
349 ////////////////////////////////////////////////////////////////////////////////
350 //Traces method exit
351 ////////////////////////////////////////////////////////////////////////////////
352 void Tracer::_traceExit(
353 const char* fileName,
354 const Uint32 lineNum,
355 const Uint32 traceComponent,
356 const char* fmt
357 ...)
358 {
359 va_list argList;
360 char* message;
361
362 if (_isTraceEnabled(traceComponent,LEVEL1))
363 {
364 mike 1.2 va_start(argList,fmt);
|
365 chip 1.20
|
366 kumpf 1.3 //
367 // Allocate memory for the message string
368 // Needs to be updated if additional info is added
369 //
|
370 david.dillard 1.32 message = new char[ strlen(fileName) +
371 _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 ];
|
372 r.kieninger 1.30
|
373 kumpf 1.3 sprintf(
374 message,
|
375 mike 1.38 "[%d:%s:%s:%u]: ",
|
376 kumpf 1.3 System::getPID(),
|
377 mike 1.38 Threads::id().buffer,
|
378 kumpf 1.3 fileName,
379 lineNum);
|
380 carson.hovey 1.37
|
381 chip 1.20 _trace(traceComponent,message,fmt,argList);
|
382 mike 1.2 va_end(argList);
383
384 delete []message;
385 }
386 }
387
388 ////////////////////////////////////////////////////////////////////////////////
389 //Checks if trace is enabled for the given component and level
390 ////////////////////////////////////////////////////////////////////////////////
391 Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,
392 const Uint32 traceLevel)
393 {
394 Tracer* instance = _getInstance();
395 if (traceComponent >= _NUM_COMPONENTS)
396 {
|
397 david.dillard 1.32 return false;
|
398 mike 1.2 }
|
399 a.arora 1.22 return (((instance->_traceComponentMask.get())[traceComponent]) &&
|
400 david.dillard 1.32 (traceLevel & instance->_traceLevelMask));
|
401 mike 1.2 }
402
403 ////////////////////////////////////////////////////////////////////////////////
404 //Called by all trace interfaces to log message to trace file
405 ////////////////////////////////////////////////////////////////////////////////
406 void Tracer::_trace(
407 const Uint32 traceComponent,
408 const char* message,
409 const char* fmt,
410 va_list argList)
411 {
412 char* msgHeader;
413
414 // Get the current system time and prepend to message
415 String currentTime = System::getCurrentASCIITime();
|
416 kumpf 1.17 CString timeStamp = currentTime.getCString();
|
417 mike 1.2
|
418 kumpf 1.3 //
|
419 chip 1.20 // Allocate messageHeader.
|
420 kumpf 1.3 // Needs to be updated if additional info is added
421 //
|
422 mday 1.19
423
|
424 mike 1.2
425 // Construct the message header
|
426 chip 1.20 // The message header is in the following format
|
427 mike 1.2 // timestamp: <component name> [file name:line number]
|
428 joyce.j 1.26 if (*message != '\0')
|
429 mike 1.2 {
|
430 mday 1.19 // << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used in this format string
431 msgHeader = new char [strlen(message)
|
432 david.dillard 1.32 + strlen(TRACE_COMPONENT_LIST[traceComponent])
433 + strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5];
|
434 chip 1.20
|
435 kumpf 1.17 sprintf(msgHeader,"%s: %s %s",(const char*)timeStamp,
|
436 mike 1.2 TRACE_COMPONENT_LIST[traceComponent] ,message);
|
437 chip 1.20 //delete [] msgHeader;
|
438 mike 1.2 }
439 else
440 {
|
441 kumpf 1.3 //
442 // Since the message is blank form a string using the pid and tid
443 //
444 char* tmpBuffer;
445
446 //
|
447 chip 1.20 // Allocate messageHeader.
|
448 kumpf 1.3 // Needs to be updated if additional info is added
449 //
|
450 mike 1.39 tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6];
|
451 mike 1.38 sprintf(tmpBuffer, "[%u:%s]: ", System::getPID(), Threads::id().buffer);
|
452 david.dillard 1.32 msgHeader = new char [ strlen(timeStamp) + strlen(TRACE_COMPONENT_LIST[traceComponent]) +
453 strlen(tmpBuffer) + 1 + 5 ];
|
454 r.kieninger 1.30
|
455 kumpf 1.17 sprintf(msgHeader,"%s: %s %s ",(const char*)timeStamp,
|
456 kumpf 1.3 TRACE_COMPONENT_LIST[traceComponent] ,tmpBuffer );
457 delete []tmpBuffer;
|
458 chip 1.20 //delete [] msgHeader;
|
459 r.kieninger 1.30
|
460 mike 1.2 }
461
462 // Call trace file handler to write message
463 _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);
|
464 chip 1.20
465 delete [] msgHeader;
|
466 mike 1.2 }
467
468 ////////////////////////////////////////////////////////////////////////////////
469 //Validate the trace file
470 ////////////////////////////////////////////////////////////////////////////////
|
471 kumpf 1.10 Boolean Tracer::isValidFileName(const char* filePath)
|
472 mike 1.2 {
|
473 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
474 if (moduleName == String::EMPTY)
475 {
476 return (_getInstance()->_traceHandler->isValidFilePath(filePath));
477 }
478 else
479 {
480 String extendedFilePath = String(filePath) + "." + moduleName;
481 return (_getInstance()->_traceHandler->isValidFilePath(
482 extendedFilePath.getCString()));
483 }
|
484 mike 1.2 }
485
486 ////////////////////////////////////////////////////////////////////////////////
487 //Validate the trace components
488 ////////////////////////////////////////////////////////////////////////////////
|
489 kumpf 1.23 Boolean Tracer::isValidComponents(const String& traceComponents)
|
490 kumpf 1.10 {
491 String invalidComponents;
492 return isValidComponents(traceComponents, invalidComponents);
493 }
494
495 Boolean Tracer::isValidComponents(
|
496 kumpf 1.23 const String& traceComponents, String& invalidComponents)
|
497 mike 1.2 {
498 // Validate the trace components and modify the traceComponents argument
499 // to reflect the invalid components
500
501 Uint32 position=0;
502 Uint32 index=0;
503 String componentName = String::EMPTY;
504 String componentStr = String::EMPTY;
505 Boolean validComponent=false;
506 Boolean retCode=true;
507
508 componentStr = traceComponents;
509 invalidComponents = String::EMPTY;
510
511 if (componentStr != String::EMPTY)
512 {
513 // Check if ALL is specified
514 if (String::equalNoCase(componentStr,"ALL"))
515 {
516 return _SUCCESS;
517 }
518 mike 1.2
519 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
520 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
521 mike 1.2
522 while (componentStr != String::EMPTY)
523 {
|
524 david.dillard 1.32 //
|
525 mike 1.2 // Get the Component name from traceComponents.
526 // Components are separated by _COMPONENT_SEPARATOR
|
527 david.dillard 1.32 //
|
528 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
529 componentName = componentStr.subString(0,(position));
530
531 // Lookup the index for Component name in TRACE_COMPONENT_LIST
532 index = 0;
533 validComponent = false;
534
535 while (index < _NUM_COMPONENTS)
536 {
|
537 chip 1.20 if (String::equalNoCase(
|
538 david.dillard 1.32 componentName, TRACE_COMPONENT_LIST[index]))
|
539 mike 1.2 {
540 // Found component, break from the loop
|
541 david.dillard 1.32 validComponent = true;
|
542 mike 1.2 break;
543 }
544 else
545 {
546 index++;
547 }
548 }
549
550 // Remove the searched componentname from the traceComponents
551 componentStr.remove(0,position+1);
552
|
553 david.dillard 1.32 if ( !validComponent )
554 {
555 invalidComponents.append(componentName);
556 invalidComponents.append(_COMPONENT_SEPARATOR);
|
557 mike 1.2 }
558 }
559 }
560 else
561 {
|
562 david.dillard 1.32 // trace components is empty, it is a valid value so return true
563 return _SUCCESS;
|
564 mike 1.2 }
565 if ( invalidComponents != String::EMPTY )
566 {
|
567 david.dillard 1.32 retCode = false;
568 //
569 // Remove the extra ',' at the end
570 //
571 invalidComponents.remove(
572 invalidComponents.reverseFind(_COMPONENT_SEPARATOR));
|
573 mike 1.2 }
574 return retCode;
575 }
|
576 chip 1.20
|
577 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
578 kumpf 1.23 //Set the name of the module being traced
579 ////////////////////////////////////////////////////////////////////////////////
580 void Tracer::setModuleName(const String& moduleName)
581 {
582 _getInstance()->_moduleName = moduleName;
583 }
584
585 ////////////////////////////////////////////////////////////////////////////////
|
586 mike 1.2 //Returns the Singleton instance of the Tracer
587 ////////////////////////////////////////////////////////////////////////////////
588 Tracer* Tracer::_getInstance()
589 {
590 if (_tracerInstance == 0)
591 {
592 _tracerInstance = new Tracer();
593 }
594 return _tracerInstance;
595 }
596
|
597 chip 1.20 // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
|
598 karl 1.35 // interfaces. This section defines the trace functions IF the remove
599 // trace flag is NOT set. If it is set, they are defined as empty functions
600 // in the header file.
|
601 mike 1.2
602 #ifndef PEGASUS_REMOVE_TRACE
603
604 ////////////////////////////////////////////////////////////////////////////////
605 //Set the trace file
606 ////////////////////////////////////////////////////////////////////////////////
607 Uint32 Tracer::setTraceFile(const char* traceFile)
608 {
|
609 kumpf 1.25 if (*traceFile == 0)
610 {
611 return 1;
612 }
613
|
614 kumpf 1.23 String moduleName = _getInstance()->_moduleName;
615 if (moduleName == String::EMPTY)
616 {
617 return (_getInstance()->_traceHandler->setFileName(traceFile));
618 }
619 else
620 {
621 String extendedTraceFile = String(traceFile) + "." + moduleName;
622 return (_getInstance()->_traceHandler->setFileName(
623 extendedTraceFile.getCString()));
624 }
|
625 chip 1.20 }
|
626 mike 1.2
627 ////////////////////////////////////////////////////////////////////////////////
628 //Set the trace level
629 ////////////////////////////////////////////////////////////////////////////////
630 Uint32 Tracer::setTraceLevel(const Uint32 traceLevel)
631 {
632 Uint32 retCode = 0;
633
634 switch (traceLevel)
635 {
|
636 david.dillard 1.32 case LEVEL1:
|
637 mike 1.2 _getInstance()->_traceLevelMask = 0x01;
|
638 david.dillard 1.32 break;
|
639 chip 1.20
|
640 mike 1.2 case LEVEL2:
641 _getInstance()->_traceLevelMask = 0x03;
|
642 david.dillard 1.32 break;
|
643 mike 1.2
644 case LEVEL3:
645 _getInstance()->_traceLevelMask = 0x07;
|
646 david.dillard 1.32 break;
|
647 mike 1.2
648 case LEVEL4:
649 _getInstance()->_traceLevelMask = 0x0F;
|
650 david.dillard 1.32 break;
|
651 mike 1.2
652 default:
653 _getInstance()->_traceLevelMask = 0;
654 retCode = 1;
655 }
656 return retCode;
657 }
658
659 ////////////////////////////////////////////////////////////////////////////////
|
660 chip 1.20 // Set components to be traced.
|
661 mike 1.2 ////////////////////////////////////////////////////////////////////////////////
|
662 kumpf 1.23 void Tracer::setTraceComponents(const String& traceComponents)
|
663 mike 1.2 {
664 Uint32 position = 0;
665 Uint32 index = 0;
666 String componentName = String::EMPTY;
667 String componentStr = traceComponents;
668 String invalidComponents = String::EMPTY;
|
669 chip 1.20
|
670 mike 1.2 if (componentStr != String::EMPTY)
671 {
672 // Check if ALL is specified
673 if (String::equalNoCase(componentStr,"ALL"))
674 {
675 for (index=0; index < _NUM_COMPONENTS;
|
676 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index++] = true);
|
677 david.dillard 1.32 _traceOn = true;
|
678 chip 1.20 return ;
|
679 mike 1.2 }
680
681 // initialise ComponentMask array to False
|
682 chip 1.20 for (index = 0;index < _NUM_COMPONENTS;
|
683 r.kieninger 1.30 (_getInstance()->_traceComponentMask.get())[index++] = false);
|
684 david.dillard 1.32 _traceOn = false;
|
685 mike 1.2
|
686 r.kieninger 1.30 // Append _COMPONENT_SEPARATOR to the end of the traceComponents
|
687 kumpf 1.16 componentStr.append(_COMPONENT_SEPARATOR);
|
688 mike 1.2
689 while (componentStr != String::EMPTY)
690 {
|
691 chip 1.20 // Get the Component name from traceComponents.
|
692 r.kieninger 1.30 // Components are separated by _COMPONENT_SEPARATOR
|
693 mike 1.2 position = componentStr.find(_COMPONENT_SEPARATOR);
|
694 r.kieninger 1.30 componentName = componentStr.subString(0,(position));
|
695 mike 1.2
|
696 r.kieninger 1.30 // Lookup the index for Component name in TRACE_COMPONENT_LIST
|
697 mike 1.2 index = 0;
|
698 r.kieninger 1.30 while (index < _NUM_COMPONENTS)
699 {
700 if (String::equalNoCase(
701 componentName,TRACE_COMPONENT_LIST[index]))
702 {
|
703 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index]=true;
|
704 david.dillard 1.32 _traceOn = true;
|
705 mike 1.2
706 // Found component, break from the loop
707 break;
|
708 r.kieninger 1.30 }
709 else
710 {
711 index++;
|
712 mike 1.2 }
|
713 chip 1.20 }
|
714 mike 1.2
715 // Remove the searched componentname from the traceComponents
716 componentStr.remove(0,position+1);
717 }
718 }
719 else
720 {
721 // initialise ComponentMask array to False
|
722 chip 1.20 for (Uint32 index = 0;index < _NUM_COMPONENTS;
|
723 a.arora 1.22 (_getInstance()->_traceComponentMask.get())[index++] = false);
|
724 r.kieninger 1.31 _traceOn = 0;
|
725 mike 1.2 }
726 return ;
727 }
728
|
729 karl 1.35 void Tracer::traceEnter(TracerToken& token, Uint32 traceComponent, const char* method)
730 {
731 if (_traceOn)
732 {
733 token.component = traceComponent;
734 token.method = method;
735
736 //Tracer::traceEnter("unknown", 0, component, method);
737 _traceEnter( "unknown", 0, traceComponent, "%s %s",
738 _METHOD_ENTER_MSG, method);
739 }
740 }
741
742 void Tracer::traceExit(TracerToken& token)
743 {
744 if (_traceOn)
745
746 // KS Tracer::traceExit("unknown", 0, token.component, token.method);
747 _traceExit( "unknown",0, token.component, "%s %s",
748 _METHOD_EXIT_MSG, token.method);
749 }
750 karl 1.35
751 void Tracer::traceEnter(
752 TracerToken& token,
753 const char* file,
754 size_t line,
755 Uint32 traceComponent,
756 const char* method)
757 {
758 if (_traceOn)
759 {
760 token.component = traceComponent;
761 token.method = method;
762
763 //Tracer::traceEnter(file, line, component, method);
764 _traceEnter( file, line, traceComponent, "%s %s",
765 _METHOD_ENTER_MSG, method);
766 }
767 }
768
769 void Tracer::traceExit(
770 TracerToken& token,
771 karl 1.35 const char* file,
772 size_t line)
773 {
774 if (_traceOn)
775 //Tracer::traceExit(file, line, token.component, token.method);
776 _traceExit( file, line, token.component, "%s %s",
777 _METHOD_EXIT_MSG, token.method);
778 }
779
780 void Tracer::traceBuffer(
781 const Uint32 traceComponent,
782 const Uint32 traceLevel,
783 const char* data,
784 const Uint32 size)
785 {
786 if (_traceOn)
787 _traceBuffer( traceComponent, traceLevel, data, size );
788 }
789
790 void Tracer::traceBuffer(
791 const char* fileName,
792 karl 1.35 const Uint32 lineNum,
793 const Uint32 traceComponent,
794 const Uint32 traceLevel,
795 const char* data,
796 const Uint32 size)
797 {
798 if (_traceOn)
799 {
800 _traceBuffer( fileName, lineNum,
801 traceComponent, traceLevel, data, size );
802 }
803 }
804
805 void Tracer::trace(
806 const Uint32 traceComponent,
807 const Uint32 traceLevel,
808 const char *fmt,
809 ...)
810 {
811 if (_traceOn)
812 {
813 karl 1.35 va_list argList;
814
815 va_start(argList,fmt);
816 _trace(traceComponent,traceLevel,fmt,argList);
817 va_end(argList);
818 }
819 }
820
821 void Tracer::trace(
822 const char* fileName,
823 const Uint32 lineNum,
824 const Uint32 traceComponent,
825 const Uint32 traceLevel,
826 const char* fmt,
827 ...)
828 {
829 if (_traceOn)
830 {
831 va_list argList;
832
833 va_start(argList,fmt);
834 karl 1.35 _trace(fileName,lineNum,traceComponent,traceLevel,fmt,argList);
835 va_end(argList);
836 }
837 }
838
839 void Tracer::trace(
840 const char* fileName,
841 const Uint32 lineNum,
842 const Uint32 traceComponent,
843 const Uint32 traceLevel,
844 const String& traceString)
845 {
846 if (_traceOn)
847 {
848 _traceString( fileName, lineNum, traceComponent, traceLevel,
849 traceString );
850 }
851 }
852
853 void Tracer::traceCIMException(
854 const Uint32 traceComponent,
855 karl 1.35 const Uint32 traceLevel,
856 CIMException cimException)
857 {
858 if (_traceOn)
859 {
860 _traceCIMException( traceComponent, traceLevel, cimException );
861 }
862 }
863
864 void Tracer::trace(
865 const Uint32 traceComponent,
866 const Uint32 level,
867 const String& string)
868 {
869 trace("unknown", 0, traceComponent, level, string);
870 }
871
872 #endif /* !PEGASUS_REMOVE_TRACE */
|
873 mike 1.2
874 PEGASUS_NAMESPACE_END
|