C12Adapter Opensource C++ Interface
MLogFileReader Class Reference

Log file utility class to handle the log from the monitor. More...

Inheritance diagram for MLogFileReader:

Public Types

typedef Muint32 PositionType
 Type used to denote the reader position. More...
 
- Public Types inherited from MLogFile
enum  {
  PAGE_HEADER_SIGNATURE = 0xA2EBBAED,
  PAGE_OBFUSCATED_HEADER_SIGNATURE = 0xA2EBBAEC,
  PAGE_TOTAL_SIZE = 0x1000,
  PAGE_HEADER_SIZE = 16,
  PAGE_FOOTER_SIZE = 4,
  PAGE_BODY_SIZE = PAGE_TOTAL_SIZE - PAGE_HEADER_SIZE - PAGE_FOOTER_SIZE,
  PACKET_HEADER_SIZE = 10,
  NUMBER_OF_PAGES_LIMIT = 0xFFFF
}
 

Public Member Functions

 MLogFileReader ()
 Constructor that creates an uninitialized log file object.
 
 MLogFileReader (const MStdString &fileName)
 Constructor that creates an existing log file with the given file name. More...
 
virtual ~MLogFileReader ()
 Object destructor, close the log file.
 
void Open (const MStdString &fileName)
 Open an existing file to read. More...
 
void Reset ()
 Reset the current pointer, one that walks through messages. More...
 
bool EndOfFile () const
 Tells if the current position is the End of the File. More...
 
const MLogFile::PacketHeaderReadPacketHeader ()
 Read the packet header of the current packet. More...
 
unsigned GetPacketBodyLength () const
 Get the length of the packet body after the reader was read successfully. More...
 
void ReadPacketBody (char *buffer)
 Fill the given buffer with the body characters of the packet and advance the file pointer to the next packet. More...
 
void SkipPacketBody ()
 Skip the body of the packet and advance to the next packet. More...
 
PositionType GetPosition () const
 Get the position of the current packet within an opened file. More...
 
void SetPosition (PositionType ptr)
 Get the position of the current packet within an opened file. More...
 
- Public Member Functions inherited from MLogFile
virtual ~MLogFile ()
 Object destructor, close the log file.
 
bool IsOpen () const
 Tells if the file is open. More...
 
const MStdStringGetFileName () const
 Get the file name, as set for logging. More...
 
const MStdStringGetOpenWarnings () const
 Get the warning message which might arise during opening a file and checking its contents. More...
 
void SetListener (MMonitorFile *listener)
 Sets the listener object to start handling events. More...
 
virtual void Close ()
 Close the file, if it was open.
 
bool GetObfuscate () const
 
void SetObfuscate (bool yes)
 

Additional Inherited Members

- Protected Member Functions inherited from MLogFile
 MLogFile ()
 Constructor that creates an uninitialized log file object.
 

Detailed Description

Log file utility class to handle the log from the monitor.

The concrete instances of this class will provide facilities for reading and writing the log files.

Reader can walk through the file sequentially. Also, it is possible to save and restore the current position within a file. Position is bound to a concrete file and it will not be valid if the file changed. For that, it is recommended to use positions only for a currently opened file.

Typical way how the file is open and read is this:

// Traversing through the file
for ( ; !reader.EndOfFile(), reader.Next() )
{
const MLogFile::PacketHeader& header = reader.GetPacketHeader(); // getting header
char* buffer = new char [ reader.GetPacketBodyLength() ];
reader.GetPacketBody(buffer);
... using length and body here ...
if ( ptr0 == NULL )
ptr0 = reader.GetPosition(); // getting the pointer (example)
}
// Using pointer to set the current position for the reader:
reader.SetPosition(ptr0);
const MLogFile::PacketHeader& header = reader.GetPacketHeader(); // getting header
char* buffer = new char [ header.m_length ];
reader.GetPacketBody(buffer);

Member Typedef Documentation

Type used to denote the reader position.

It allows storing and restoring the position within the file. Position pointer of NULL will point to nowhere.

Constructor & Destructor Documentation

MLogFileReader::MLogFileReader ( const MStdString fileName)
inlineexplicit

Constructor that creates an existing log file with the given file name.

Precondition
File, if given, shall be a valid file name, or an exception is thrown. Write access to a file is attempted. If anything fails there is an exception.

Member Function Documentation

bool MLogFileReader::EndOfFile ( ) const
inline

Tells if the current position is the End of the File.

End of the file position pointer will be a NULL pointer.

Precondition
The file has to be open, there is an assertion.
unsigned MLogFileReader::GetPacketBodyLength ( ) const
inline

Get the length of the packet body after the reader was read successfully.

Precondition
It shall not be an end of file condition, or there is an assertion.
PositionType MLogFileReader::GetPosition ( ) const
inline

Get the position of the current packet within an opened file.

Position is like pointer, except that it points to a place within an opened log file. It is guaranteed that the position will be of a size the same as the size of a pointer to any type (like void). Also, NULL pointer will point to no object, and referencing it its position will lead to EndOfFile condition.

void MLogFileReader::Open ( const MStdString fileName)

Open an existing file to read.

Precondition
The file shall be a valid file name, the open procedure has to be achievable by the operating system, or an exception is thrown.
void MLogFileReader::ReadPacketBody ( char *  buffer)

Fill the given buffer with the body characters of the packet and advance the file pointer to the next packet.

Precondition
The buffer shall be at least of the size denoted by GetPacketBodyLength(), or the behavior is undefined. It shall not be an end of file condition, or there is an assertion.
const MLogFile::PacketHeader& MLogFileReader::ReadPacketHeader ( )

Read the packet header of the current packet.

Precondition
It shall not be an end of file condition, or there is an assertion.
void MLogFileReader::Reset ( )
inline

Reset the current pointer, one that walks through messages.

Position points to the first item in a file.

Precondition
The file has to be successfully open, there is an assertion. Also, file read error can be raised.
void MLogFileReader::SetPosition ( PositionType  ptr)

Get the position of the current packet within an opened file.

Position is like pointer, except that it points to a place within an opened log file. It is guaranteed that the position will be of a size the same as the size of a pointer to any type (like void). Also, NULL pointer will point to no object, and referencing it its position will lead to EndOfFile condition.

void MLogFileReader::SkipPacketBody ( )

Skip the body of the packet and advance to the next packet.

Precondition
It shall not be an end of file condition, or there is an assertion. Also, any file-related exception can be thrown.