add parsing of old logging files for history graph (server)
This commit is contained in:
parent
b08b5e6dd6
commit
e664b5769c
3 changed files with 101 additions and 22 deletions
|
@ -145,18 +145,26 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
CycleTimeVariance.Init ( SYSTEM_FRAME_SIZE_SAMPLES,
|
CycleTimeVariance.Init ( SYSTEM_FRAME_SIZE_SAMPLES,
|
||||||
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
|
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
|
||||||
|
|
||||||
// enable logging (if requested)
|
|
||||||
if ( !strLoggingFileName.isEmpty() )
|
|
||||||
{
|
|
||||||
Logging.Start ( strLoggingFileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable history graph (if requested)
|
// enable history graph (if requested)
|
||||||
if ( !strHistoryFileName.isEmpty() )
|
if ( !strHistoryFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
Logging.EnableHistory ( strHistoryFileName );
|
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
|
// HTML status file writing
|
||||||
if ( !strHTMLStatusFileName.isEmpty() )
|
if ( !strHTMLStatusFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -221,6 +221,27 @@ void CHistoryGraph::Save ( const QString sFileName )
|
||||||
PlotPixmap.save ( sFileName, "JPG", 90 );
|
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,
|
void CHistoryGraph::Add ( const QDateTime& newDateTime,
|
||||||
const EHistoryItemType curType )
|
const EHistoryItemType curType )
|
||||||
{
|
{
|
||||||
|
@ -275,6 +296,7 @@ void CHistoryGraph::Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Server logging --------------------------------------------------------------
|
||||||
CServerLogging::~CServerLogging()
|
CServerLogging::~CServerLogging()
|
||||||
{
|
{
|
||||||
// close logging file of open
|
// close logging file of open
|
||||||
|
@ -311,21 +333,8 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
|
||||||
#endif
|
#endif
|
||||||
*this << strLogStr; // in log file
|
*this << strLogStr; // in log file
|
||||||
|
|
||||||
// add element to history, distinguish between a local connection
|
// add element to history
|
||||||
// and a remote connection
|
HistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerLogging::AddServerStopped()
|
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()
|
QString CServerLogging::CurTimeDatetoLogString()
|
||||||
{
|
{
|
||||||
// time and date to string conversion
|
// time and date to string conversion
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
/* Definitions ****************************************************************/
|
||||||
// number of history items to store
|
// number of history items to store
|
||||||
#define NUM_ITEMS_HISTORY 400
|
#define NUM_ITEMS_HISTORY 600
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
@ -57,6 +57,7 @@ public:
|
||||||
CHistoryGraph();
|
CHistoryGraph();
|
||||||
void Start ( const QString& sNewFileName );
|
void Start ( const QString& sNewFileName );
|
||||||
void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
|
void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
|
||||||
|
void Add ( const QDateTime& newDateTime, const QHostAddress ClientInetAddr );
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -115,6 +116,7 @@ public:
|
||||||
void EnableHistory ( const QString& strHistoryFileName );
|
void EnableHistory ( const QString& strHistoryFileName );
|
||||||
void AddNewConnection ( const QHostAddress& ClientInetAddr );
|
void AddNewConnection ( const QHostAddress& ClientInetAddr );
|
||||||
void AddServerStopped();
|
void AddServerStopped();
|
||||||
|
void ParseLogFile ( const QString& strFileName );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void operator<< ( const QString& sNewStr );
|
void operator<< ( const QString& sNewStr );
|
||||||
|
|
Loading…
Add table
Reference in a new issue