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