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

Diff for /pegasus/src/Pegasus/Common/TraceMemoryHandler.cpp between version 1.5 and 1.8

version 1.5, 2008/09/04 18:22:29 version 1.8, 2008/09/18 07:50:07
Line 43 
Line 43 
 #include <iostream> #include <iostream>
 #include <fstream> #include <fstream>
  
 // ATTN: This is a workaround to allow HP-UX builds to succeed.  It appears to  // ATTN: This is a workaround to allow HP-UX and Windows builds to succeed.
 // work, but it may not be reliable.  A better solution would be preferred.  // It appears to work, but it may not be reliable.  A better solution would be
 // Windows platforms appear to have a similar problem with va_copy not defined.  // preferred.
 #ifdef PEGASUS_OS_HPUX  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_TYPE_WINDOWS)
 # ifndef va_copy # ifndef va_copy
 #  define va_copy(dest, src) (void)((dest) = (src)) #  define va_copy(dest, src) (void)((dest) = (src))
 # endif # endif
 #endif #endif
  
 #define PEGASUS_TRC_BUFFER_WRAP_MARKER ""  
 #define PEGASUS_TRC_BUFFER_EOT_MARKER "*EOTRACE*"  
 #define PEGASUS_TRC_BUFFER_EOT_MARKER_LEN 9  
   
   
 //#define DBG(output) output //#define DBG(output) output
 #define DBG(output) #define DBG(output)
  
Line 345 
Line 340 
         return;         return;
     }     }
  
       Uint32 msgStart =  _traceArea->nextPos;
     // Handle the static part of the message     // Handle the static part of the message
     _appendSimpleMessage(message, msgLen);     _appendSimpleMessage(message, msgLen);
  
Line 399 
Line 395 
         // buffer.         // buffer.
         // To save memory allocations, the overflow buffer is kept around         // To save memory allocations, the overflow buffer is kept around
         // until it becomes to small and needs to be reallocated.         // until it becomes to small and needs to be reallocated.
           if (ttlMsgLen == -1 || (msgLen + ttlMsgLen) > _traceArea->bufferSize)
           {
               // The message does not fit in the remaining buffer and
               // vsnprintf() did not return the bytes needed
               // or the message is larger then the treace Buffer.
   
               // The message does not fit in the remaining buffer,
               // clean up the the message fragment.
               _traceArea->traceBuffer[msgStart] = 0;
   
               // Wrap the buffer
               _traceArea->nextPos = 0;
               _leftBytesInBuffer = _traceArea->bufferSize;
   
               // Rewrite the static part of the message
               _appendSimpleMessage(message, msgLen);
  
         if (ttlMsgLen == -1)              // Rewrite the variable part of the message
   #ifdef PEGASUS_OS_TYPE_WINDOWS
               // Windows until VC 8 does not support vsnprintf
               // need to use Windows equivalent function with the underscore
               ttlMsgLen =
               _vsnprintf(&(_traceArea->traceBuffer[_traceArea->nextPos]),
                          _leftBytesInBuffer,
                          fmt,
                          argListCopy);
   #else
               ttlMsgLen =
               vsnprintf(&(_traceArea->traceBuffer[_traceArea->nextPos]),
                         _leftBytesInBuffer,
                         fmt,
                         argListCopy);
   #endif
               if (ttlMsgLen == -1 ||
                   (msgLen + ttlMsgLen) > _traceArea->bufferSize)
         {         {
             // The vsnprintf failed and did not return the bytes needed for the                  // The message still does not fit in the buffer, but know
             // message.  A fixed message size is used in this case.  The                  // we know that the most part of the message is in the buffer.
             // vsnprintf will write not more than 4096 bytes (including                  // Truncate the message using the truncation marker and leave
             // trailing '\0') into the buffer.  The rest is truncated.                  // space for the EOT marker + '\n'.
             ttlMsgLen = 4096;                  _leftBytesInBuffer = PEGASUS_TRC_BUFFER_TRUNC_MARKER_LEN +
                       PEGASUS_TRC_BUFFER_EOT_MARKER_LEN + 1 ;
   
                   _traceArea->nextPos =
                       _traceArea->bufferSize - _leftBytesInBuffer ;
   
                   // copy the marker including the trailing '0' !
                   memcpy(&(_traceArea->traceBuffer[_traceArea->nextPos]),
                       PEGASUS_TRC_BUFFER_TRUNC_MARKER,
                       PEGASUS_TRC_BUFFER_TRUNC_MARKER_LEN + 1 );
   
                   _traceArea->nextPos += PEGASUS_TRC_BUFFER_TRUNC_MARKER_LEN + 1;
         }         }
               else
               {
                   // Now the message fits into the buffer.
                   ttlMsgLen++;  //Include the '/0'
  
         if ((Uint32)ttlMsgLen > _overflowBufferSize)                  _traceArea->nextPos += ttlMsgLen;
                   _leftBytesInBuffer -= ttlMsgLen;
               }
           } // End of vsnprintf() == -1 or message > buffer size
           else
           {
               // vsnprintf() retuns number of bytes of the variable message and
               // the Message fits in the buffer.
               if ((Uint32)ttlMsgLen >= _overflowBufferSize)
         {         {
             if (_overflowBuffer != NULL )             if (_overflowBuffer != NULL )
             {             {
                 delete[] _overflowBuffer;                 delete[] _overflowBuffer;
             }             }
             _overflowBufferSize = ttlMsgLen;                  _overflowBufferSize = ttlMsgLen+1;
             _overflowBuffer = new char[_overflowBufferSize];             _overflowBuffer = new char[_overflowBufferSize];
         }         }
  
Line 433 
Line 485 
                               argListCopy);                               argListCopy);
 #endif #endif
  
               // The actual number of characters written to the buffer is the
               // number of bytes left in the buffer minus the trailing '/0'.
               Uint32 numCharsWritten = _leftBytesInBuffer-1;
  
         // Now calculate how much data we have to copy from the overflow         // Now calculate how much data we have to copy from the overflow
         // buffer back to the trace buffer.         // buffer back to the trace buffer.
         ttlMsgLen -= _leftBytesInBuffer;              ttlMsgLen -= numCharsWritten;
  
         // Copy the remainder of the trace message to the trace buffer         // Copy the remainder of the trace message to the trace buffer
         memcpy(&(_traceArea->traceBuffer[0]),         memcpy(&(_traceArea->traceBuffer[0]),
                &(_overflowBuffer[_leftBytesInBuffer]),                     &(_overflowBuffer[numCharsWritten]),
                ttlMsgLen );                ttlMsgLen );
  
         _traceArea->nextPos = ttlMsgLen+1;         _traceArea->nextPos = ttlMsgLen+1;
         _leftBytesInBuffer = _traceArea->bufferSize - _traceArea->nextPos;         _leftBytesInBuffer = _traceArea->bufferSize - _traceArea->nextPos;
     }     }
       } // End of reached end of buffer and need to wrap.
  
     // replace null terminator with line break     // replace null terminator with line break
     _traceArea->traceBuffer[_traceArea->nextPos-1] = '\n';     _traceArea->traceBuffer[_traceArea->nextPos-1] = '\n';


Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2