83 lines
1.7 KiB
C++
83 lines
1.7 KiB
C++
#include <logfile/logfile.hpp>
|
|
|
|
LogFile::LogFile(const String &strLogName)
|
|
: mFileMap(strLogName,0,1000000), mFileView(mFileMap), mIOEvent("IOPUTEVENT",FALSE),
|
|
mIOAckEvent("IOACKEVENT",FALSE), mMutex("IOENTERREQUEST",FALSE), mIsAckPending(FALSE)
|
|
{
|
|
mLogFile.open("APISPY.LOG",
|
|
FileIO::GenericWrite,
|
|
FileIO::FileShareRead,
|
|
FileIO::CreateAlways,
|
|
FileIO::Normal);
|
|
}
|
|
|
|
LogFile::~LogFile()
|
|
{
|
|
}
|
|
|
|
BOOL LogFile::write(const String &strLine)
|
|
{
|
|
mLogFile.writeLine(strLine);
|
|
mIOAckEvent.waitEvent();
|
|
mIOAckEvent.resetEvent();
|
|
mMutex.requestMutex();
|
|
mFileView.rewind();
|
|
mFileView.writeLine(strLine);
|
|
mMutex.releaseMutex();
|
|
mIOEvent.setEvent();
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL LogFile::write(Block<String> &strLines)
|
|
{
|
|
mIOAckEvent.waitEvent();
|
|
mIOAckEvent.resetEvent();
|
|
mMutex.requestMutex();
|
|
mFileView.rewind();
|
|
for(int lineIndex=0;lineIndex<strLines.size();lineIndex++)mFileView.writeLine(strLines[lineIndex]);
|
|
mMutex.releaseMutex();
|
|
mIOEvent.setEvent();
|
|
return TRUE;
|
|
}
|
|
|
|
inline
|
|
BOOL LogFile::read(String &strLine)
|
|
{
|
|
String lineString;
|
|
mIOEvent.waitEvent();
|
|
mMutex.requestMutex();
|
|
mIOEvent.resetEvent();
|
|
mFileView.rewind();
|
|
mFileView.getLine(lineString);
|
|
strLine=lineString;
|
|
mMutex.releaseMutex();
|
|
mIOAckEvent.setEvent();
|
|
return lineString.isNull();
|
|
}
|
|
|
|
inline
|
|
BOOL LogFile::read(Block<String> &strLines)
|
|
{
|
|
String strLine;
|
|
|
|
strLines.remove();
|
|
mIOEvent.waitEvent();
|
|
mMutex.requestMutex();
|
|
mIOEvent.resetEvent();
|
|
mFileView.rewind();
|
|
while(mFileView.getLine(strLine)&&!strLine.isNull())strLines.insert(&strLine);
|
|
mMutex.releaseMutex();
|
|
mIOAckEvent.setEvent();
|
|
return TRUE;
|
|
}
|
|
|
|
void LogFile::synchronize(void)
|
|
{
|
|
mIOAckEvent.setEvent();
|
|
}
|
|
|
|
void LogFile::log(const String &msg)
|
|
{
|
|
::OutputDebugString((String&)msg+String("\n"));
|
|
}
|