/*
 * Resize the log pool.
 */
void LogPool::Resize(long maxSize)
{
    assert(maxSize >= 0);

    mMaxSize = maxSize;
    while (mCurrentSize > mMaxSize)
        RemoveOldest();
}
bool WCache<cacheItem, cacheActual>::Cleanup()
{
    bool result = true;
    // this looks redundant, but the idea is, don't grab the mutex if there's no work to do
    if (RequiresOldItemCleanup())
    {
        boost::mutex::scoped_lock lock(sCacheMutex);
        while (RequiresOldItemCleanup())
        {
            if (!RemoveOldest())
            {
                result = false;
                break;
            }
        }
    }

    return result;
}
/*
 * Add a message at the head of the pool.
 */
void LogPool::Add(LogMessage* pLogMessage)
{
    pLogMessage->Acquire();     // bump up the ref count

    assert(pLogMessage->GetPrev() == NULL);
    assert(pLogMessage->GetNext() == NULL);

    if (mpHead == NULL) {
        assert(mpTail == NULL);
        mpTail = mpHead = pLogMessage;
    } else {
        assert(mpHead->GetPrev() == NULL);
        mpHead->SetPrev(pLogMessage);
        pLogMessage->SetNext(mpHead);
        mpHead = pLogMessage;
    }

    /* update the pool size, and remove old entries if necessary */
    mCurrentSize += pLogMessage->GetFootprint();

    while (mCurrentSize > mMaxSize)
        RemoveOldest();
}
Example #4
0
void MessageLog::PostError(unsigned char Magnitude, const char *ErrorMsg)
{
FILE *LogOut;
char *ErrorToList;
int FilterScan;

ErrorToList = (char *)ErrorMsg;

// Add to RootWin
if (GlobalApp->MCP)
	{
	GlobalApp->MCP->SetCurrentStatusText((char *)ErrorMsg);
	} // if

// Do the real stuff
if ((LogTop + 1) == LogSize)
	{
	LogTop = 1;
	strncpy(&LineArray[0], ErrorMsg, WCS_LOG_LINE_WIDTH);
	ErrorToList = &LineArray[0];
	LineArray[WCS_LOG_LINE_WIDTH - 1] = NULL;
	} // if
else
	{
	strncpy(&LineArray[LogTop * WCS_LOG_LINE_WIDTH], ErrorMsg, WCS_LOG_LINE_WIDTH);
	ErrorToList = &LineArray[LogTop * WCS_LOG_LINE_WIDTH];
	LineArray[((WCS_LOG_LINE_WIDTH * (LogTop + 1)) - 1)] = NULL;
	LogTop++;
	if (LoggedLines < LogSize)
		{
		LoggedLines++;
		} // if
	} // else

// Note: Go ahead and add the entry to the List object.
// If the log window is open but hidden, or even if it isn't opened,
// AddToListObj will cope.

if (LoggedLines == LogSize)
	{
	RemoveOldest();
	} // if

// Try to filter out bad characters.
for(FilterScan = 0; ErrorToList[FilterScan]; FilterScan++)
	{
	if (!isprint(ErrorToList[FilterScan]))
		{
		ErrorToList[FilterScan] = ' ';
		} // if
	} // for

if (!NativeWin)
	{
	if (Magnitude >= OpenSeverity)
		{
		OpenLogWin();
		} // if
	} // if
else
	{
	AddToListObj(ErrorToList);
	} // else

// Now log it to the logfile if needed.
if (LogFileEnable && LogFileName[0])
	{
	if (LogOut = PROJ_fopen(LogFileName, "a"))
		{
		fputs(ErrorMsg, LogOut);
		fputc('\n', LogOut);
		fclose(LogOut);
		} // if
	} // if

} // MessageLog::PostError
/*
 * Remove all entries.
 */
void LogPool::Clear(void)
{
    while (mpTail != NULL)
        RemoveOldest();
}