add parsing of old logging files for history graph (server)

This commit is contained in:
Volker Fischer 2009-09-02 18:03:37 +00:00
parent b08b5e6dd6
commit e664b5769c
3 changed files with 101 additions and 22 deletions

View file

@ -145,18 +145,26 @@ CServer::CServer ( const QString& strLoggingFileName,
CycleTimeVariance.Init ( SYSTEM_FRAME_SIZE_SAMPLES,
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
// enable logging (if requested)
if ( !strLoggingFileName.isEmpty() )
{
Logging.Start ( strLoggingFileName );
}
// enable history graph (if requested)
if ( !strHistoryFileName.isEmpty() )
{
Logging.EnableHistory ( strHistoryFileName );
}
// enable logging (if requested)
if ( !strLoggingFileName.isEmpty() )
{
// in case the history is enabled and a logging file name is
// given, parse the logging file for old entries which are then
// added in the history on software startup
if ( !strHistoryFileName.isEmpty() )
{
Logging.ParseLogFile ( strLoggingFileName );
}
Logging.Start ( strLoggingFileName );
}
// HTML status file writing
if ( !strHTMLStatusFileName.isEmpty() )
{

View file

@ -221,6 +221,27 @@ void CHistoryGraph::Save ( const QString sFileName )
PlotPixmap.save ( sFileName, "JPG", 90 );
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const QHostAddress ClientInetAddr )
{
if ( bDoHistory )
{
// add element to history, distinguish between a local connection
// and a remote connection
if ( ( ClientInetAddr == QHostAddress ( "127.0.0.1" ) ) ||
( ClientInetAddr.toString().left ( 7 ).compare ( "192.168" ) == 0 ) )
{
// local connection
Add ( newDateTime, CHistoryGraph::HIT_LOCAL_CONNECTION );
}
else
{
// remote connection
Add ( newDateTime, CHistoryGraph::HIT_REMOTE_CONNECTION );
}
}
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const EHistoryItemType curType )
{
@ -275,6 +296,7 @@ void CHistoryGraph::Update()
}
// Server logging --------------------------------------------------------------
CServerLogging::~CServerLogging()
{
// close logging file of open
@ -311,21 +333,8 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
#endif
*this << strLogStr; // in log file
// add element to history, distinguish between a local connection
// and a remote connection
if ( ( ClientInetAddr == QHostAddress ( "127.0.0.1" ) ) ||
( ClientInetAddr.toString().left ( 7 ).compare ( "192.168" ) == 0 ) )
{
// local connection
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_LOCAL_CONNECTION );
}
else
{
// remote connection
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_REMOTE_CONNECTION );
}
// add element to history
HistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
}
void CServerLogging::AddServerStopped()
@ -357,6 +366,66 @@ void CServerLogging::operator<< ( const QString& sNewStr )
}
}
void CServerLogging::ParseLogFile ( const QString& strFileName )
{
// open file for reading
QFile LogFile ( strFileName );
LogFile.open ( QIODevice::ReadOnly | QIODevice::Text );
QTextStream inStream ( &LogFile );
// read all content from file
while ( !inStream.atEnd() )
{
// get a new line from log file
QString strCurLine = inStream.readLine();
// parse log file line
QStringList strlistCurLine = strCurLine.split( "," );
// check number of separated strings condition
if ( strlistCurLine.size() == 4 )
{
// first entry
QDate curDate =
QDate::fromString ( strlistCurLine.at ( 0 ).trimmed(),
"d.M.yyyy" );
// second entry
QTime curTime =
QTime::fromString ( strlistCurLine.at ( 1 ).trimmed(),
"hh:mm:ss" );
if ( curDate.isValid() && curTime.isValid() )
{
QDateTime curDateTime ( curDate, curTime );
// check if server stop or new client connection
QString strAddress = strlistCurLine.at ( 2 ).trimmed();
if ( strAddress.isEmpty() )
{
// server stop
HistoryGraph.Add ( curDateTime,
CHistoryGraph::HIT_SERVER_STOP );
}
else
{
QHostAddress curAddress;
// third entry is IP address
if ( curAddress.setAddress ( strlistCurLine.at ( 2 ).trimmed() ) )
{
// new client connection
HistoryGraph.Add ( curDateTime, curAddress );
}
}
}
}
}
HistoryGraph.Update();
}
QString CServerLogging::CurTimeDatetoLogString()
{
// time and date to string conversion

View file

@ -38,7 +38,7 @@
/* Definitions ****************************************************************/
// number of history items to store
#define NUM_ITEMS_HISTORY 400
#define NUM_ITEMS_HISTORY 600
/* Classes ********************************************************************/
@ -57,6 +57,7 @@ public:
CHistoryGraph();
void Start ( const QString& sNewFileName );
void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
void Add ( const QDateTime& newDateTime, const QHostAddress ClientInetAddr );
void Update();
protected:
@ -115,6 +116,7 @@ public:
void EnableHistory ( const QString& strHistoryFileName );
void AddNewConnection ( const QHostAddress& ClientInetAddr );
void AddServerStopped();
void ParseLogFile ( const QString& strFileName );
protected:
void operator<< ( const QString& sNewStr );