first fully version of history

This commit is contained in:
Volker Fischer 2009-06-06 10:07:01 +00:00
parent 6b610b0bed
commit 37d826630d
8 changed files with 124 additions and 66 deletions

View File

@ -96,6 +96,7 @@ BUILT_SOURCES=moc/moc_server.cpp \
moc/moc_audiomixerboard.cpp \ moc/moc_audiomixerboard.cpp \
moc/moc_util.cpp \ moc/moc_util.cpp \
moc/moc_testbench.cpp \ moc/moc_testbench.cpp \
moc/moc_serverlogging.cpp \
moc/moc_llconclientdlg.cpp \ moc/moc_llconclientdlg.cpp \
moc/llconclientdlgbase.h \ moc/llconclientdlgbase.h \
moc/moc_clientsettingsdlg.cpp \ moc/moc_clientsettingsdlg.cpp \
@ -148,6 +149,9 @@ moc/moc_channel.cpp: ../src/channel.h
moc/moc_testbench.cpp: ../src/testbench.h moc/moc_testbench.cpp: ../src/testbench.h
$(QT_MOC) ../src/testbench.h -o moc/moc_testbench.cpp $(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 moc/moc_llconclientdlg.cpp: ../src/llconclientdlg.h
$(QT_MOC) ../src/llconclientdlg.h -o moc/moc_llconclientdlg.cpp $(QT_MOC) ../src/llconclientdlg.h -o moc/moc_llconclientdlg.cpp

View File

@ -32,12 +32,6 @@
#include "testbench.h" #include "testbench.h"
// TEST
#include "serverlogging.h"
// Implementation ************************************************************** // Implementation **************************************************************
// these pointers are only used for the post-event routine // these pointers are only used for the post-event routine
QApplication* pApp = NULL; QApplication* pApp = NULL;
@ -59,6 +53,7 @@ int main ( int argc, char** argv )
std::string strHTMLStatusFileName = ""; std::string strHTMLStatusFileName = "";
std::string strServerName = ""; std::string strServerName = "";
std::string strLoggingFileName = ""; std::string strLoggingFileName = "";
std::string strHistoryFileName = "";
// QT docu: argv()[0] is the program name, argv()[1] is the first // QT docu: argv()[0] is the program name, argv()[1] is the first
// argument and argv()[argc()-1] is the last argument. // 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 ------------------------------------------------- // initialization file -------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
{ {
@ -231,6 +235,7 @@ int main ( int argc, char** argv )
CServer Server ( strLoggingFileName.c_str(), CServer Server ( strLoggingFileName.c_str(),
iPortNumber, iPortNumber,
strHTMLStatusFileName.c_str(), strHTMLStatusFileName.c_str(),
strHistoryFileName.c_str(),
strServerName.c_str(), strServerName.c_str(),
iUploadRateLimitKbps ); iUploadRateLimitKbps );
@ -288,11 +293,16 @@ std::string UsageArguments ( char **argv )
" -s, --server start server\n" " -s, --server start server\n"
" -n, --nogui disable GUI (only avaiable for server)\n" " -n, --nogui disable GUI (only avaiable for server)\n"
" -l, --log enable logging, set file name\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" " -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" " -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" " -h, -?, --help this help text\n"
"Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n";
} }

View File

@ -29,6 +29,7 @@
CServer::CServer ( const QString& strLoggingFileName, CServer::CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber, const quint16 iPortNumber,
const QString& strHTMLStatusFileName, const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile, const QString& strServerNameForHTMLStatusFile,
const int iNewUploadRateLimitKbps ) : const int iNewUploadRateLimitKbps ) :
Socket ( &ChannelSet, this, iPortNumber ), Socket ( &ChannelSet, this, iPortNumber ),
@ -60,6 +61,12 @@ CServer::CServer ( const QString& strLoggingFileName,
Logging.Start ( strLoggingFileName ); Logging.Start ( strLoggingFileName );
} }
// enable history graph (if requested)
if ( !strHistoryFileName.isEmpty() )
{
Logging.EnableHistory ( strHistoryFileName );
}
// HTML status file writing // HTML status file writing
if ( !strHTMLStatusFileName.isEmpty() ) if ( !strHTMLStatusFileName.isEmpty() )
{ {

View File

@ -45,6 +45,7 @@ public:
CServer ( const QString& strLoggingFileName, CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber, const quint16 iPortNumber,
const QString& strHTMLStatusFileName, const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile, const QString& strServerNameForHTMLStatusFile,
const int iNewUploadRateLimitKbps ); const int iNewUploadRateLimitKbps );
virtual ~CServer() {} virtual ~CServer() {}

View File

@ -26,8 +26,9 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CHistoryGraph::CHistoryGraph ( const QString& sNewFileName ) : CHistoryGraph::CHistoryGraph() :
sFileName ( sNewFileName ), sFileName ( "" ),
bDoHistory ( false ),
vDateTimeFifo ( NUM_ITEMS_HISTORY ), vDateTimeFifo ( NUM_ITEMS_HISTORY ),
vItemTypeFifo ( NUM_ITEMS_HISTORY ), vItemTypeFifo ( NUM_ITEMS_HISTORY ),
PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph
@ -56,7 +57,29 @@ CHistoryGraph::CHistoryGraph ( const QString& sNewFileName ) :
// scale pixmap to correct size // scale pixmap to correct size
PlotPixmap = PlotPixmap.scaled ( 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 ) void CHistoryGraph::DrawFrame ( const int iNewNumTicksX )
@ -192,69 +215,54 @@ void CHistoryGraph::Save ( const QString sFileName )
void CHistoryGraph::Add ( const QDateTime& newDateTime, void CHistoryGraph::Add ( const QDateTime& newDateTime,
const bool newIsServerStop ) const bool newIsServerStop )
{ {
// add new element in FIFOs if ( bDoHistory )
vDateTimeFifo.Add ( newDateTime ); {
vItemTypeFifo.Add ( static_cast<int> ( newIsServerStop ) ); // add new element in FIFOs
vDateTimeFifo.Add ( newDateTime );
vItemTypeFifo.Add ( static_cast<int> ( newIsServerStop ) );
}
} }
void CHistoryGraph::Update() void CHistoryGraph::Update()
{ {
int i; if ( bDoHistory )
// 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++ )
{ {
// only use valid dates int i;
if ( vDateTimeFifo[i].date().isValid() )
// 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<bool> ( 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<bool> ( 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() CServerLogging::~CServerLogging()
{ {
// close logging file of open // 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 ) void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
{ {
// logging of new connected channel // logging of new connected channel
@ -285,6 +298,9 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
tsConsoloeStream << strLogStr << endl; // on console tsConsoloeStream << strLogStr << endl; // on console
#endif #endif
*this << strLogStr; // in log file *this << strLogStr; // in log file
// add element to history
HistoryGraph.Add ( QDateTime::currentDateTime(), false );
} }
void CServerLogging::AddServerStopped() void CServerLogging::AddServerStopped()
@ -297,6 +313,10 @@ void CServerLogging::AddServerStopped()
tsConsoloeStream << strLogStr << endl; // on console tsConsoloeStream << strLogStr << endl; // on console
#endif #endif
*this << strLogStr; // in log file *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 ) void CServerLogging::operator<< ( const QString& sNewStr )

View File

@ -31,6 +31,7 @@
#include <qhostaddress.h> #include <qhostaddress.h>
#include <qfile.h> #include <qfile.h>
#include <qstring.h> #include <qstring.h>
#include <qtimer.h>
#include "global.h" #include "global.h"
#include "util.h" #include "util.h"
@ -41,12 +42,15 @@
/* Classes ********************************************************************/ /* Classes ********************************************************************/
class CHistoryGraph class CHistoryGraph : public QObject
{ {
Q_OBJECT
public: public:
CHistoryGraph ( const QString& sNewFileName ); CHistoryGraph();
void Update(); void Start ( const QString& sNewFileName );
void Add ( const QDateTime& newDateTime, const bool newIsServerStop ); void Add ( const QDateTime& newDateTime, const bool newIsServerStop );
void Update();
protected: protected:
void DrawFrame ( const int iNewNumTicksX ); void DrawFrame ( const int iNewNumTicksX );
@ -54,6 +58,7 @@ protected:
const bool bIsServerStop ); const bool bIsServerStop );
void Save ( const QString sFileName ); void Save ( const QString sFileName );
bool bDoHistory;
int iYAxisStart; int iYAxisStart;
int iYAxisEnd; int iYAxisEnd;
int iNumTicksX; int iNumTicksX;
@ -76,19 +81,25 @@ protected:
QRect PlotCanvasRect; QRect PlotCanvasRect;
QRect PlotGridFrame; QRect PlotGridFrame;
QString sFileName; QString sFileName;
QTimer TimerDailyUpdate;
CFIFO<QDateTime> vDateTimeFifo; CFIFO<QDateTime> vDateTimeFifo;
CFIFO<int> vItemTypeFifo; CFIFO<int> vItemTypeFifo;
public slots:
void OnTimerDailyUpdate() { Update(); }
}; };
class CServerLogging class CServerLogging
{ {
public: public:
CServerLogging(); CServerLogging() : bDoLogging ( false ),
File ( DEFAULT_LOG_FILE_NAME ) {}
virtual ~CServerLogging(); virtual ~CServerLogging();
void Start ( const QString& strLoggingFileName ); void Start ( const QString& strLoggingFileName );
void EnableHistory ( const QString& strHistoryFileName );
void AddNewConnection ( const QHostAddress& ClientInetAddr ); void AddNewConnection ( const QHostAddress& ClientInetAddr );
void AddServerStopped(); void AddServerStopped();

View File

@ -42,6 +42,7 @@ rem .h --------------
%qtdir%\bin\moc.exe ..\src\channel.h -o moc\moc_channel.cpp %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\soundbase.h -o moc\moc_soundbase.cpp
%qtdir%\bin\moc.exe ..\src\testbench.h -o moc\moc_testbench.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 ------------- rem .ui -------------

View File

@ -814,6 +814,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\moc\moc_serverlogging.cpp"
>
</File>
<File <File
RelativePath="moc\moc_socket.cpp" RelativePath="moc\moc_socket.cpp"
> >