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

Diff for /pegasus/src/Pegasus/Common/Tracer.cpp between version 1.1.2.4 and 1.56

version 1.1.2.4, 2001/08/01 21:56:25 version 1.56, 2008/10/22 08:11:24
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // The Open Group, Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 21 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/Constants.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/Destroyer.h>  #include <Pegasus/Common/TraceFileHandler.h>
   #include <Pegasus/Common/TraceLogHandler.h>
   #include <Pegasus/Common/TraceMemoryHandler.h>
   #include <Pegasus/Common/Thread.h>
   #include <Pegasus/Common/System.h>
   #include <Pegasus/Common/HTTPMessage.h>
   #include <Pegasus/Common/StringConversion.h>
   #include <Pegasus/Common/FileSystem.h>
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 // ATTN  mdday@us.ibm.com Wed Aug  1 10:31:51 2001  /**
 /// el-cheapo version of ltoa      String constants for naming the various Trace components.
 // ltoa is implemented differently from platform to platform      These strings will used when turning on tracing for the respective
 // Linux does not have it at all.      components.  The component list must be kept in sync with the
 // windows implements it as char * _ltoa(long, char *, int);      TraceComponentId enumeration.
 //  
 // Because of the static buffer this you should copy the      The tracer uses the _traceComponentMask in form of a 64bit field to mask
 // return value before another thread clobbers it.      the user configured components.
 // If using for temporary values, as in :      Please ensure that no more than 64 components are specified in the
 // strlen(ltoa(linenumber))      TRACE_COMPONENT_LIST.
 // it should be safe enough for trace functions. .  
 #ifndef PEGASUS_PLATFORM_HPUX_PARISC_ACC      The following example shows the usage of trace component names.
 static inline char *ltoa(int n)      The setTraceComponents method is used to turn on tracing for the
 {      components: Config and Repository. The component names are passed as a
    static char buf [21];      comma separated list.
    sprintf(buf, "%d", n);  
    return(buf);         Tracer::setTraceComponents("Config,Repository");
 }  */
   static char const* TRACE_COMPONENT_LIST[] =
   {
       "XmlParser",
       "XmlWriter",
       "XmlReader",
       "XmlIO",
       "Http",
       "CimData",
       "Repository",
       "Dispatcher",
       "OsAbstraction",
       "Config",
       "IndHandler",
       "Authentication",
       "Authorization",
       "UserManager",
       "Registration",
       "Shutdown",
       "Server",
       "IndicationService",
       "IndicationServiceInternal",
       "MessageQueueService",
       "ProviderManager",
       "ObjectResolution",
       "WQL",
       "CQL",
       "Thread",
       "IPC",
       "IndicationHandlerService",
       "CIMExportRequestDispatcher",
       "SSL",
       "ControlProvider",
       "CIMOMHandle",
       "BinaryMessageHandler",
       "L10N",
       "ExportClient",
       "Listener",
       "DiscardedData",
       "ProviderAgent",
       "IndicationFormatter",
       "StatisticalData",
       "CMPIProvider",
       "IndicationGeneration",
       "IndicationReceipt",
       "CMPIProviderInterface",
       "WsmServer",
       "LogMessages"
   };
   
   
   // Defines the value values for trace facilities
   // Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX,
   // so that the index matches the according string in the list.
   char const* Tracer::TRACE_FACILITY_LIST[] =
   {
       "File",
       "Log",
       "Memory",
       0
   };
  
 #endif  
  
 // Set the trace levels // Set the trace levels
 // These levels will be compared against a trace level mask to determine // These levels will be compared against a trace level mask to determine
 // if a specific trace level is enabled // if a specific trace level is enabled
  
   const Uint32 Tracer::LEVEL0 =  0;
 const Uint32 Tracer::LEVEL1 = (1 << 0); const Uint32 Tracer::LEVEL1 = (1 << 0);
 const Uint32 Tracer::LEVEL2 = (1 << 1); const Uint32 Tracer::LEVEL2 = (1 << 1);
 const Uint32 Tracer::LEVEL3 = (1 << 2); const Uint32 Tracer::LEVEL3 = (1 << 2);
 const Uint32 Tracer::LEVEL4 = (1 << 3); const Uint32 Tracer::LEVEL4 = (1 << 3);
   const Uint32 Tracer::LEVEL5 = (1 << 4);
  
 // Set the Enter and Exit messages // Set the Enter and Exit messages
 const char Tracer::_FUNC_ENTER_MSG[] = "Entering method";  const char Tracer::_METHOD_ENTER_MSG[] = "Entering method";
 const char Tracer::_FUNC_EXIT_MSG[]  = "Exiting method";  const char Tracer::_METHOD_EXIT_MSG[]  = "Exiting method";
   
 // Set Log messages  
 const char Tracer::_LOG_MSG1[] = "LEVEL1 not enabled with Tracer::trace call.";  
 const char Tracer::_LOG_MSG2[]="Use trace macros, PEG_FUNC_ENTER/PEG_FUNC_EXIT";  
  
 // Initialize singleton instance of Tracer // Initialize singleton instance of Tracer
 Tracer* Tracer::_tracerInstance = 0; Tracer* Tracer::_tracerInstance = 0;
