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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2