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_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

View file

@ -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";
}

View file

@ -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() )
{

View file

@ -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() {}

View file

@ -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
@ -57,6 +58,28 @@ CHistoryGraph::CHistoryGraph ( const QString& sNewFileName ) :
// scale pixmap to correct size
PlotPixmap = PlotPixmap.scaled (
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<int> ( newIsServerStop ) );
if ( bDoHistory )
{
// add new element in FIFOs
vDateTimeFifo.Add ( newDateTime );
vItemTypeFifo.Add ( static_cast<int> ( 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<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()
{
// 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 )

View file

@ -31,6 +31,7 @@
#include <qhostaddress.h>
#include <qfile.h>
#include <qstring.h>
#include <qtimer.h>
#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<QDateTime> vDateTimeFifo;
CFIFO<int> 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();

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\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 -------------

View file

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