version 1.4, 2008/09/04 18:10:31
|
version 1.8, 2008/09/18 07:50:07
|
|
|
#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) |
| |
|
|
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); |
| |
|
|
// 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 ((Uint32)ttlMsgLen > _overflowBufferSize) |
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); |
|
|
|
// 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 message still does not fit in the buffer, but know |
|
// we know that the most part of the message is in the buffer. |
|
// Truncate the message using the truncation marker and leave |
|
// space for the EOT marker + '\n'. |
|
_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' |
|
|
|
_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]; |
} | } |
| |
|
|
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'; |