ApparatusFramework::LogFileDevice Class Reference
[Device Services]

#include <DeviceServices/Win32/current/include/LogFileDevice.h>

Inheritance diagram for ApparatusFramework::LogFileDevice:
ApparatusFramework::FileDevice ApparatusFramework::CharDevice

List of all members.

Public Member Functions

 LogFileDevice (int maxNumberOfFiles, int maxFileSize, char *logPath, char *baseFileName, char *fileExtension)
 LogFileDevice ()
 ~LogFileDevice ()
virtual int32 open (void *args)
virtual int32 close ()
virtual int32 read (uint8 *buffer, const int32 count)
virtual int32 write (uint8 *buffer, const int32 count)
virtual int32 ioCtl (uint32 cmd, void *arg)
virtual int32 seek (uint32 offset, SeekWhenceEnum whence)
virtual void flush ()

Detailed Description

A class to write log messages into a logfile device. The user can set maximal number of files, maximal file size, file location, basefile name and the file extension for the logfiles. The body of a logfile will look like the following buildup:

[basefile name].[file name counter].[file extension]

For example: Log.0.txt Log is in this example the basefile name, 0 the file counter and txt the extension.

There is a check, if the maximum file size is reached, it increments the file name counter, builds the new file name and creates a new log file out of this new builded file name. If the maximum file number is reached, it deletes the oldest one, so that the maximum file number can never be exceeded.

To use this, make a instance of this class, register it, and set this log device like in the following example:

LogFileDevice theLogFileDevice(100, 50000, "/home/rene/logs/","Log","txt");

DeviceMgr::Create(); Logger::Create();

DeviceMgr::Default()->registerDevice((CharDevice*)&theLogFileDevice, "DEVNAME"); Logger::Default()->setLogDevice("DEVNAME");

An other way to use this logfile device is explained by the next example. This shows the late binding of the parameter.

LogFileDevice theLogFileDevice = LogFileDevice(); theLogFileDevice.ioCtl(LOG_FILE_DEVICE_SET_MAX_NUMBER_OF_FILES, (void*)100); theLogFileDevice.ioCtl(LOG_FILE_DEVICE_SET_MAX_FILE_SIZE, (void*)50000); theLogFileDevice.ioCtl(LOG_FILE_DEVICE_SET_LOG_PATH, (void*)logPath); theLogFileDevice.ioCtl(LOG_FILE_DEVICE_SET_BASE_FILE_NAME, (void*)baseFileName); theLogFileDevice.ioCtl(LOG_FILE_DEVICE_SET_LOG_FILE_EXTENSION, (void*)extension);

DeviceMgr::Create(); Logger::Create();

DeviceMgr::Default()->registerDevice((CharDevice*)&theLogFileDevice, "DEVNAME"); Logger::Default()->setLogDevice("DEVNAME");

Definition at line 116 of file LogFileDevice.h.


Constructor & Destructor Documentation

ApparatusFramework::LogFileDevice::LogFileDevice ( int  maxNumberOfFiles,
int  maxFileSize,
char *  logPath,
char *  baseFileName,
char *  fileExtension 
)

Construction, destruction Constructs a new logfile device and defines the following member variables:

Parameters:
maxNumberOfFiles Maximum number of logfiles to be created.
maxFileSize Maximum size of a logfile in bytes.
logPath Pointer to a character array. The array contains the folder path of the logfiles.
baseFileName Pointer to a character array. The array contains the logfile name without the file extension.
fileExtension Pointer to a character array. The array contains the file extension of the logfiles.
ApparatusFramework::LogFileDevice::LogFileDevice (  ) 

Constructs a new logfile device with default settings.

ApparatusFramework::LogFileDevice::~LogFileDevice (  ) 

Destructs a file device. Closes it if needed.


Member Function Documentation

virtual int32 ApparatusFramework::LogFileDevice::close (  )  [virtual]

Closes the file device, releases resources used for the operation. After another open, the device is ready for communication again.

Returns:
Status of the method. See CharDeviceRetVal

Reimplemented from ApparatusFramework::FileDevice.

virtual void ApparatusFramework::LogFileDevice::flush (  )  [inline, virtual]

Writes all internally buffered data onto the device and clears the send and receive buffers.

Reimplemented from ApparatusFramework::FileDevice.

Definition at line 187 of file LogFileDevice.h.

virtual int32 ApparatusFramework::LogFileDevice::ioCtl ( uint32  cmd,
void *  arg 
) [virtual]

Universal method that may be used to configure the logfile device and implement functionality not provided by the interface.

Parameters:
cmd A command that specifies the function to be executed by the method. Those are the command defined in LogFileDeviceIoCtlCmdEnum LOG_FILE_DEVICE_SET_MAX_NUMBER_OF_FILES : Maximal number of files to create LOG_FILE_DEVICE_SET_MAX_FILE_SIZE : Maximal size of each file LOG_FILE_DEVICE_SET_LOG_PATH : Path in which the log files will be created. This path must exist! LOG_FILE_DEVICE_SET_BASE_FILE_NAME : Name of the logfile which will be extended by .<number>.<extension> LOG_FILE_DEVICE_SET_LOG_FILE_EXTENSION : Extension of the logfile
arg A pointer to an argument passed to the function to be executed
Returns:
Status of the method. See CharDeviceRetVal

Reimplemented from ApparatusFramework::FileDevice.

virtual int32 ApparatusFramework::LogFileDevice::open ( void *  args  )  [virtual]

Inherited interface methods Opens the logfile device for read and write and gets the highest file name counter of the logfiles from the logdirectory. When there are no files in the logdirectory, the FileNameCounter starts with 0. If this method returns successfully, the device is ready to use.

Parameters:
arg A void pointer that can be used for whatever one choses (default = null).
Returns:
Status of the method. See CharDeviceRetVal

Reimplemented from ApparatusFramework::FileDevice.

virtual int32 ApparatusFramework::LogFileDevice::read ( uint8 buffer,
const int32  count 
) [virtual]

No function.

Reimplemented from ApparatusFramework::FileDevice.

virtual int32 ApparatusFramework::LogFileDevice::seek ( uint32  offset,
SeekWhenceEnum  whence 
) [virtual]

No function.

Reimplemented from ApparatusFramework::FileDevice.

virtual int32 ApparatusFramework::LogFileDevice::write ( uint8 buffer,
const int32  count 
) [virtual]

Writes a specified number of characters from a buffer onto the logfile device. It also checks the maximum file size or file number is reached.

Parameters:
buffer Pointer to a character buffer. Its the buffer that write takes as data source.
count Number of characters to be taken out of the buffer onto the device.
Returns:
Status of the method.

Reimplemented from ApparatusFramework::FileDevice.

© 2004-2010 bbv Software Services AG / Apparatus Services