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