#ifndef _PROTO_LOGFILE_HPP_ #define _PROTO_LOGFILE_HPP_ #ifndef _COMMON_PUREVIEWOFFILE_HPP_ #include #endif #ifndef _COMMON_FILEMAP_HPP_ #include #endif #ifndef _THREAD_EVENT_HPP_ #include #endif #ifndef _THREAD_MUTEX_HPP_ #include #endif class LogFile { public: LogFile(const String &strLogName); virtual ~LogFile(); BOOL write(const String &strLine); BOOL write(Block &strLines); BOOL read(String &strLine); BOOL read(Block &strLines); void synchronize(void); private: void log(const String &msg); FileMap mFileMap; PureViewOfFile mFileView; Event mIOEvent; Event mIOAckEvent; Mutex mMutex; BOOL mIsAckPending; }; LogFile::LogFile(const String &strLogName) : mFileMap(strLogName,0,1000000), mFileView(mFileMap), mIOEvent("IOPUTEVENT",FALSE), mIOAckEvent("IOACKEVENT",FALSE), mMutex("IOENTERREQUEST",FALSE), mIsAckPending(FALSE) { } LogFile::~LogFile() { } BOOL LogFile::write(const String &strLine) { mIOAckEvent.waitEvent(); mIOAckEvent.resetEvent(); mMutex.requestMutex(); mFileView.rewind(); mFileView.writeLine(strLine); mMutex.releaseMutex(); mIOEvent.setEvent(); return TRUE; } BOOL LogFile::write(Block &strLines) { mIOAckEvent.waitEvent(); mIOAckEvent.resetEvent(); mMutex.requestMutex(); mFileView.rewind(); for(int lineIndex=0;lineIndex &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")); } #endif