diff --git a/src/server.cpp b/src/server.cpp index 7d7818f6..b5cfaaac 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -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() ) { diff --git a/src/serverlogging.cpp b/src/serverlogging.cpp index 490f6d4f..028e4ef4 100755 --- a/src/serverlogging.cpp +++ b/src/serverlogging.cpp @@ -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 diff --git a/src/serverlogging.h b/src/serverlogging.h index 4f65702d..1399896b 100755 --- a/src/serverlogging.h +++ b/src/serverlogging.h @@ -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 );