Line 82 
Line 152 
 const Uint32 Tracer::_NUM_COMPONENTS = const Uint32 Tracer::_NUM_COMPONENTS =
     sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]);     sizeof(TRACE_COMPONENT_LIST)/sizeof(TRACE_COMPONENT_LIST[0]);
  
   // Set the line maximum
   const Uint32 Tracer::_STRLEN_MAX_UNSIGNED_INT = 21;
   
   // Set the max PID and Thread ID Length
   const Uint32 Tracer::_STRLEN_MAX_PID_TID = 21;
   
   // Initialize public indicator of trace state
   Boolean Tracer::_traceOn=false;
   Uint32  Tracer::_traceLevelMask=0;
   Uint64  Tracer::_traceComponentMask=(Uint64)0;
   
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 // Tracer constructor // Tracer constructor
 // Constructor is private to preclude construction of Tracer objects // Constructor is private to preclude construction of Tracer objects
 // Single Instance of Tracer is maintained for each process. // Single Instance of Tracer is maintained for each process.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::Tracer() Tracer::Tracer()
       : _traceMemoryBufferSize(PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB),
         _traceFacility(TRACE_FACILITY_FILE),
         _runningOOP(false),
         _traceHandler(0)
 { {
     // Initialize Trace File Handler  
     _traceHandler=new TraceFileHandler();  
     _traceLevelMask=0;  
     _traceComponentMask=new Boolean[_NUM_COMPONENTS];  
  
     // Initialize ComponentMask array to false      // The tracer uses a 64bit field to mask the user configured components.
     for (int index=0;index < _NUM_COMPONENTS;      // This assert ensures that no more than 64 components are specified in the
         _traceComponentMask[index++]=false);      // TRACE_COMPONENT_LIST.
       PEGASUS_ASSERT(_NUM_COMPONENTS <= 64);
   
       // Instantiate trace handler according to configured facility
       _setTraceHandler(_traceFacility);
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Line 104 
Line 189 
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer::~Tracer() Tracer::~Tracer()
 { {
     delete []_traceComponentMask;  
     delete _traceHandler;     delete _traceHandler;
     delete _tracerInstance;     delete _tracerInstance;
 } }
  
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces the given message  //Factory function for the trace handler instances.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_trace(  void Tracer::_setTraceHandler( Uint32 traceFacility )
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char* fmt,  
     va_list argList)  
 { {
     if ( traceLevel == LEVEL1 )      TraceHandler * oldTrcHandler = _traceHandler;
     {  
         // ATTN: Setting the Log file type to DEBUG_LOG      switch(traceFacility)
         // May need to change to an appropriate log file type  
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0 $1",  
            _LOG_MSG1,_LOG_MSG2);  
     }  
     else  
     {  
         if (_isTraceEnabled(traceComponent,traceLevel))  
         {         {
             _trace(traceComponent,"",fmt,argList);          case TRACE_FACILITY_LOG:
         }              _traceFacility = TRACE_FACILITY_LOG;
               _traceHandler = new TraceLogHandler();
               break;
   
           case TRACE_FACILITY_MEMORY:
               _traceFacility = TRACE_FACILITY_MEMORY;
               _traceHandler = new TraceMemoryHandler();
               break;
   
           case TRACE_FACILITY_FILE:
           default:
               _traceFacility = TRACE_FACILITY_FILE;
               _traceHandler = new TraceFileHandler();
     }     }
       delete oldTrcHandler;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces the given message - Overloaded for including FileName and Line number  // Validates if a given file path if it is eligible for writing traces.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_trace(  Boolean Tracer::_isValidTraceFile(String fileName)
     const char* fileName,  
     const Uint32 lineNum,  
     const Uint32 traceComponent,  
     const Uint32 traceLevel,  
     const char* fmt,  
     va_list argList)  
 { {
     char* message;      // Check if the file path is a directory
       FileSystem::translateSlashes(fileName);
       if (FileSystem::isDirectory(fileName))
       {
           return false;
       }
  
     if ( traceLevel == LEVEL1 )      // Check if the file exists and is writable
       if (FileSystem::exists(fileName))
     {     {
         Logger::put(Logger::DEBUG_LOG,"Tracer",Logger::WARNING,"$0 $1",          return FileSystem::canWrite(fileName);
            _LOG_MSG1,_LOG_MSG2);  
      }      }
      else  
       // Check if directory is writable
       Uint32 index = fileName.reverseFind('/');
   
       if (index != PEG_NOT_FOUND)
      {      {
          if (_isTraceEnabled(traceComponent,traceLevel))          String dirName = fileName.subString(0,index);
   
           if (dirName.size() == 0)
          {          {
             message = new char[strlen(fileName)+strlen(ltoa((long)lineNum))+6];              dirName = "/";
             sprintf(message,"[%s:%d]: ",fileName,lineNum);  
             _trace(traceComponent,message,fmt,argList);  
             delete []message;  
          }          }
   
           if (!FileSystem::isDirectory(dirName))
           {
               return false;
      }      }
   
           return FileSystem::canWrite(dirName);
       }
   
       String currentDir;
   
       // Check if there is permission to write in the
       // current working directory
       FileSystem::getCurrentDirectory(currentDir);
   
       return FileSystem::canWrite(currentDir);
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces method entry  //Traces the given message - Overloaded for including FileName and Line number
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_traceEnter(  void Tracer::_trace(
     const char* fileName,     const char* fileName,
     const Uint32 lineNum,     const Uint32 lineNum,
     const Uint32 traceComponent,      const TraceComponentId traceComponent,
     const char* fmt,     const char* fmt,
     ...)      va_list argList)
 { {
     va_list argList;  
     char* message;     char* message;
       //
       // Allocate memory for the message string
       // Needs to be updated if additional info is added
       //
       message = new char[strlen(fileName) +
           _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8];
       sprintf(
          message,
          "[%u:%s:%s:%u]: ",
          System::getPID(),
          Threads::id().buffer,
          fileName,
          lineNum);
  
     if (_isTraceEnabled(traceComponent,LEVEL1))  
     {  
         va_start(argList,fmt);  
         message = new char[strlen(fileName)+strlen(ltoa((long)lineNum))+6];  
         sprintf(message,"[%s:%d]: ",fileName,lineNum);  
         _trace(traceComponent,message,fmt,argList);         _trace(traceComponent,message,fmt,argList);
         va_end(argList);  
         delete []message;         delete []message;
     }     }
 }  
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Traces method exit  //Traces the message in the given CIMException object.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_traceExit(  void Tracer::_traceCIMException(
     const char* fileName,      const TraceComponentId traceComponent,
     const Uint32 lineNum,      const CIMException& cimException)
     const Uint32 traceComponent,  
     const char* fmt  
     ...)  
 { {
     va_list argList;      // get the CIMException trace message string
     char* message;      CString traceMsg =
           TraceableCIMException(cimException).getTraceDescription().getCString();
       // trace the string
       _traceCString(traceComponent, "", (const char*) traceMsg);
   }
  
     if (_isTraceEnabled(traceComponent,LEVEL1))  SharedArrayPtr<char> Tracer::getHTTPRequestMessage(
       const Buffer& requestMessage)
     {     {
         va_start(argList,fmt);      const Uint32 requestSize = requestMessage.size();
         message = new char[strlen(fileName)+strlen(ltoa((long)lineNum))+6];  
         sprintf(message,"[%s:%d]: ",fileName,lineNum);      // Make a copy of the request message.
         _trace(traceComponent,message,fmt,argList);      SharedArrayPtr<char>
         va_end(argList);          requestBuf(new char [requestSize + 1]);
         delete []message;      strncpy(requestBuf.get(), requestMessage.getData(), requestSize);
       requestBuf.get()[requestSize] = 0;
   
       //
       // Check if requestBuffer contains a Basic authorization header.
       // If true, suppress the user/passwd info in the request buffer.
       //
       char* sep;
       const char* line = requestBuf.get();
   
       while ((sep = HTTPMessage::findSeparator(
           line, (Uint32)(requestSize - (line - requestBuf.get())))) &&
           (line != sep))
       {
           if (HTTPMessage::expectHeaderToken(line, "Authorization") &&
                HTTPMessage::expectHeaderToken(line, ":") &&
                HTTPMessage::expectHeaderToken(line, "Basic"))
           {
               // Suppress the user/passwd info
               HTTPMessage::skipHeaderWhitespace(line);
               for ( char* userpass = (char*)line ;
                   userpass < sep;
                   *userpass = 'X', userpass++);
   
               break;
     }     }
   
           line = sep + ((*sep == '\r') ? 2 : 1);
       }
   
       return requestBuf;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Checks if trace is enabled for the given component and level  //Traces method entry and exit
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Boolean Tracer::_isTraceEnabled(const Uint32 traceComponent,  void Tracer::_traceMethod(
     const Uint32 traceLevel)      const char* fileName,
 {      const Uint32 lineNum,
     Tracer* instance = _getInstance();      const TraceComponentId traceComponent,
     if ((traceComponent < 0) || (traceComponent >= _NUM_COMPONENTS ))      const char* methodEntryExit,
       const char* method)
     {     {
         return false;      char* message;
     }  
     return ((instance->_traceComponentMask[traceComponent]) &&      //
             (traceLevel  & instance->_traceLevelMask));      // Allocate memory for the message string
       // Needs to be updated if additional info is added
       //
       // assume Method entry/exit string 15 characters long
       // +1 space character
       message = new char[ strlen(fileName) +
           _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8
           + 16];
   
       sprintf(
          message,
          "[%u:%s:%s:%u]: %s ",
          System::getPID(),
          Threads::id().buffer,
          fileName,
          lineNum,
          methodEntryExit);
   
       _traceCString(traceComponent, message, method);
   
       delete [] message;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Called by all trace interfaces to log message to trace file  //Called by all trace interfaces with variable arguments
   //to log message to trace file
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::_trace( void Tracer::_trace(
     const Uint32 traceComponent,      const TraceComponentId traceComponent,
     const char* message,     const char* message,
     const char* fmt,     const char* fmt,
     va_list argList)     va_list argList)
 { {
     char* msgHeader;     char* msgHeader;
       Uint32 msgLen;
       Uint32 usec,sec;
  
     // Get the current system time and prepend to message     // Get the current system time and prepend to message
     String currentTime = System::getCurrentASCIITime();      System::getCurrentTimeUsec(sec,usec);
     ArrayDestroyer<char> timeStamp(currentTime.allocateCString());  
  
       //
     // Allocate messageHeader.     // Allocate messageHeader.
     msgHeader = new char [strlen(message)      // Needs to be updated if additional info is added
         + strlen(TRACE_COMPONENT_LIST[traceComponent])      //
         + strlen(timeStamp.getPointer()) + 6];  
  
     // Construct the message header     // Construct the message header
     // The message header is in the following format     // The message header is in the following format
     // timestamp: <component name> [file name:line number]     // timestamp: <component name> [file name:line number]
     if (strcmp(message,"") != 0)      //
       // Format string length calculation:
       //        11(sec)+ 2('s-')+11(usec)+4('us: ')+1(' ')+1(\0) = 30
       if (*message != '\0')
     {     {
         sprintf(msgHeader,"%s: %s %s",timeStamp.getPointer(),         msgHeader = new char [strlen(message) +
              strlen(TRACE_COMPONENT_LIST[traceComponent]) + 30];
   
           msgLen = sprintf(msgHeader, "%us-%uus: %s %s", sec, usec,
             TRACE_COMPONENT_LIST[traceComponent] ,message);             TRACE_COMPONENT_LIST[traceComponent] ,message);
     }     }
     else     else
     {     {
         sprintf(msgHeader,"%s: %s ",timeStamp.getPointer(),          //
             TRACE_COMPONENT_LIST[traceComponent] );          // Allocate messageHeader.
           // Needs to be updated if additional info is added
           //
           // Format string length calculation:
           //        11(sec)+2('s-')+11(usec)+4('us: ')+
           //        +2(' [')+1(':')+3(']: ')+1(\0) = 35
           msgHeader = new char[2 * _STRLEN_MAX_PID_TID +
               strlen(TRACE_COMPONENT_LIST[traceComponent]) + 35];
   
           msgLen = sprintf(msgHeader, "%us-%uus: %s [%u:%s]: ", sec, usec,
               TRACE_COMPONENT_LIST[traceComponent],
               System::getPID(), Threads::id().buffer);
     }     }
  
     // Call trace file handler to write message     // Call trace file handler to write message
     _getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList);      _getInstance()->_traceHandler->handleMessage(msgHeader,msgLen,fmt,argList);
   
     delete []msgHeader;     delete []msgHeader;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Set the trace file  //Called by all trace interfaces using a character string without format string
   //to log message to trace file
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Uint32 Tracer::setTraceFile(const char* traceFile)  void Tracer::_traceCString(
       const TraceComponentId traceComponent,
       const char* message,
       const char* cstring)
 { {
     ofstream outFile;      char* completeMessage;
     Uint32 retCode = 0;      Uint32 msgLen;
       Uint32 usec,sec;
  
     // Check if the file can be opened in append mode      // Get the current system time and prepend to message
     if (traceFile)      System::getCurrentTimeUsec(sec,usec);
   
       //
       // Allocate completeMessage.
       // Needs to be updated if additional info is added
       //
   
       // Construct the message header
       // The message header is in the following format
       // timestamp: <component name> [file name:line number]
       //
       // Format string length calculation:
       //        11(sec)+ 2('s-')+11(usec)+4('us: ')+1(' ')+1(\0) = 30
       if (*message != '\0')
       {
          completeMessage = new char [strlen(message) +
              strlen(TRACE_COMPONENT_LIST[traceComponent]) +
              strlen(cstring) + 30];
   
           msgLen = sprintf(completeMessage, "%us-%uus: %s %s%s", sec, usec,
               TRACE_COMPONENT_LIST[traceComponent], message, cstring);
       }
       else
     {     {
         outFile.open(traceFile,ofstream::app);          //
           // Since the message is blank, form a string using the pid and tid
           //
           char* tmpBuffer;
   
           //
           // Allocate messageHeader.
           // Needs to be updated if additional info is added
           //
           // Format string length calculation:
           //        11(sec)+2('s-')+11(usec)+4('us: ')+
           //        +2(' [')+1(':')+3(']: ')+1(\0) = 35
           completeMessage = new char[2 * _STRLEN_MAX_PID_TID +
               strlen(TRACE_COMPONENT_LIST[traceComponent]) +
               strlen(cstring) +35];
   
           msgLen = sprintf(completeMessage, "%us-%uus: %s [%u:%s] %s", sec, usec,
               TRACE_COMPONENT_LIST[traceComponent],
               System::getPID(), Threads::id().buffer,
               cstring);
       }
   
       // Call trace file handler to write message
       _getInstance()->_traceHandler->handleMessage(completeMessage,msgLen);
   
       delete [] completeMessage;
   }
   
   
   ////////////////////////////////////////////////////////////////////////////////
   //Validate the trace file
   ////////////////////////////////////////////////////////////////////////////////
   Boolean Tracer::isValidFileName(const char* filePath)
   {
       Tracer* instance = _getInstance();
       String testTraceFile(filePath);
  
         if (outFile.good())      if (instance->_runningOOP)
         {         {
             _getInstance()->_traceHandler->setFileName (traceFile);          testTraceFile.append(".");
             outFile.close();          testTraceFile.append(instance->_oopTraceFileExtension);
       }
   
       return _isValidTraceFile(testTraceFile);
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   //Validate the trace components
   ////////////////////////////////////////////////////////////////////////////////
   Boolean Tracer::isValidComponents(const String& traceComponents)
   {
       String invalidComponents;
       return isValidComponents(traceComponents, invalidComponents);
   }
   
   Boolean Tracer::isValidComponents(
       const String& traceComponents,
       String& invalidComponents)
   {
       // Validate the trace components and modify the traceComponents argument
       // to reflect the invalid components
   
       Uint32    position=0;
       Uint32    index=0;
       String    componentName;
       String    componentStr;
       Boolean   validComponent=false;
       Boolean   retCode=true;
   
       componentStr = traceComponents;
       invalidComponents = String::EMPTY;
   
       if (componentStr != String::EMPTY)
       {
           // Check if ALL is specified
           if (String::equalNoCase(componentStr,"ALL"))
           {
               return true;
           }
   
           // Append _COMPONENT_SEPARATOR to the end of the traceComponents
           componentStr.append(_COMPONENT_SEPARATOR);
   
           while (componentStr != String::EMPTY)
           {
               //
               // Get the Component name from traceComponents.
               // Components are separated by _COMPONENT_SEPARATOR
               //
               position = componentStr.find(_COMPONENT_SEPARATOR);
               componentName = componentStr.subString(0,(position));
   
               // Lookup the index for Component name in TRACE_COMPONENT_LIST
               index = 0;
               validComponent = false;
   
               while (index < _NUM_COMPONENTS)
               {
                   if (String::equalNoCase(
                          componentName, TRACE_COMPONENT_LIST[index]))
                   {
                       // Found component, break from the loop
                       validComponent = true;
                       break;
         }         }
         else         else
         {         {
             outFile.close();                     index++;
             retCode = 1;                  }
               }
   
               // Remove the searched componentname from the traceComponents
               componentStr.remove(0,position+1);
   
               if (!validComponent)
               {
                   invalidComponents.append(componentName);
                   invalidComponents.append(_COMPONENT_SEPARATOR);
               }
         }         }
     }     }
     else     else
     {     {
         retCode=1;          // trace components is empty, it is a valid value so return true
           return true;
       }
   
       if (invalidComponents != String::EMPTY)
       {
           retCode = false;
           //
           // Remove the extra ',' at the end
           //
           invalidComponents.remove(
               invalidComponents.reverseFind(_COMPONENT_SEPARATOR));
     }     }
     return retCode;     return retCode;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
   //Validate the trace facility
   ////////////////////////////////////////////////////////////////////////////////
   Boolean Tracer::isValidTraceFacility(const String& traceFacility)
   {
       Boolean retCode = false;
   
       if (traceFacility.size() != 0)
       {
           Uint32 index = 0;
           while (TRACE_FACILITY_LIST[index] != 0 )
           {
               if (String::equalNoCase(traceFacility,TRACE_FACILITY_LIST[index]))
               {
                   retCode = true;
                   break;
               }
               index++;
           }
       }
   
       return retCode;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   // Notify the trare running out of process and provide the trace file extension
   // for the out of process trace file.
   ////////////////////////////////////////////////////////////////////////////////
   void Tracer::setOOPTraceFileExtension(const String& oopTraceFileExtension)
   {
       Tracer* instance = _getInstance();
       instance->_oopTraceFileExtension = oopTraceFileExtension;
       instance->_runningOOP=true;
       instance->_traceMemoryBufferSize /= PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR;
   
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   //Returns the Singleton instance of the Tracer
   ////////////////////////////////////////////////////////////////////////////////
   Tracer* Tracer::_getInstance()
   {
       if (_tracerInstance == 0)
       {
           _tracerInstance = new Tracer();
       }
       return _tracerInstance;
   }
   
   // PEGASUS_REMOVE_TRACE defines the compile time inclusion of the Trace
   // interfaces. This section defines the trace functions IF the remove
   // trace flag is NOT set.  If it is set, they are defined as empty functions
   // in the header file.
   
   #ifndef PEGASUS_REMOVE_TRACE
   
   ////////////////////////////////////////////////////////////////////////////////
   //Set the trace file
   ////////////////////////////////////////////////////////////////////////////////
   Uint32 Tracer::setTraceFile(const char* traceFile)
   {
       if (*traceFile == 0)
       {
           return 1;
       }
   
       Tracer* instance = _getInstance();
       String newTraceFile(traceFile);
   
       if (instance->_runningOOP)
       {
           newTraceFile.append(".");
           newTraceFile.append(instance->_oopTraceFileExtension);
       }
   
       if (_isValidTraceFile(newTraceFile))
       {
           instance->_traceFile = newTraceFile;
           instance->_traceHandler->configurationUpdated();
       }
       else
       {
           return 1;
       }
   
   
       return 0;
   
   }
   
   ////////////////////////////////////////////////////////////////////////////////
 //Set the trace level //Set the trace level
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Uint32 Tracer::setTraceLevel(const Uint32 traceLevel) Uint32 Tracer::setTraceLevel(const Uint32 traceLevel)
Line 307 
Line 723 
  
     switch (traceLevel)     switch (traceLevel)
     {     {
           case LEVEL0:
               _traceLevelMask = 0x00;
               break;
   
         case LEVEL1:         case LEVEL1:
             _getInstance()->_traceLevelMask = 0x01;              _traceLevelMask = 0x01;
             break;             break;
  
         case LEVEL2:         case LEVEL2:
             _getInstance()->_traceLevelMask = 0x03;              _traceLevelMask = 0x03;
             break;             break;
  
         case LEVEL3:         case LEVEL3:
             _getInstance()->_traceLevelMask = 0x07;              _traceLevelMask = 0x07;
             break;             break;
  
         case LEVEL4:         case LEVEL4:
             _getInstance()->_traceLevelMask = 0x0F;              _traceLevelMask = 0x0F;
               break;
   
           case LEVEL5:
               _traceLevelMask = 0x1F;
             break;             break;
  
         default:         default:
             _getInstance()->_traceLevelMask = 0;              _traceLevelMask = 0x00;
             retCode = 1;             retCode = 1;
     }     }
   
       // If one of the components was set for tracing and the traceLevel
       // is not zero, then turn on tracing.
       _traceOn=((_traceComponentMask!=(Uint64)0)&&(_traceLevelMask!=LEVEL0));
   
     return retCode;     return retCode;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Set components to be traced. //Set components to be traced.
 //The String traceComponents will be updated within the function.  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 void Tracer::setTraceComponents(String traceComponents)  void Tracer::setTraceComponents(const String& traceComponents)
 {  
     Uint32 position=0;  
     Uint32 index=0;  
     String componentName;  
   
     if (traceComponents != String::EMPTY)  
     {     {
         // Check if ALL is specified         // Check if ALL is specified
         if (traceComponents == "ALL")      if (String::equalNoCase(traceComponents,"ALL"))
         {         {
             for (int index=0; index < _NUM_COMPONENTS;          // initialize ComponentMask bit array to true
                 _getInstance()->_traceComponentMask[index++] = true);          _traceComponentMask = (Uint64)-1;
   
           // If tracing isn't turned off by a traceLevel of zero, let's
           // turn on the flag that activates tracing.
           _traceOn = (_traceLevelMask != LEVEL0);
   
             return;             return;
         }         }
  
         // initialise ComponentMask array to False      // initialize ComponentMask bit array to false
         for (int index = 0;index < _NUM_COMPONENTS;      _traceComponentMask = (Uint64)0;
             _getInstance()->_traceComponentMask[index++] = false);      _traceOn = false;
   
       if (traceComponents != String::EMPTY)
       {
           Uint32 index = 0;
           Uint32 position = 0;
           String componentName;
           String componentStr = traceComponents;
   
  
         // Append _COMPONENT_SEPARATOR to the end of the traceComponents         // Append _COMPONENT_SEPARATOR to the end of the traceComponents
         traceComponents += _COMPONENT_SEPARATOR;          componentStr.append(_COMPONENT_SEPARATOR);
  
         while (traceComponents != String::EMPTY)          while (componentStr != String::EMPTY)
         {         {
             // Get the Component name from traceComponents.             // Get the Component name from traceComponents.
             // Components are separated by _COMPONENT_SEPARATOR             // Components are separated by _COMPONENT_SEPARATOR
             position = traceComponents.find(_COMPONENT_SEPARATOR);              position = componentStr.find(_COMPONENT_SEPARATOR);
             componentName = traceComponents.subString(0,(position));              componentName = componentStr.subString(0,(position));
  
             // Lookup the index for Component name in TRACE_COMPONENT_LIST             // Lookup the index for Component name in TRACE_COMPONENT_LIST
             index = 0;             index = 0;
             while (index < _NUM_COMPONENTS)             while (index < _NUM_COMPONENTS)
             {             {
                 if (componentName == TRACE_COMPONENT_LIST[index])                  if (String::equalNoCase(
                       componentName,TRACE_COMPONENT_LIST[index]))
                 {                 {
                     _getInstance()->_traceComponentMask[index]=true;                      _traceComponentMask=_traceComponentMask|((Uint64)1<<index);
   
                     // Found component, break from the loop                     // Found component, break from the loop
                     break;                     break;
                 }                 }
Line 380 
Line 815 
                    index++;                    index++;
                 }                 }
             }             }
   
             // Remove the searched componentname from the traceComponents             // Remove the searched componentname from the traceComponents
             traceComponents.remove(0,position+1);              componentStr.remove(0,position+1);
         }         }
           // If one of the components was set for tracing and the traceLevel
           // is not zero, then turn on tracing.
           _traceOn=((_traceComponentMask!=(Uint64)0)&&(_traceLevelMask!=LEVEL0));
       }
   
       return ;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   // Set the trace facility to be used
   ////////////////////////////////////////////////////////////////////////////////
   Uint32 Tracer::setTraceFacility(const String& traceFacility)
   {
       Uint32 retCode = 0;
       Tracer* instance = _getInstance();
   
       if (traceFacility.size() != 0)
       {
           Uint32 index = 0;
           while (TRACE_FACILITY_LIST[index] != 0 )
           {
               if (String::equalNoCase( traceFacility,TRACE_FACILITY_LIST[index]))
               {
                   if (index != instance->_traceFacility)
                   {
                       instance->_setTraceHandler(index);
                   }
                   retCode = 1;
                   break;
               }
               index++;
           }
       }
   
       return retCode;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   // Get the trace facility in use
   ////////////////////////////////////////////////////////////////////////////////
   Uint32 Tracer::getTraceFacility()
   {
       return _getInstance()->_traceFacility;
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   // Set the size of the memory trace buffer
   ////////////////////////////////////////////////////////////////////////////////
   Boolean Tracer::setTraceMemoryBufferSize(Uint32 bufferSize)
   {
       Tracer* instance = _getInstance();
       if (instance->_runningOOP)
       {
           // in OOP we reduce the trace memory buffer by factor
           // PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR
           instance->_traceMemoryBufferSize =
               bufferSize / PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR;
     }     }
     else     else
     {     {
         // initialise ComponentMask array to False          instance->_traceMemoryBufferSize = bufferSize;
         for (int index = 0;index < _NUM_COMPONENTS;  
             _getInstance()->_traceComponentMask[index++] = false);  
     }     }
   
       // If we decide to dynamically change the trace buffer size,
       // this is where it needs to be implemented.
       return true;
 } }
  
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 //Returns the Singleton instance of the Tracer  // Flushes the trace buffer to traceFilePath. This method will only
   // have an effect when traceFacility=Memory.
 //////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
 Tracer* Tracer::_getInstance()  void Tracer::flushTrace()
 { {
     if (_tracerInstance == 0)      _getInstance()->_traceHandler->flushTrace();
       return;
   }
   
   
   void Tracer::traceEnter(
       TracerToken& token,
       const char* file,
       size_t line,
       TraceComponentId traceComponent,
       const char* method)
     {     {
         _tracerInstance = new Tracer();      token.component = traceComponent;
       token.method = method;
   
       if (isTraceEnabled(traceComponent, LEVEL5))
       {
           _traceMethod(
               file, (Uint32)line, traceComponent,
               _METHOD_ENTER_MSG, method);
     }     }
     return _tracerInstance;  
 } }
  
   void Tracer::traceExit(
       TracerToken& token,
       const char* file,
       size_t line)
   {
       if (isTraceEnabled(token.component, LEVEL5) && token.method)
           _traceMethod(
               file, (Uint32)line, token.component,
               _METHOD_EXIT_MSG, token.method);
   }
   
   ////////////////////////////////////////////////////////////////////////////////
   //Traces the given string - Overloaded to include the fileName and line number
   //of trace origin.
   ////////////////////////////////////////////////////////////////////////////////
   void Tracer::traceCString(
       const char* fileName,
       const Uint32 lineNum,
       const TraceComponentId traceComponent,
       const char* cstring)
   {
       char* message;
   
       Uint32 msgLen;
       Uint32 usec,sec;
   
       // Get the current system time
       System::getCurrentTimeUsec(sec,usec);
   
       //
       // Allocate memory for the message string
       // Needs to be updated if additional info is added
       //
       message = new char [strlen(fileName) +
           _STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 +
           strlen(TRACE_COMPONENT_LIST[traceComponent]) +
           strlen(cstring) + 30];
   
       msgLen = sprintf(message, "%us-%uus: %s [%u:%s:%s:%u]: %s",
           sec,
           usec,
           TRACE_COMPONENT_LIST[traceComponent],
           System::getPID(),
           Threads::id().buffer,
           fileName,
           lineNum,
           cstring);
   
       // Call trace file handler to write message
       _getInstance()->_traceHandler->handleMessage(message,msgLen);
   
       delete [] message;
   }
   
   void Tracer::traceCIMException(
       const TraceComponentId traceComponent,
       const Uint32 traceLevel,
       const CIMException& cimException)
   {
       if (isTraceEnabled(traceComponent, traceLevel))
       {
           _traceCIMException(traceComponent, cimException);
       }
   }
   
   #endif /* !PEGASUS_REMOVE_TRACE */
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.56

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2