From 37d826630d1eaf3454a9e59ae42baa5cfcd90860 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 6 Jun 2009 10:07:01 +0000 Subject: [PATCH] first fully version of history --- linux/Makefile.am | 4 ++ src/main.cpp | 28 +++++++--- src/server.cpp | 7 +++ src/server.h | 1 + src/serverlogging.cpp | 126 ++++++++++++++++++++++++------------------ src/serverlogging.h | 19 +++++-- windows/MocQT.bat | 1 + windows/llcon.vcproj | 4 ++ 8 files changed, 124 insertions(+), 66 deletions(-) diff --git a/linux/Makefile.am b/linux/Makefile.am index 403ab9d0..0ee21a2b 100755 --- a/linux/Makefile.am +++ b/linux/Makefile.am @@ -96,6 +96,7 @@ BUILT_SOURCES=moc/moc_server.cpp \ moc/moc_audiomixerboard.cpp \ moc/moc_util.cpp \ moc/moc_testbench.cpp \ + moc/moc_serverlogging.cpp \ moc/moc_llconclientdlg.cpp \ moc/llconclientdlgbase.h \ moc/moc_clientsettingsdlg.cpp \ @@ -148,6 +149,9 @@ moc/moc_channel.cpp: ../src/channel.h moc/moc_testbench.cpp: ../src/testbench.h $(QT_MOC) ../src/testbench.h -o moc/moc_testbench.cpp +moc/moc_serverlogging.cpp: ../src/serverlogging.h + $(QT_MOC) ../src/serverlogging.h -o moc/moc_serverlogging.cpp + moc/moc_llconclientdlg.cpp: ../src/llconclientdlg.h $(QT_MOC) ../src/llconclientdlg.h -o moc/moc_llconclientdlg.cpp diff --git a/src/main.cpp b/src/main.cpp index 81fb3010..90e63632 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,12 +32,6 @@ #include "testbench.h" -// TEST -#include "serverlogging.h" - - - - // Implementation ************************************************************** // these pointers are only used for the post-event routine QApplication* pApp = NULL; @@ -59,6 +53,7 @@ int main ( int argc, char** argv ) std::string strHTMLStatusFileName = ""; std::string strServerName = ""; std::string strLoggingFileName = ""; + std::string strHistoryFileName = ""; // QT docu: argv()[0] is the program name, argv()[1] is the first // argument and argv()[argc()-1] is the last argument. @@ -129,6 +124,15 @@ int main ( int argc, char** argv ) } + // HTML status file ---------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-y", "--history", strArgument ) ) + { + strHistoryFileName = strArgument; + cout << "history file name: " << strHistoryFileName << std::endl; + continue; + } + + // initialization file ------------------------------------------------- if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) { @@ -231,6 +235,7 @@ int main ( int argc, char** argv ) CServer Server ( strLoggingFileName.c_str(), iPortNumber, strHTMLStatusFileName.c_str(), + strHistoryFileName.c_str(), strServerName.c_str(), iUploadRateLimitKbps ); @@ -288,11 +293,16 @@ std::string UsageArguments ( char **argv ) " -s, --server start server\n" " -n, --nogui disable GUI (only avaiable for server)\n" " -l, --log enable logging, set file name\n" - " -i, --inifile initialization file name (only available for client)\n" + " -i, --inifile initialization file name (only available for\n" + " client)\n" " -p, --port local port number (only avaiable for server)\n" - " -m, --htmlstatus enable HTML status file, set file name (only avaiable for server)\n" + " -m, --htmlstatus enable HTML status file, set file name (only\n" + " avaiable for server)\n" + " -y, --history enable connection history and set file\n" + " name (only available for server)\n" " -u, --maxuploadrate maximum upload rate (only avaiable for server)\n" - " -c, --connect connect to last server on startup (only available for client)\n" + " -c, --connect connect to last server on startup (only\n" + " available for client)\n" " -h, -?, --help this help text\n" "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; } diff --git a/src/server.cpp b/src/server.cpp index 2c7bd951..86b50d09 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -29,6 +29,7 @@ CServer::CServer ( const QString& strLoggingFileName, const quint16 iPortNumber, const QString& strHTMLStatusFileName, + const QString& strHistoryFileName, const QString& strServerNameForHTMLStatusFile, const int iNewUploadRateLimitKbps ) : Socket ( &ChannelSet, this, iPortNumber ), @@ -60,6 +61,12 @@ CServer::CServer ( const QString& strLoggingFileName, Logging.Start ( strLoggingFileName ); } + // enable history graph (if requested) + if ( !strHistoryFileName.isEmpty() ) + { + Logging.EnableHistory ( strHistoryFileName ); + } + // HTML status file writing if ( !strHTMLStatusFileName.isEmpty() ) { diff --git a/src/server.h b/src/server.h index 8a01a0c4..38f7ab46 100755 --- a/src/server.h +++ b/src/server.h @@ -45,6 +45,7 @@ public: CServer ( const QString& strLoggingFileName, const quint16 iPortNumber, const QString& strHTMLStatusFileName, + const QString& strHistoryFileName, const QString& strServerNameForHTMLStatusFile, const int iNewUploadRateLimitKbps ); virtual ~CServer() {} diff --git a/src/serverlogging.cpp b/src/serverlogging.cpp index 0cf3a001..8bb4cd48 100755 --- a/src/serverlogging.cpp +++ b/src/serverlogging.cpp @@ -26,8 +26,9 @@ /* Implementation *************************************************************/ -CHistoryGraph::CHistoryGraph ( const QString& sNewFileName ) : - sFileName ( sNewFileName ), +CHistoryGraph::CHistoryGraph() : + sFileName ( "" ), + bDoHistory ( false ), vDateTimeFifo ( NUM_ITEMS_HISTORY ), vItemTypeFifo ( NUM_ITEMS_HISTORY ), PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph @@ -56,7 +57,29 @@ CHistoryGraph::CHistoryGraph ( const QString& sNewFileName ) : // scale pixmap to correct size PlotPixmap = PlotPixmap.scaled ( - PlotCanvasRect.width(), PlotCanvasRect.height() ); + PlotCanvasRect.width(), PlotCanvasRect.height() ); + + // connections + QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ), + this, SLOT ( OnTimerDailyUpdate() ) ); +} + +void CHistoryGraph::Start ( const QString& sNewFileName ) +{ + if ( !sNewFileName.isEmpty() ) + { + // save file name + sFileName = sNewFileName; + + // set enable flag + bDoHistory = true; + + // enable timer (update once a day) + TimerDailyUpdate.start ( 3600000 * 24 ); + + // initial update (empty graph) + Update(); + } } void CHistoryGraph::DrawFrame ( const int iNewNumTicksX ) @@ -192,69 +215,54 @@ void CHistoryGraph::Save ( const QString sFileName ) void CHistoryGraph::Add ( const QDateTime& newDateTime, const bool newIsServerStop ) { - // add new element in FIFOs - vDateTimeFifo.Add ( newDateTime ); - vItemTypeFifo.Add ( static_cast ( newIsServerStop ) ); + if ( bDoHistory ) + { + // add new element in FIFOs + vDateTimeFifo.Add ( newDateTime ); + vItemTypeFifo.Add ( static_cast ( newIsServerStop ) ); + } } void CHistoryGraph::Update() { - int i; - - // store current date for reference - curDate = QDate::currentDate(); - - // get oldest date in history - QDate oldestDate = curDate.addDays ( 1 ); // one day in the future - const int iNumItemsForHistory = vDateTimeFifo.Size(); - for ( i = 0; i < iNumItemsForHistory; i++ ) + if ( bDoHistory ) { - // only use valid dates - if ( vDateTimeFifo[i].date().isValid() ) + int i; + + // store current date for reference + curDate = QDate::currentDate(); + + // get oldest date in history + QDate oldestDate = curDate.addDays ( 1 ); // one day in the future + const int iNumItemsForHistory = vDateTimeFifo.Size(); + for ( i = 0; i < iNumItemsForHistory; i++ ) { - if ( vDateTimeFifo[i].date() < oldestDate ) + // only use valid dates + if ( vDateTimeFifo[i].date().isValid() ) { - oldestDate = vDateTimeFifo[i].date(); + if ( vDateTimeFifo[i].date() < oldestDate ) + { + oldestDate = vDateTimeFifo[i].date(); + } } } + const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1; + + // draw frame of the graph + DrawFrame ( iNumDaysInHistory ); + + // add markers + for ( i = 0; i < iNumItemsForHistory; i++ ) + { + AddMarker ( vDateTimeFifo[i], static_cast ( vItemTypeFifo[i] ) ); + } + + // save graph as picture in file + Save ( sFileName ); } - const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1; - - // draw frame of the graph - DrawFrame ( iNumDaysInHistory ); - - // add markers - for ( i = 0; i < iNumItemsForHistory; i++ ) - { - AddMarker ( vDateTimeFifo[i], static_cast ( vItemTypeFifo[i] ) ); - } - - // save graph as picture in file - Save ( sFileName ); } -CServerLogging::CServerLogging() : - bDoLogging ( false ), - File ( DEFAULT_LOG_FILE_NAME ), - HistoryGraph ( "test.jpg" ) -{ - - -#if 1 - -// TEST add some elements -HistoryGraph.Add ( QDateTime ( QDate::currentDate().addDays ( -1 ), - QTime ( 18, 0, 0, 0 ) ), false ); - -HistoryGraph.Add ( QDateTime ( QDate::currentDate().addDays ( -0 ), - QTime ( 17, 50, 0, 0 ) ), true ); - -HistoryGraph.Update(); - -#endif -} - CServerLogging::~CServerLogging() { // close logging file of open @@ -274,6 +282,11 @@ void CServerLogging::Start ( const QString& strLoggingFileName ) } } +void CServerLogging::EnableHistory ( const QString& strHistoryFileName ) +{ + HistoryGraph.Start ( strHistoryFileName ); +} + void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr ) { // logging of new connected channel @@ -285,6 +298,9 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr ) tsConsoloeStream << strLogStr << endl; // on console #endif *this << strLogStr; // in log file + + // add element to history + HistoryGraph.Add ( QDateTime::currentDateTime(), false ); } void CServerLogging::AddServerStopped() @@ -297,6 +313,10 @@ void CServerLogging::AddServerStopped() tsConsoloeStream << strLogStr << endl; // on console #endif *this << strLogStr; // in log file + + // add element to history and update on server stop + HistoryGraph.Add ( QDateTime::currentDateTime(), true ); + HistoryGraph.Update(); } void CServerLogging::operator<< ( const QString& sNewStr ) diff --git a/src/serverlogging.h b/src/serverlogging.h index 729d41d2..9f97fe40 100755 --- a/src/serverlogging.h +++ b/src/serverlogging.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "global.h" #include "util.h" @@ -41,12 +42,15 @@ /* Classes ********************************************************************/ -class CHistoryGraph +class CHistoryGraph : public QObject { + Q_OBJECT + public: - CHistoryGraph ( const QString& sNewFileName ); - void Update(); + CHistoryGraph(); + void Start ( const QString& sNewFileName ); void Add ( const QDateTime& newDateTime, const bool newIsServerStop ); + void Update(); protected: void DrawFrame ( const int iNewNumTicksX ); @@ -54,6 +58,7 @@ protected: const bool bIsServerStop ); void Save ( const QString sFileName ); + bool bDoHistory; int iYAxisStart; int iYAxisEnd; int iNumTicksX; @@ -76,19 +81,25 @@ protected: QRect PlotCanvasRect; QRect PlotGridFrame; QString sFileName; + QTimer TimerDailyUpdate; CFIFO vDateTimeFifo; CFIFO vItemTypeFifo; + +public slots: + void OnTimerDailyUpdate() { Update(); } }; class CServerLogging { public: - CServerLogging(); + CServerLogging() : bDoLogging ( false ), + File ( DEFAULT_LOG_FILE_NAME ) {} virtual ~CServerLogging(); void Start ( const QString& strLoggingFileName ); + void EnableHistory ( const QString& strHistoryFileName ); void AddNewConnection ( const QHostAddress& ClientInetAddr ); void AddServerStopped(); diff --git a/windows/MocQT.bat b/windows/MocQT.bat index 7348a9c4..afafc4b9 100755 --- a/windows/MocQT.bat +++ b/windows/MocQT.bat @@ -42,6 +42,7 @@ rem .h -------------- %qtdir%\bin\moc.exe ..\src\channel.h -o moc\moc_channel.cpp %qtdir%\bin\moc.exe ..\src\soundbase.h -o moc\moc_soundbase.cpp %qtdir%\bin\moc.exe ..\src\testbench.h -o moc\moc_testbench.cpp +%qtdir%\bin\moc.exe ..\src\serverlogging.h -o moc\moc_serverlogging.cpp rem .ui ------------- diff --git a/windows/llcon.vcproj b/windows/llcon.vcproj index 3bd86b1f..0b38c831 100755 --- a/windows/llcon.vcproj +++ b/windows/llcon.vcproj @@ -814,6 +814,10 @@ /> + +