Initial
This commit is contained in:
82
logfile/LOGFILE.CPP
Normal file
82
logfile/LOGFILE.CPP
Normal file
@@ -0,0 +1,82 @@
|
||||
#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"));
|
||||
}
|
||||
47
logfile/LOGFILE.HPP
Normal file
47
logfile/LOGFILE.HPP
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef _LOGFILE_LOGFILE_HPP_
|
||||
#define _LOGFILE_LOGFILE_HPP_
|
||||
#ifndef _COMMON_PUREVIEWOFFILE_HPP_
|
||||
#include <common/pview.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_FILEMAP_HPP_
|
||||
#include <common/filemap.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_EVENT_HPP_
|
||||
#include <thread/event.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_MUTEX_HPP_
|
||||
#include <thread/mutex.hpp>
|
||||
#endif
|
||||
#ifndef _FILEIO_FILEIO_HPP_
|
||||
#include <fileio/fileio.hpp>
|
||||
#endif
|
||||
|
||||
class LogFile
|
||||
{
|
||||
public:
|
||||
LogFile(const String &strLogName=String("LOGFILE"));
|
||||
virtual ~LogFile();
|
||||
BOOL writeLine(const String &strLine);
|
||||
BOOL write(const String &strLine);
|
||||
BOOL write(Block<String> &strLines);
|
||||
BOOL read(String &strLine);
|
||||
BOOL read(Block<String> &strLines);
|
||||
void synchronize(void);
|
||||
private:
|
||||
void log(const String &msg);
|
||||
|
||||
FileMap mFileMap;
|
||||
PureViewOfFile mFileView;
|
||||
Event mIOEvent;
|
||||
Event mIOAckEvent;
|
||||
Mutex mMutex;
|
||||
BOOL mIsAckPending;
|
||||
FileIO mLogFile;
|
||||
};
|
||||
|
||||
inline
|
||||
BOOL LogFile::writeLine(const String &strLine)
|
||||
{
|
||||
return write(strLine);
|
||||
}
|
||||
#endif
|
||||
219
logfile/LOGFILE.MAK
Normal file
219
logfile/LOGFILE.MAK
Normal file
@@ -0,0 +1,219 @@
|
||||
# Microsoft Developer Studio Generated NMAKE File, Format Version 4.20
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
!IF "$(CFG)" == ""
|
||||
CFG=logfile - Win32 Debug
|
||||
!MESSAGE No configuration specified. Defaulting to logfile - Win32 Debug.
|
||||
!ENDIF
|
||||
|
||||
!IF "$(CFG)" != "logfile - Win32 Release" && "$(CFG)" !=\
|
||||
"logfile - Win32 Debug"
|
||||
!MESSAGE Invalid configuration "$(CFG)" specified.
|
||||
!MESSAGE You can specify a configuration when running NMAKE on this makefile
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "logfile.mak" CFG="logfile - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "logfile - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "logfile - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
!ERROR An invalid configuration is specified.
|
||||
!ENDIF
|
||||
|
||||
!IF "$(OS)" == "Windows_NT"
|
||||
NULL=
|
||||
!ELSE
|
||||
NULL=nul
|
||||
!ENDIF
|
||||
################################################################################
|
||||
# Begin Project
|
||||
# PROP Target_Last_Scanned "logfile - Win32 Debug"
|
||||
CPP=cl.exe
|
||||
|
||||
!IF "$(CFG)" == "logfile - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
OUTDIR=.\Release
|
||||
INTDIR=.\Release
|
||||
|
||||
ALL : "$(OUTDIR)\logfile.lib"
|
||||
|
||||
CLEAN :
|
||||
-@erase "$(INTDIR)\logfile.obj"
|
||||
-@erase "$(OUTDIR)\logfile.lib"
|
||||
|
||||
"$(OUTDIR)" :
|
||||
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
|
||||
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
|
||||
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\
|
||||
/Fp"$(INTDIR)/logfile.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
CPP_OBJS=.\Release/
|
||||
CPP_SBRS=.\.
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
BSC32_FLAGS=/nologo /o"$(OUTDIR)/logfile.bsc"
|
||||
BSC32_SBRS= \
|
||||
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
LIB32_FLAGS=/nologo /out:"$(OUTDIR)/logfile.lib"
|
||||
LIB32_OBJS= \
|
||||
"$(INTDIR)\logfile.obj"
|
||||
|
||||
"$(OUTDIR)\logfile.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
|
||||
$(LIB32) @<<
|
||||
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
|
||||
<<
|
||||
|
||||
!ELSEIF "$(CFG)" == "logfile - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "msvcobj"
|
||||
# PROP Intermediate_Dir "msvcobj"
|
||||
# PROP Target_Dir ""
|
||||
OUTDIR=.\msvcobj
|
||||
INTDIR=.\msvcobj
|
||||
|
||||
ALL : "..\exe\logfile.lib"
|
||||
|
||||
CLEAN :
|
||||
-@erase "$(INTDIR)\logfile.obj"
|
||||
-@erase "..\exe\logfile.lib"
|
||||
|
||||
"$(OUTDIR)" :
|
||||
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
|
||||
|
||||
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /Zp1 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__FLAT__" /D "STRICT" /YX /c
|
||||
CPP_PROJ=/nologo /Zp1 /MTd /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D\
|
||||
"__FLAT__" /D "STRICT" /Fp"$(INTDIR)/logfile.pch" /YX /Fo"$(INTDIR)/" /c
|
||||
CPP_OBJS=.\msvcobj/
|
||||
CPP_SBRS=.\.
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
BSC32_FLAGS=/nologo /o"$(OUTDIR)/logfile.bsc"
|
||||
BSC32_SBRS= \
|
||||
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"..\exe\logfile.lib"
|
||||
LIB32_FLAGS=/nologo /out:"..\exe\logfile.lib"
|
||||
LIB32_OBJS= \
|
||||
"$(INTDIR)\logfile.obj"
|
||||
|
||||
"..\exe\logfile.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
|
||||
$(LIB32) @<<
|
||||
$(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
|
||||
<<
|
||||
|
||||
!ENDIF
|
||||
|
||||
.c{$(CPP_OBJS)}.obj:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
.cpp{$(CPP_OBJS)}.obj:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
.cxx{$(CPP_OBJS)}.obj:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
.c{$(CPP_SBRS)}.sbr:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
.cpp{$(CPP_SBRS)}.sbr:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
.cxx{$(CPP_SBRS)}.sbr:
|
||||
$(CPP) $(CPP_PROJ) $<
|
||||
|
||||
################################################################################
|
||||
# Begin Target
|
||||
|
||||
# Name "logfile - Win32 Release"
|
||||
# Name "logfile - Win32 Debug"
|
||||
|
||||
!IF "$(CFG)" == "logfile - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "logfile - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
################################################################################
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\logfile.cpp
|
||||
|
||||
!IF "$(CFG)" == "logfile - Win32 Release"
|
||||
|
||||
DEP_CPP_LOGFI=\
|
||||
{$(INCLUDE)}"\.\logfile.hpp"\
|
||||
{$(INCLUDE)}"\Common\Assert.hpp"\
|
||||
{$(INCLUDE)}"\Common\Block.hpp"\
|
||||
{$(INCLUDE)}"\Common\Block.tpp"\
|
||||
{$(INCLUDE)}"\Common\Filemap.hpp"\
|
||||
{$(INCLUDE)}"\Common\Puredwrd.hpp"\
|
||||
{$(INCLUDE)}"\Common\Pview.hpp"\
|
||||
{$(INCLUDE)}"\Common\Stdio.hpp"\
|
||||
{$(INCLUDE)}"\Common\Stdlib.hpp"\
|
||||
{$(INCLUDE)}"\Common\String.hpp"\
|
||||
{$(INCLUDE)}"\Common\Windows.hpp"\
|
||||
{$(INCLUDE)}"\fileio\fileio.hpp"\
|
||||
{$(INCLUDE)}"\Thread\Event.hpp"\
|
||||
{$(INCLUDE)}"\Thread\Mutex.hpp"\
|
||||
|
||||
|
||||
"$(INTDIR)\logfile.obj" : $(SOURCE) $(DEP_CPP_LOGFI) "$(INTDIR)"
|
||||
|
||||
|
||||
!ELSEIF "$(CFG)" == "logfile - Win32 Debug"
|
||||
|
||||
DEP_CPP_LOGFI=\
|
||||
{$(INCLUDE)}"\.\logfile.hpp"\
|
||||
{$(INCLUDE)}"\Common\Assert.hpp"\
|
||||
{$(INCLUDE)}"\Common\Block.hpp"\
|
||||
{$(INCLUDE)}"\Common\Block.tpp"\
|
||||
{$(INCLUDE)}"\Common\Filemap.hpp"\
|
||||
{$(INCLUDE)}"\Common\Puredwrd.hpp"\
|
||||
{$(INCLUDE)}"\Common\Pview.hpp"\
|
||||
{$(INCLUDE)}"\Common\Stdio.hpp"\
|
||||
{$(INCLUDE)}"\Common\Stdlib.hpp"\
|
||||
{$(INCLUDE)}"\Common\String.hpp"\
|
||||
{$(INCLUDE)}"\Common\Windows.hpp"\
|
||||
{$(INCLUDE)}"\fileio\fileio.hpp"\
|
||||
{$(INCLUDE)}"\Thread\Event.hpp"\
|
||||
{$(INCLUDE)}"\Thread\Mutex.hpp"\
|
||||
|
||||
|
||||
"$(INTDIR)\logfile.obj" : $(SOURCE) $(DEP_CPP_LOGFI) "$(INTDIR)"
|
||||
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
################################################################################
|
||||
BIN
logfile/LOGFILE.MDP
Normal file
BIN
logfile/LOGFILE.MDP
Normal file
Binary file not shown.
Reference in New Issue
Block a user