diff --git a/src/main.cpp b/src/main.cpp index 09d0c446..713f3e26 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -164,11 +164,6 @@ int main ( int argc, char** argv ) //CTestbench Testbench ( "127.0.0.1", LLCON_DEFAULT_PORT_NUMBER ); -// TEST -CServerLogging ServerLogging; -exit(1); - - try { if ( bIsClient ) diff --git a/src/server.cpp b/src/server.cpp index 844efaf5..2c7bd951 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -104,27 +104,13 @@ void CServer::Stop() Timer.stop(); // logging - const QString strLogStr = CLogTimeDate::toString() + ",, server stopped " - "-------------------------------------"; - -#ifndef _WIN32 - QTextStream tsConsoloeStream ( stdout ); - tsConsoloeStream << strLogStr << endl; // on console -#endif - Logging << strLogStr; // in log file + Logging.AddServerStopped(); } void CServer::OnNewChannel ( CHostAddress ChanAddr ) { // logging of new connected channel - const QString strLogStr = CLogTimeDate::toString() + ", " + - ChanAddr.InetAddr.toString() + ", connected"; - -#ifndef _WIN32 - QTextStream tsConsoloeStream ( stdout ); - tsConsoloeStream << strLogStr << endl; // on console -#endif - Logging << strLogStr; // in log file + Logging.AddNewConnection ( ChanAddr.InetAddr ); } void CServer::OnTimer() diff --git a/src/server.h b/src/server.h index d11e21ee..8a01a0c4 100755 --- a/src/server.h +++ b/src/server.h @@ -33,6 +33,7 @@ #include "socket.h" #include "channel.h" #include "util.h" +#include "serverlogging.h" /* Classes ********************************************************************/ @@ -82,7 +83,7 @@ protected: CCycleTimeVariance CycleTimeVariance; // logging - CLogging Logging; + CServerLogging Logging; public slots: void OnTimer(); diff --git a/src/serverlogging.cpp b/src/serverlogging.cpp index 3f078a19..9f5660ee 100755 --- a/src/serverlogging.cpp +++ b/src/serverlogging.cpp @@ -26,8 +26,13 @@ /* Implementation *************************************************************/ -CServerLogging::CServerLogging() +CServerLogging::CServerLogging() : + bDoLogging ( false ), File ( DEFAULT_LOG_FILE_NAME ) { + + +#if 0 + int i; // constants defining the plot properties @@ -90,9 +95,10 @@ CServerLogging::CServerLogging() iCurX, PlotGridFrame.bottom() ); } - // grid (ticks) for y-axis + // grid (ticks) for y-axis, draw iNumTicksY - 2 grid lines and + // iNumTicksY - 1 text labels (the lowest grid line is the grid frame) const int iYSpace = PlotGridFrame.height() / ( iNumTicksY - 1 ); - for ( i = 0; i < ( iNumTicksY - 2 ); i++ ) + for ( i = 0; i < ( iNumTicksY - 1 ); i++ ) { const int iCurY = PlotGridFrame.y() + iYSpace * ( i + 1 ); @@ -102,14 +108,17 @@ CServerLogging::CServerLogging() PlotPainter.drawText ( QPoint ( PlotGridFrame.x() + iTextOffsetToGrid, iCurY - iTextOffsetToGrid ), - QString().setNum ( + QString ( "%1:00" ).arg ( ( iYAxisEnd - iYAxisStart ) / ( iNumTicksY - 1 ) * ( ( iNumTicksY - 2 ) - i ) ) ); - // grid - PlotPainter.setPen ( PlotGridColor ); - PlotPainter.drawLine ( PlotGridFrame.x(), iCurY, - PlotGridFrame.right(), iCurY ); + // grid (do not overwrite frame) + if ( i < ( iNumTicksY - 2 ) ) + { + PlotPainter.setPen ( PlotGridColor ); + PlotPainter.drawLine ( PlotGridFrame.x(), iCurY, + PlotGridFrame.right(), iCurY ); + } } @@ -117,4 +126,72 @@ CServerLogging::CServerLogging() // save plot as a file PlotPixmap.save ( "test.jpg", "JPG", 90 ); +#endif +} + +CServerLogging::~CServerLogging() +{ + // close logging file of open + if ( File.isOpen() ) + { + File.close(); + } +} + +void CServerLogging::Start ( const QString& strLoggingFileName ) +{ + // open file + File.setFileName ( strLoggingFileName ); + if ( File.open ( QIODevice::Append | QIODevice::Text ) ) + { + bDoLogging = true; + } +} + +void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr ) +{ + // logging of new connected channel + const QString strLogStr = CurTimeDatetoLogString() + ", " + + ClientInetAddr.toString() + ", connected"; + +#ifndef _WIN32 + QTextStream tsConsoloeStream ( stdout ); + tsConsoloeStream << strLogStr << endl; // on console +#endif + *this << strLogStr; // in log file +} + +void CServerLogging::AddServerStopped() +{ + const QString strLogStr = CurTimeDatetoLogString() + ",, server stopped " + "-------------------------------------"; + +#ifndef _WIN32 + QTextStream tsConsoloeStream ( stdout ); + tsConsoloeStream << strLogStr << endl; // on console +#endif + *this << strLogStr; // in log file +} + +void CServerLogging::operator<< ( const QString& sNewStr ) +{ + if ( bDoLogging ) + { + // append new line in logging file + QTextStream out ( &File ); + out << sNewStr << endl; + File.flush(); + } +} + +QString CServerLogging::CurTimeDatetoLogString() +{ + // time and date to string conversion + const QDateTime curDateTime = QDateTime::currentDateTime(); + + // format date and time output according to "3.9.2006, 11:38:08" + return QString().setNum ( curDateTime.date().day() ) + "." + + QString().setNum ( curDateTime.date().month() ) + "." + + QString().setNum ( curDateTime.date().year() ) + ", " + + curDateTime.time().toString(); } diff --git a/src/serverlogging.h b/src/serverlogging.h index 059268bb..940b35ea 100755 --- a/src/serverlogging.h +++ b/src/serverlogging.h @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include "global.h" @@ -36,6 +39,18 @@ class CServerLogging { public: CServerLogging(); + virtual ~CServerLogging(); + + void Start ( const QString& strLoggingFileName ); + void AddNewConnection ( const QHostAddress& ClientInetAddr ); + void AddServerStopped(); + +protected: + void operator<< ( const QString& sNewStr ); + QString CurTimeDatetoLogString(); + + bool bDoLogging; + QFile File; }; #endif /* !defined ( SERVERLOGGING_HOIHOKIH83JH8_3_43445KJIUHF1912__INCLUDED_ ) */ diff --git a/src/util.h b/src/util.h index cea61ba2..a2dc212f 100755 --- a/src/util.h +++ b/src/util.h @@ -323,7 +323,6 @@ template void CMovingAv::Add ( const TData tNewD ) } - /******************************************************************************\ * GUI utilities * \******************************************************************************/ @@ -545,64 +544,6 @@ public: }; -// Time and Data to String conversion ------------------------------------------ -class CLogTimeDate -{ -public: - static QString toString() - { - const QDateTime curDateTime = QDateTime::currentDateTime(); - - // format date and time output according to "3.9.2006, 11:38:08" - return QString().setNum ( curDateTime.date().day() ) + "." + - QString().setNum ( curDateTime.date().month() ) + "." + - QString().setNum ( curDateTime.date().year() ) + ", " + - curDateTime.time().toString(); - } -}; - - -// Logging --------------------------------------------------------------------- -class CLogging -{ -public: - CLogging() : bDoLogging ( false ), File ( DEFAULT_LOG_FILE_NAME ) {} - virtual ~CLogging() - { - if ( File.isOpen() ) - { - File.close(); - } - } - - void Start ( const QString& strLoggingFileName ) - { - // open file - File.setFileName ( strLoggingFileName ); - if ( File.open ( QIODevice::Append | QIODevice::Text ) ) - { - bDoLogging = true; - } - } - - void operator<< ( const QString& sNewStr ) - { - if ( bDoLogging ) - { - // append new line in logging file - QTextStream out ( &File ); - out << sNewStr << endl; - File.flush(); - } - } - -protected: - bool bDoLogging; - QFile File; -}; - - - /******************************************************************************\ * Cycle Time Variance Measurement * \******************************************************************************/