(file) Return to Tracer.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2