replacing internal history graph functionality by external scripts/tools (#501)
This commit is contained in:
parent
a3c53afdcb
commit
a386d388fa
10 changed files with 9 additions and 880 deletions
|
@ -20,11 +20,15 @@
|
||||||
|
|
||||||
- option to set "Mute Myself" on with a command line argument (#495)
|
- option to set "Mute Myself" on with a command line argument (#495)
|
||||||
|
|
||||||
|
- replacing internal history graph functionality by external scripts/tools (#501)
|
||||||
|
|
||||||
- bug fix: added more mutex in the server (should fix #480)
|
- bug fix: added more mutex in the server (should fix #480)
|
||||||
|
|
||||||
- bug fix: --showallservers ping column sort is alphabetic (#201)
|
- bug fix: --showallservers ping column sort is alphabetic (#201)
|
||||||
|
|
||||||
|
|
||||||
|
TODO make clear that filter # filters musicians
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -363,7 +363,6 @@ HEADERS += src/buffer.h \
|
||||||
src/recorder/jamrecorder.h \
|
src/recorder/jamrecorder.h \
|
||||||
src/recorder/creaperproject.h \
|
src/recorder/creaperproject.h \
|
||||||
src/recorder/cwavestream.h \
|
src/recorder/cwavestream.h \
|
||||||
src/historygraph.h \
|
|
||||||
src/signalhandler.h
|
src/signalhandler.h
|
||||||
|
|
||||||
HEADERS_GUI = src/audiomixerboard.h \
|
HEADERS_GUI = src/audiomixerboard.h \
|
||||||
|
@ -462,8 +461,7 @@ SOURCES += src/buffer.cpp \
|
||||||
src/util.cpp \
|
src/util.cpp \
|
||||||
src/recorder/jamrecorder.cpp \
|
src/recorder/jamrecorder.cpp \
|
||||||
src/recorder/creaperproject.cpp \
|
src/recorder/creaperproject.cpp \
|
||||||
src/recorder/cwavestream.cpp \
|
src/recorder/cwavestream.cpp
|
||||||
src/historygraph.cpp
|
|
||||||
|
|
||||||
SOURCES_GUI = src/audiomixerboard.cpp \
|
SOURCES_GUI = src/audiomixerboard.cpp \
|
||||||
src/chatdlg.cpp \
|
src/chatdlg.cpp \
|
||||||
|
|
|
@ -92,9 +92,6 @@ LED bar: lbr
|
||||||
// file name for logging file
|
// file name for logging file
|
||||||
#define DEFAULT_LOG_FILE_NAME "Jamulussrvlog.txt"
|
#define DEFAULT_LOG_FILE_NAME "Jamulussrvlog.txt"
|
||||||
|
|
||||||
// default oldest item to draw in history graph (days ago)
|
|
||||||
#define DEFAULT_DAYS_HISTORY 60
|
|
||||||
|
|
||||||
// System block size, this is the block size on which the audio coder works.
|
// System block size, this is the block size on which the audio coder works.
|
||||||
// All other block sizes must be a multiple of this size.
|
// All other block sizes must be a multiple of this size.
|
||||||
// Note that the UpdateAutoSetting() function assumes a value of 128.
|
// Note that the UpdateAutoSetting() function assumes a value of 128.
|
||||||
|
|
|
@ -1,513 +0,0 @@
|
||||||
/******************************************************************************\
|
|
||||||
* Copyright (c) 2004-2020
|
|
||||||
*
|
|
||||||
* Author(s):
|
|
||||||
* Volker Fischer
|
|
||||||
* Peter L Jones <pljones@users.sf.net>
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
||||||
*
|
|
||||||
\******************************************************************************/
|
|
||||||
|
|
||||||
#include "historygraph.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Abstract class *************************************************************/
|
|
||||||
AHistoryGraph::AHistoryGraph ( const int iMaxDaysHistory ) :
|
|
||||||
sFileName ( "" ),
|
|
||||||
bDoHistory ( false ),
|
|
||||||
vHistoryDataFifo ( NUM_ITEMS_HISTORY ),
|
|
||||||
iNumTicksX ( 0 ), // number of days in history
|
|
||||||
iHistMaxDays ( iMaxDaysHistory ),
|
|
||||||
|
|
||||||
BackgroundColor ( "white" ), // background
|
|
||||||
FrameColor ( "black" ), // frame
|
|
||||||
GridColor ( "gray" ), // grid
|
|
||||||
TextColor ( "black" ), // text
|
|
||||||
MarkerNewColor ( "darkCyan" ), // marker for new connection
|
|
||||||
MarkerNewLocalColor ( "blue" ), // marker for new local connection
|
|
||||||
MarkerStopColor ( "red" ), // marker for server stop
|
|
||||||
|
|
||||||
canvasRectX ( 0 ),
|
|
||||||
canvasRectY ( 0 ),
|
|
||||||
canvasRectWidth ( 640 ),
|
|
||||||
canvasRectHeight ( 450 ),
|
|
||||||
|
|
||||||
iGridFrameOffset ( 10 ),
|
|
||||||
iGridWidthWeekend ( 3 ), // should be an odd value
|
|
||||||
iXAxisTextHeight ( 22 ),
|
|
||||||
gridFrameX ( canvasRectX + iGridFrameOffset ),
|
|
||||||
gridFrameY ( canvasRectY + iGridFrameOffset ),
|
|
||||||
gridFrameWidth ( canvasRectWidth - 2 * iGridFrameOffset ),
|
|
||||||
gridFrameHeight ( canvasRectHeight - 2 * iGridFrameOffset - iXAxisTextHeight ),
|
|
||||||
gridFrameRight ( gridFrameX + gridFrameWidth - 1 ),
|
|
||||||
gridFrameBottom ( gridFrameY + gridFrameHeight - 1 ),
|
|
||||||
|
|
||||||
axisFontFamily ( "Arial" ),
|
|
||||||
axisFontWeight ( "100" ),
|
|
||||||
axisFontSize ( 12 ),
|
|
||||||
|
|
||||||
iYAxisStart ( 0 ),
|
|
||||||
iYAxisEnd ( 24 ),
|
|
||||||
iNumTicksY ( 5 ),
|
|
||||||
|
|
||||||
iTextOffsetToGrid ( 3 ),
|
|
||||||
iTextOffsetX ( 18 ),
|
|
||||||
|
|
||||||
iMarkerSizeNewCon ( 10 ),
|
|
||||||
iMarkerSizeServSt ( 6 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void AHistoryGraph::Start ( const QString& sNewFileName )
|
|
||||||
{
|
|
||||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
|
||||||
tsConsoleStream << QString ( "AHistoryGraph::Start ( %1 )" ).arg ( sNewFileName ) << endl; // on console
|
|
||||||
|
|
||||||
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 AHistoryGraph::Add ( const QDateTime& newDateTime, const EHistoryItemType curType )
|
|
||||||
{
|
|
||||||
if ( bDoHistory )
|
|
||||||
{
|
|
||||||
// create and add new element in FIFO
|
|
||||||
SHistoryData curHistoryData;
|
|
||||||
curHistoryData.DateTime = newDateTime;
|
|
||||||
curHistoryData.Type = curType;
|
|
||||||
|
|
||||||
vHistoryDataFifo.Add ( curHistoryData );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AHistoryGraph::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, HIT_LOCAL_CONNECTION );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// remote connection
|
|
||||||
Add ( newDateTime, HIT_REMOTE_CONNECTION );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AHistoryGraph::Update ( )
|
|
||||||
{
|
|
||||||
if ( bDoHistory )
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// store current date for reference
|
|
||||||
curDate = QDate::currentDate();
|
|
||||||
|
|
||||||
// set oldest date to draw
|
|
||||||
QDate minDate = curDate.addDays ( iHistMaxDays * -1 );
|
|
||||||
|
|
||||||
// get oldest date in history
|
|
||||||
QDate oldestDate = curDate.addDays ( 1 ); // one day in the future
|
|
||||||
const int iNumItemsForHistory = vHistoryDataFifo.Size();
|
|
||||||
|
|
||||||
for ( i = 0; i < iNumItemsForHistory; i++ )
|
|
||||||
{
|
|
||||||
// only use valid dates
|
|
||||||
if ( vHistoryDataFifo[i].DateTime.date().isValid() )
|
|
||||||
{
|
|
||||||
if ( vHistoryDataFifo[i].DateTime.date() < oldestDate )
|
|
||||||
{
|
|
||||||
oldestDate = vHistoryDataFifo[i].DateTime.date();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( oldestDate < minDate )
|
|
||||||
{
|
|
||||||
oldestDate = minDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1;
|
|
||||||
|
|
||||||
// draw frame of the graph
|
|
||||||
DrawFrame ( iNumDaysInHistory );
|
|
||||||
|
|
||||||
// add markers
|
|
||||||
for ( i = 0; i < iNumItemsForHistory; i++ )
|
|
||||||
{
|
|
||||||
// only use valid dates
|
|
||||||
if ( vHistoryDataFifo[i].DateTime.date().isValid() && ( oldestDate <= vHistoryDataFifo[i].DateTime.date() ) )
|
|
||||||
{
|
|
||||||
AddMarker ( vHistoryDataFifo[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// save graph as picture in file
|
|
||||||
Save ( sFileName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AHistoryGraph::DrawFrame ( const int iNewNumTicksX )
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// store number of x-axis ticks (number of days we want to draw
|
|
||||||
// the history for
|
|
||||||
iNumTicksX = iNewNumTicksX;
|
|
||||||
|
|
||||||
|
|
||||||
// Create actual plot region (grid frame) ----------------------------------
|
|
||||||
rect( gridFrameX, gridFrameY, gridFrameWidth, gridFrameHeight );
|
|
||||||
|
|
||||||
// calculate step for x-axis ticks so that we get the desired number of
|
|
||||||
// ticks -> 5 ticks
|
|
||||||
|
|
||||||
// TODO the following equation does not work as expected but results are acceptable
|
|
||||||
|
|
||||||
// we want to have "floor ( iNumTicksX / 5 )" which is the same as
|
|
||||||
// "iNumTicksX / 5" since "iNumTicksX" is an integer variable
|
|
||||||
const int iXAxisTickStep = iNumTicksX / 5 + 1;
|
|
||||||
|
|
||||||
// grid (ticks) for x-axis
|
|
||||||
dayXSpace = static_cast<double> ( gridFrameWidth ) / ( iNumTicksX + 1 );
|
|
||||||
|
|
||||||
for ( i = 0; i < static_cast<int> ( iNumTicksX ); i++ )
|
|
||||||
{
|
|
||||||
int iBottomExtraTickLen = 0;
|
|
||||||
const int iCurX = gridFrameX + static_cast<int> ( dayXSpace * ( i + 1 ) );
|
|
||||||
const QDate curXAxisDate = curDate.addDays ( 0 - static_cast<signed> ( iNumTicksX ) + i + 1 );
|
|
||||||
|
|
||||||
// text (print only every "iXAxisTickStep" tick)
|
|
||||||
if ( !( i % iXAxisTickStep ) )
|
|
||||||
{
|
|
||||||
text ( iCurX - iTextOffsetX, gridFrameBottom + iXAxisTextHeight + iTextOffsetToGrid, curXAxisDate.toString ( "dd.MM." ) );
|
|
||||||
|
|
||||||
iBottomExtraTickLen = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
// regular grid
|
|
||||||
line ( iCurX, 1 + gridFrameY, iCurX, gridFrameBottom + iBottomExtraTickLen );
|
|
||||||
|
|
||||||
// different grid width for weekends (overwrite regular grid)
|
|
||||||
if ( ( curXAxisDate.dayOfWeek() == 6 ) || // check for Saturday
|
|
||||||
( curXAxisDate.dayOfWeek() == 7 ) ) // check for Sunday
|
|
||||||
{
|
|
||||||
const int iGridWidthWeekendHalf = iGridWidthWeekend / 2;
|
|
||||||
|
|
||||||
line ( iCurX, 1 + gridFrameY + iGridWidthWeekendHalf, iCurX, gridFrameBottom - iGridWidthWeekendHalf, iGridWidthWeekend );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// grid (ticks) for y-axis, draw iNumTicksY - 2 grid lines and
|
|
||||||
// iNumTicksY - 1 text labels (the lowest grid line is the grid frame)
|
|
||||||
iYSpace = gridFrameHeight / ( iNumTicksY - 1 );
|
|
||||||
|
|
||||||
for ( i = 0; i < ( static_cast<int> ( iNumTicksY ) - 1 ); i++ )
|
|
||||||
{
|
|
||||||
const int iCurY = gridFrameY + iYSpace * ( i + 1 );
|
|
||||||
|
|
||||||
// text
|
|
||||||
text ( gridFrameX + iTextOffsetToGrid,
|
|
||||||
iCurY - iTextOffsetToGrid,
|
|
||||||
QString ( "%1:00" ).arg ( ( iYAxisEnd - iYAxisStart ) / ( iNumTicksY - 1 ) * ( ( iNumTicksY - 2 ) - i ) ) );
|
|
||||||
|
|
||||||
// grid (do not overwrite frame)
|
|
||||||
if ( i < ( static_cast<int> ( iNumTicksY ) - 2 ) )
|
|
||||||
{
|
|
||||||
line ( gridFrameX, iCurY, gridFrameRight, iCurY );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
|
|
||||||
{
|
|
||||||
// calculate x-axis offset (difference of days compared to
|
|
||||||
// current date)
|
|
||||||
const int iXAxisOffs =
|
|
||||||
curDate.daysTo ( curHistoryData.DateTime.date() );
|
|
||||||
|
|
||||||
// check range, if out of range, do not plot anything
|
|
||||||
if ( -iXAxisOffs > ( static_cast<signed> ( iNumTicksX ) - 1 ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate y-axis offset (consider hours and minutes)
|
|
||||||
const double dYAxisOffs = 24 - curHistoryData.DateTime.time().hour() -
|
|
||||||
static_cast<double> ( curHistoryData.DateTime.time().minute() ) / 60;
|
|
||||||
|
|
||||||
// calculate the actual point in the graph (in pixels)
|
|
||||||
int curPointX = gridFrameX + static_cast<int> ( dayXSpace * ( static_cast<signed> ( iNumTicksX ) + iXAxisOffs ) );
|
|
||||||
int curPointY = gridFrameY + static_cast<int> ( static_cast<double> (
|
|
||||||
gridFrameHeight ) / ( iYAxisEnd - iYAxisStart ) * dYAxisOffs );
|
|
||||||
|
|
||||||
QString curPointColour = MarkerNewColor;
|
|
||||||
int curPointSize = iMarkerSizeNewCon;
|
|
||||||
|
|
||||||
// we use different markers for new connection and server stop items
|
|
||||||
switch ( curHistoryData.Type )
|
|
||||||
{
|
|
||||||
case HIT_SERVER_STOP:
|
|
||||||
curPointColour = MarkerStopColor;
|
|
||||||
curPointSize = iMarkerSizeServSt;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HIT_LOCAL_CONNECTION:
|
|
||||||
curPointColour = MarkerNewLocalColor;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HIT_REMOTE_CONNECTION:
|
|
||||||
curPointColour = MarkerNewColor;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
point ( curPointX - curPointSize / 2, curPointY - curPointSize / 2, curPointSize, curPointColour );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* JPEG History Graph implementation ******************************************/
|
|
||||||
#ifndef HEADLESS
|
|
||||||
CJpegHistoryGraph::CJpegHistoryGraph ( const int iMaxDaysHistory ) :
|
|
||||||
AHistoryGraph ( iMaxDaysHistory ),
|
|
||||||
PlotPixmap ( 1, 1, QImage::Format_RGB32 ),
|
|
||||||
iAxisFontWeight ( -1 )
|
|
||||||
{
|
|
||||||
// scale pixmap to correct size
|
|
||||||
PlotPixmap = PlotPixmap.scaled ( canvasRectWidth, canvasRectHeight );
|
|
||||||
|
|
||||||
// axisFontWeight is a string matching the CSS2 font-weight definition
|
|
||||||
// Thin = 0, // 100
|
|
||||||
// ExtraLight = 12, // 200
|
|
||||||
// Light = 25, // 300
|
|
||||||
// Normal = 50, // 400
|
|
||||||
// Medium = 57, // 500
|
|
||||||
// DemiBold = 63, // 600
|
|
||||||
// Bold = 75, // 700
|
|
||||||
// ExtraBold = 81, // 800
|
|
||||||
// Black = 87 // 900
|
|
||||||
bool ok;
|
|
||||||
int weight = axisFontWeight.toInt( &ok );
|
|
||||||
|
|
||||||
if ( !ok )
|
|
||||||
{
|
|
||||||
if ( !QString ( "normal" ).compare ( axisFontWeight, Qt::CaseSensitivity::CaseInsensitive ) )
|
|
||||||
{
|
|
||||||
iAxisFontWeight = 50;
|
|
||||||
}
|
|
||||||
else if ( !QString ( "bold" ).compare ( axisFontWeight, Qt::CaseSensitivity::CaseInsensitive ) )
|
|
||||||
{
|
|
||||||
weight = 75;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( weight <= 100 ) { iAxisFontWeight = 0; }
|
|
||||||
else if ( weight <= 200 ) { iAxisFontWeight = 12; }
|
|
||||||
else if ( weight <= 300 ) { iAxisFontWeight = 25; }
|
|
||||||
else if ( weight <= 400 ) { iAxisFontWeight = 50; }
|
|
||||||
else if ( weight <= 500 ) { iAxisFontWeight = 57; }
|
|
||||||
else if ( weight <= 600 ) { iAxisFontWeight = 63; }
|
|
||||||
else if ( weight <= 700 ) { iAxisFontWeight = 75; }
|
|
||||||
else if ( weight <= 800 ) { iAxisFontWeight = 81; }
|
|
||||||
else if ( weight <= 900 ) { iAxisFontWeight = 87; }
|
|
||||||
}
|
|
||||||
// if all else fails, it's left at -1
|
|
||||||
|
|
||||||
// QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
|
||||||
// tsConsoleStream << "CJpegHistoryGraph" << endl; // on console
|
|
||||||
|
|
||||||
|
|
||||||
// Connections -------------------------------------------------------------
|
|
||||||
QObject::connect ( &TimerDailyUpdate, &QTimer::timeout,
|
|
||||||
this, &CJpegHistoryGraph::OnTimerDailyUpdate );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override Update to blank out the plot area each time
|
|
||||||
void CJpegHistoryGraph::Update()
|
|
||||||
{
|
|
||||||
if ( bDoHistory )
|
|
||||||
{
|
|
||||||
// create JPEG image
|
|
||||||
PlotPixmap.fill ( BackgroundColor ); // fill background
|
|
||||||
|
|
||||||
AHistoryGraph::Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CJpegHistoryGraph::Save ( const QString sFileName )
|
|
||||||
{
|
|
||||||
// save plot as a file
|
|
||||||
PlotPixmap.save ( sFileName, "JPG", 90 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CJpegHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
|
||||||
{
|
|
||||||
QPainter PlotPainter ( &PlotPixmap );
|
|
||||||
PlotPainter.setPen ( FrameColor );
|
|
||||||
PlotPainter.drawRect ( x, y, width, height );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CJpegHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
|
||||||
{
|
|
||||||
QPainter PlotPainter ( &PlotPixmap );
|
|
||||||
PlotPainter.setPen ( TextColor );
|
|
||||||
// QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
|
|
||||||
PlotPainter.setFont ( QFont( axisFontFamily, static_cast<int> ( axisFontSize ), iAxisFontWeight ) );
|
|
||||||
PlotPainter.drawText ( QPoint ( x, y ), value );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CJpegHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
|
||||||
{
|
|
||||||
QPainter PlotPainter ( &PlotPixmap );
|
|
||||||
PlotPainter.setPen ( QPen ( QBrush ( QColor ( GridColor ) ), strokeWidth ) );
|
|
||||||
PlotPainter.drawLine ( x1, y1, x2, y2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CJpegHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
|
||||||
{
|
|
||||||
QPainter PlotPainter ( &PlotPixmap );
|
|
||||||
PlotPainter.setPen ( QPen ( QBrush( QColor ( colour ) ), size ) );
|
|
||||||
PlotPainter.drawPoint ( x, y );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* SVG History Graph implementation *******************************************/
|
|
||||||
CSvgHistoryGraph::CSvgHistoryGraph ( const int iMaxDaysHistory ) :
|
|
||||||
AHistoryGraph ( iMaxDaysHistory ),
|
|
||||||
svgImage ( "" ),
|
|
||||||
svgStreamWriter ( &svgImage )
|
|
||||||
{
|
|
||||||
// set SVG veiwBox to correct size to ensure correct scaling
|
|
||||||
svgRootAttributes.append ( "viewBox",
|
|
||||||
QString ( "%1, %2, %3, %4" )
|
|
||||||
.arg ( canvasRectX )
|
|
||||||
.arg ( canvasRectY )
|
|
||||||
.arg ( canvasRectWidth )
|
|
||||||
.arg ( canvasRectHeight )
|
|
||||||
);
|
|
||||||
|
|
||||||
svgRootAttributes.append ( "xmlns", "http://www.w3.org/2000/svg" );
|
|
||||||
svgRootAttributes.append ( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
|
|
||||||
|
|
||||||
// QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
|
||||||
// tsConsoleStream << "CSvgHistoryGraph" << endl; // on console
|
|
||||||
|
|
||||||
|
|
||||||
// Connections -------------------------------------------------------------
|
|
||||||
QObject::connect ( &TimerDailyUpdate, &QTimer::timeout,
|
|
||||||
this, &CSvgHistoryGraph::OnTimerDailyUpdate );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override Update to create the fresh SVG stream each time
|
|
||||||
void CSvgHistoryGraph::Update()
|
|
||||||
{
|
|
||||||
if ( bDoHistory )
|
|
||||||
{
|
|
||||||
// create SVG document
|
|
||||||
svgImage = "";
|
|
||||||
|
|
||||||
svgStreamWriter.setAutoFormatting ( true );
|
|
||||||
svgStreamWriter.writeStartDocument();
|
|
||||||
svgStreamWriter.writeStartElement ( "svg" );
|
|
||||||
svgStreamWriter.writeAttributes ( svgRootAttributes );
|
|
||||||
|
|
||||||
AHistoryGraph::Update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSvgHistoryGraph::Save ( const QString sFileName )
|
|
||||||
{
|
|
||||||
svgStreamWriter.writeEndDocument();
|
|
||||||
|
|
||||||
QFile outf ( sFileName );
|
|
||||||
|
|
||||||
if ( !outf.open ( QFile::WriteOnly ) )
|
|
||||||
{
|
|
||||||
throw std::runtime_error ( ( sFileName + " could not be written. Aborting." ).toStdString() );
|
|
||||||
}
|
|
||||||
QTextStream out ( &outf );
|
|
||||||
|
|
||||||
out << svgImage << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSvgHistoryGraph::rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height )
|
|
||||||
{
|
|
||||||
svgStreamWriter.writeEmptyElement ( "rect" );
|
|
||||||
svgStreamWriter.writeAttribute ( "x", QString ( "%1" ).arg ( x ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "y", QString ( "%1" ).arg ( y ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "width", QString ( "%1" ).arg ( width ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "height", QString ( "%1" ).arg ( height ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke", FrameColor );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke-width", QString ( "1" ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "style", QString ( "fill: none;" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSvgHistoryGraph::text ( const unsigned int x, const unsigned int y, const QString& value )
|
|
||||||
{
|
|
||||||
svgStreamWriter.writeStartElement ( "text" );
|
|
||||||
svgStreamWriter.writeAttribute ( "x", QString ( "%1" ).arg ( x ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "y", QString ( "%1" ).arg ( y ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke", TextColor );
|
|
||||||
svgStreamWriter.writeAttribute ( "font-family", axisFontFamily );
|
|
||||||
svgStreamWriter.writeAttribute ( "font-weight", axisFontWeight );
|
|
||||||
svgStreamWriter.writeAttribute ( "font-size", QString ( "%1" ).arg ( axisFontSize ) );
|
|
||||||
|
|
||||||
svgStreamWriter.writeCharacters( value );
|
|
||||||
svgStreamWriter.writeEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSvgHistoryGraph::line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth )
|
|
||||||
{
|
|
||||||
svgStreamWriter.writeEmptyElement ( "line" );
|
|
||||||
svgStreamWriter.writeAttribute ( "x1", QString ( "%1" ).arg ( x1 ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "y1", QString ( "%1" ).arg ( y1 ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "x2", QString ( "%1" ).arg ( x2 ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "y2", QString ( "%1" ).arg ( y2 ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke", GridColor );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke-width", QString ( "%1" ).arg ( strokeWidth ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSvgHistoryGraph::point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour )
|
|
||||||
{
|
|
||||||
svgStreamWriter.writeEmptyElement ( "rect" );
|
|
||||||
svgStreamWriter.writeAttribute ( "x", QString ( "%1" ).arg ( x ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "y", QString ( "%1" ).arg ( y ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "width", QString ( "%1" ).arg ( size ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "height", QString ( "%1" ).arg ( size ) );
|
|
||||||
svgStreamWriter.writeAttribute ( "stroke-opacity", "0" );
|
|
||||||
svgStreamWriter.writeAttribute ( "fill", colour );
|
|
||||||
}
|
|
|
@ -1,188 +0,0 @@
|
||||||
/******************************************************************************\
|
|
||||||
* Copyright (c) 2004-2020
|
|
||||||
*
|
|
||||||
* Author(s):
|
|
||||||
* Volker Fischer
|
|
||||||
* Peter L Jones <pljones@users.sf.net>
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
||||||
*
|
|
||||||
\******************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QHostAddress>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QString>
|
|
||||||
#include <QTimer>
|
|
||||||
#include "global.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
// for CJpegHistoryGraph
|
|
||||||
#ifndef HEADLESS
|
|
||||||
# include <QImage>
|
|
||||||
# include <QPainter>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// for CSvgHistoryGraph
|
|
||||||
#include <QXmlStreamWriter>
|
|
||||||
#include <QXmlStreamAttributes>
|
|
||||||
|
|
||||||
|
|
||||||
/* Definitions ****************************************************************/
|
|
||||||
// number of history items to store
|
|
||||||
#define NUM_ITEMS_HISTORY 20000
|
|
||||||
|
|
||||||
|
|
||||||
/* Interface ******************************************************************/
|
|
||||||
class AHistoryGraph
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum EHistoryItemType
|
|
||||||
{
|
|
||||||
HIT_LOCAL_CONNECTION,
|
|
||||||
HIT_REMOTE_CONNECTION,
|
|
||||||
HIT_SERVER_STOP
|
|
||||||
};
|
|
||||||
|
|
||||||
AHistoryGraph ( const int iMaxDaysHistory );
|
|
||||||
virtual ~AHistoryGraph() { }
|
|
||||||
|
|
||||||
void Start ( const QString& sNewFileName );
|
|
||||||
void Add ( const QDateTime& newDateTime, const EHistoryItemType curType );
|
|
||||||
void Add ( const QDateTime& newDateTime, const QHostAddress ClientInetAddr );
|
|
||||||
virtual void Update ( );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
struct SHistoryData
|
|
||||||
{
|
|
||||||
QDateTime DateTime;
|
|
||||||
EHistoryItemType Type;
|
|
||||||
};
|
|
||||||
void DrawFrame ( const int iNewNumTicksX );
|
|
||||||
void AddMarker ( const SHistoryData& curHistoryData );
|
|
||||||
virtual void Save ( const QString sFileName ) = 0;
|
|
||||||
|
|
||||||
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height ) = 0;
|
|
||||||
virtual void text ( const unsigned int x, const unsigned int y, const QString& value ) = 0;
|
|
||||||
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 ) = 0;
|
|
||||||
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour ) = 0;
|
|
||||||
|
|
||||||
// Constructor sets these
|
|
||||||
QString sFileName;
|
|
||||||
bool bDoHistory;
|
|
||||||
CFIFO<SHistoryData> vHistoryDataFifo;
|
|
||||||
unsigned int iNumTicksX; // Class global, not sure why
|
|
||||||
int iHistMaxDays;
|
|
||||||
|
|
||||||
QString BackgroundColor;
|
|
||||||
QString FrameColor;
|
|
||||||
QString GridColor;
|
|
||||||
QString TextColor;
|
|
||||||
QString MarkerNewColor;
|
|
||||||
QString MarkerNewLocalColor;
|
|
||||||
QString MarkerStopColor;
|
|
||||||
|
|
||||||
const unsigned int canvasRectX;
|
|
||||||
const unsigned int canvasRectY;
|
|
||||||
const unsigned int canvasRectWidth;
|
|
||||||
const unsigned int canvasRectHeight;
|
|
||||||
|
|
||||||
const unsigned int iGridFrameOffset;
|
|
||||||
const unsigned int iGridWidthWeekend;
|
|
||||||
const unsigned int iXAxisTextHeight;
|
|
||||||
const unsigned int gridFrameX;
|
|
||||||
const unsigned int gridFrameY;
|
|
||||||
const unsigned int gridFrameWidth;
|
|
||||||
const unsigned int gridFrameHeight;
|
|
||||||
const unsigned int gridFrameRight;
|
|
||||||
const unsigned int gridFrameBottom;
|
|
||||||
|
|
||||||
const QString axisFontFamily;
|
|
||||||
const QString axisFontWeight;
|
|
||||||
const unsigned int axisFontSize;
|
|
||||||
|
|
||||||
const unsigned int iYAxisStart;
|
|
||||||
const unsigned int iYAxisEnd;
|
|
||||||
const unsigned int iNumTicksY;
|
|
||||||
|
|
||||||
const unsigned int iTextOffsetToGrid;
|
|
||||||
const unsigned int iTextOffsetX;
|
|
||||||
|
|
||||||
const unsigned int iMarkerSizeNewCon;
|
|
||||||
const unsigned int iMarkerSizeServSt;
|
|
||||||
|
|
||||||
// others
|
|
||||||
double dayXSpace;
|
|
||||||
unsigned int iYSpace;
|
|
||||||
QDate curDate;
|
|
||||||
QTimer TimerDailyUpdate;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Implementations ************************************************************/
|
|
||||||
#ifndef HEADLESS
|
|
||||||
class CJpegHistoryGraph : public QObject, virtual public AHistoryGraph
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CJpegHistoryGraph ( const int iMaxDaysHistory );
|
|
||||||
virtual void Update ( );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void Save ( const QString sFileName );
|
|
||||||
|
|
||||||
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height );
|
|
||||||
virtual void text ( const unsigned int x, const unsigned int y, const QString& value );
|
|
||||||
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 );
|
|
||||||
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour );
|
|
||||||
|
|
||||||
private:
|
|
||||||
QImage PlotPixmap;
|
|
||||||
int iAxisFontWeight;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void OnTimerDailyUpdate() { Update(); }
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class CSvgHistoryGraph : public QObject, virtual public AHistoryGraph
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CSvgHistoryGraph ( const int iMaxDaysHistory );
|
|
||||||
virtual void Update();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void Save ( const QString sFileName );
|
|
||||||
|
|
||||||
virtual void rect ( const unsigned int x, const unsigned int y, const unsigned int width, const unsigned int height );
|
|
||||||
virtual void text ( const unsigned int x, const unsigned int y, const QString& value );
|
|
||||||
virtual void line ( const unsigned int x1, const unsigned int y1, const unsigned int x2, const unsigned int y2, const unsigned int strokeWidth = 1 );
|
|
||||||
virtual void point ( const unsigned int x, const unsigned int y, const unsigned int size, const QString& colour );
|
|
||||||
|
|
||||||
private:
|
|
||||||
QXmlStreamAttributes svgRootAttributes;
|
|
||||||
QString svgImage;
|
|
||||||
QXmlStreamWriter svgStreamWriter;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void OnTimerDailyUpdate() { Update(); }
|
|
||||||
};
|
|
47
src/main.cpp
47
src/main.cpp
|
@ -72,7 +72,6 @@ int main ( int argc, char** argv )
|
||||||
bool bUseTranslation = true;
|
bool bUseTranslation = true;
|
||||||
bool bCustomPortNumberGiven = false;
|
bool bCustomPortNumberGiven = false;
|
||||||
int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS;
|
int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS;
|
||||||
int iMaxDaysHistory = DEFAULT_DAYS_HISTORY;
|
|
||||||
int iCtrlMIDIChannel = INVALID_MIDI_CH;
|
int iCtrlMIDIChannel = INVALID_MIDI_CH;
|
||||||
quint16 iPortNumber = DEFAULT_PORT_NUMBER;
|
quint16 iPortNumber = DEFAULT_PORT_NUMBER;
|
||||||
ELicenceType eLicenceType = LT_NO_LICENCE;
|
ELicenceType eLicenceType = LT_NO_LICENCE;
|
||||||
|
@ -81,7 +80,6 @@ int main ( int argc, char** argv )
|
||||||
QString strHTMLStatusFileName = "";
|
QString strHTMLStatusFileName = "";
|
||||||
QString strServerName = "";
|
QString strServerName = "";
|
||||||
QString strLoggingFileName = "";
|
QString strLoggingFileName = "";
|
||||||
QString strHistoryFileName = "";
|
|
||||||
QString strRecordingDirName = "";
|
QString strRecordingDirName = "";
|
||||||
QString strCentralServer = "";
|
QString strCentralServer = "";
|
||||||
QString strServerInfo = "";
|
QString strServerInfo = "";
|
||||||
|
@ -162,26 +160,6 @@ int main ( int argc, char** argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Maximum days in history display -------------------------------------
|
|
||||||
if ( GetNumericArgument ( tsConsole,
|
|
||||||
argc,
|
|
||||||
argv,
|
|
||||||
i,
|
|
||||||
"-D",
|
|
||||||
"--histdays",
|
|
||||||
1,
|
|
||||||
366,
|
|
||||||
rDbleArgument ) )
|
|
||||||
{
|
|
||||||
iMaxDaysHistory = static_cast<int> ( rDbleArgument );
|
|
||||||
|
|
||||||
tsConsole << "- maximum days in history display: "
|
|
||||||
<< iMaxDaysHistory << endl;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Start minimized -----------------------------------------------------
|
// Start minimized -----------------------------------------------------
|
||||||
if ( GetFlagArgument ( argv,
|
if ( GetFlagArgument ( argv,
|
||||||
i,
|
i,
|
||||||
|
@ -364,21 +342,6 @@ int main ( int argc, char** argv )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Server history file name --------------------------------------------
|
|
||||||
if ( GetStringArgument ( tsConsole,
|
|
||||||
argc,
|
|
||||||
argv,
|
|
||||||
i,
|
|
||||||
"-y",
|
|
||||||
"--history",
|
|
||||||
strArgument ) )
|
|
||||||
{
|
|
||||||
strHistoryFileName = strArgument;
|
|
||||||
tsConsole << "- history file name: " << strHistoryFileName << endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Recording directory -------------------------------------------------
|
// Recording directory -------------------------------------------------
|
||||||
if ( GetStringArgument ( tsConsole,
|
if ( GetStringArgument ( tsConsole,
|
||||||
argc,
|
argc,
|
||||||
|
@ -541,12 +504,6 @@ int main ( int argc, char** argv )
|
||||||
iPortNumber += 10; // increment by 10
|
iPortNumber += 10; // increment by 10
|
||||||
}
|
}
|
||||||
|
|
||||||
// display a warning if in server no GUI mode and a history file is requested
|
|
||||||
if ( !bIsClient && !bUseGUI && !strHistoryFileName.isEmpty() )
|
|
||||||
{
|
|
||||||
tsConsole << "Qt5 requires a windowing system to paint a JPEG image; image will use SVG" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Application/GUI setup ---------------------------------------------------
|
// Application/GUI setup ---------------------------------------------------
|
||||||
// Application object
|
// Application object
|
||||||
|
@ -655,11 +612,9 @@ int main ( int argc, char** argv )
|
||||||
// Server:
|
// Server:
|
||||||
// actual server object
|
// actual server object
|
||||||
CServer Server ( iNumServerChannels,
|
CServer Server ( iNumServerChannels,
|
||||||
iMaxDaysHistory,
|
|
||||||
strLoggingFileName,
|
strLoggingFileName,
|
||||||
iPortNumber,
|
iPortNumber,
|
||||||
strHTMLStatusFileName,
|
strHTMLStatusFileName,
|
||||||
strHistoryFileName,
|
|
||||||
strServerName,
|
strServerName,
|
||||||
strCentralServer,
|
strCentralServer,
|
||||||
strServerInfo,
|
strServerInfo,
|
||||||
|
@ -760,7 +715,6 @@ QString UsageArguments ( char **argv )
|
||||||
"\nServer only:\n"
|
"\nServer only:\n"
|
||||||
" -a, --servername server name, required for HTML status\n"
|
" -a, --servername server name, required for HTML status\n"
|
||||||
" -d, --discononquit disconnect all clients on quit\n"
|
" -d, --discononquit disconnect all clients on quit\n"
|
||||||
" -D, --histdays number of days of history to display\n"
|
|
||||||
" -e, --centralserver address of the central server\n"
|
" -e, --centralserver address of the central server\n"
|
||||||
" -F, --fastupdate use 64 samples frame size mode\n"
|
" -F, --fastupdate use 64 samples frame size mode\n"
|
||||||
" -g, --pingservers ping servers in list to keep NAT port open\n"
|
" -g, --pingservers ping servers in list to keep NAT port open\n"
|
||||||
|
@ -780,7 +734,6 @@ QString UsageArguments ( char **argv )
|
||||||
" -s, --server start server\n"
|
" -s, --server start server\n"
|
||||||
" -u, --numchannels maximum number of channels\n"
|
" -u, --numchannels maximum number of channels\n"
|
||||||
" -w, --welcomemessage welcome message on connect\n"
|
" -w, --welcomemessage welcome message on connect\n"
|
||||||
" -y, --history enable connection history and set file name\n"
|
|
||||||
" -z, --startminimized start minimizied\n"
|
" -z, --startminimized start minimizied\n"
|
||||||
"\nClient only:\n"
|
"\nClient only:\n"
|
||||||
" -M, --mutestream starts the application in muted state\n"
|
" -M, --mutestream starts the application in muted state\n"
|
||||||
|
|
|
@ -220,11 +220,9 @@ void CHighPrecisionTimer::run()
|
||||||
|
|
||||||
// CServer implementation ******************************************************
|
// CServer implementation ******************************************************
|
||||||
CServer::CServer ( const int iNewMaxNumChan,
|
CServer::CServer ( const int iNewMaxNumChan,
|
||||||
const int iMaxDaysHistory,
|
|
||||||
const QString& strLoggingFileName,
|
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 QString& strCentralServer,
|
const QString& strCentralServer,
|
||||||
const QString& strServerInfo,
|
const QString& strServerInfo,
|
||||||
|
@ -237,7 +235,7 @@ CServer::CServer ( const int iNewMaxNumChan,
|
||||||
bUseDoubleSystemFrameSize ( bNUseDoubleSystemFrameSize ),
|
bUseDoubleSystemFrameSize ( bNUseDoubleSystemFrameSize ),
|
||||||
iMaxNumChannels ( iNewMaxNumChan ),
|
iMaxNumChannels ( iNewMaxNumChan ),
|
||||||
Socket ( this, iPortNumber ),
|
Socket ( this, iPortNumber ),
|
||||||
Logging ( iMaxDaysHistory ),
|
Logging ( ),
|
||||||
iFrameCount ( 0 ),
|
iFrameCount ( 0 ),
|
||||||
bWriteStatusHTMLFile ( false ),
|
bWriteStatusHTMLFile ( false ),
|
||||||
HighPrecisionTimer ( bNUseDoubleSystemFrameSize ),
|
HighPrecisionTimer ( bNUseDoubleSystemFrameSize ),
|
||||||
|
@ -368,23 +366,9 @@ CServer::CServer ( const int iNewMaxNumChan,
|
||||||
// allocate worst case memory for the channel levels
|
// allocate worst case memory for the channel levels
|
||||||
vecChannelLevels.Init ( iMaxNumChannels );
|
vecChannelLevels.Init ( iMaxNumChannels );
|
||||||
|
|
||||||
// enable history graph (if requested)
|
|
||||||
if ( !strHistoryFileName.isEmpty() )
|
|
||||||
{
|
|
||||||
Logging.EnableHistory ( strHistoryFileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable logging (if requested)
|
// enable logging (if requested)
|
||||||
if ( !strLoggingFileName.isEmpty() )
|
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 );
|
Logging.Start ( strLoggingFileName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,11 +172,9 @@ class CServer :
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CServer ( const int iNewMaxNumChan,
|
CServer ( const int iNewMaxNumChan,
|
||||||
const int iMaxDaysHistory,
|
|
||||||
const QString& strLoggingFileName,
|
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 QString& strCentralServer,
|
const QString& strCentralServer,
|
||||||
const QString& strServerInfo,
|
const QString& strServerInfo,
|
||||||
|
|
|
@ -45,20 +45,6 @@ void CServerLogging::Start ( const QString& strLoggingFileName )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerLogging::EnableHistory ( const QString& strHistoryFileName )
|
|
||||||
{
|
|
||||||
#ifndef HEADLESS
|
|
||||||
if ( strHistoryFileName.right ( 4 ).compare ( ".svg", Qt::CaseInsensitive ) != 0 )
|
|
||||||
{
|
|
||||||
JpegHistoryGraph.Start ( strHistoryFileName );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
SvgHistoryGraph.Start ( strHistoryFileName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr,
|
void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr,
|
||||||
const int iNumberOfConnectedClients )
|
const int iNumberOfConnectedClients )
|
||||||
{
|
{
|
||||||
|
@ -69,12 +55,6 @@ void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr,
|
||||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||||
tsConsoleStream << strLogStr << endl; // on console
|
tsConsoleStream << strLogStr << endl; // on console
|
||||||
*this << strLogStr; // in log file
|
*this << strLogStr; // in log file
|
||||||
|
|
||||||
// add element to history
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerLogging::AddServerStopped()
|
void CServerLogging::AddServerStopped()
|
||||||
|
@ -85,17 +65,6 @@ void CServerLogging::AddServerStopped()
|
||||||
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
QTextStream& tsConsoleStream = *( ( new ConsoleWriterFactory() )->get() );
|
||||||
tsConsoleStream << strLogStr << endl; // on console
|
tsConsoleStream << strLogStr << endl; // on console
|
||||||
*this << strLogStr; // in log file
|
*this << strLogStr; // in log file
|
||||||
|
|
||||||
// add element to history and update on server stop
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Add ( QDateTime::currentDateTime(), AHistoryGraph::HIT_SERVER_STOP );
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Add ( QDateTime::currentDateTime(), AHistoryGraph::HIT_SERVER_STOP );
|
|
||||||
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Update();
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServerLogging::operator<< ( const QString& sNewStr )
|
void CServerLogging::operator<< ( const QString& sNewStr )
|
||||||
|
@ -109,68 +78,6 @@ 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() == 3 )
|
|
||||||
{
|
|
||||||
// first entry
|
|
||||||
QDateTime curDateTime =
|
|
||||||
QDateTime::fromString ( strlistCurLine.at ( 0 ).trimmed(),
|
|
||||||
"yyyy-MM-dd HH:mm:ss" );
|
|
||||||
|
|
||||||
if ( curDateTime.isValid() )
|
|
||||||
{
|
|
||||||
// check if server stop or new client connection
|
|
||||||
QString strAddress = strlistCurLine.at ( 1 ).trimmed();
|
|
||||||
|
|
||||||
if ( strAddress.isEmpty() )
|
|
||||||
{
|
|
||||||
// server stop
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Add ( curDateTime, AHistoryGraph::HIT_SERVER_STOP );
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Add ( curDateTime, CSvgHistoryGraph::HIT_SERVER_STOP );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QHostAddress curAddress;
|
|
||||||
|
|
||||||
// second entry is IP address
|
|
||||||
if ( curAddress.setAddress ( strlistCurLine.at ( 1 ).trimmed() ) )
|
|
||||||
{
|
|
||||||
// new client connection
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Add ( curDateTime, curAddress );
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Add ( curDateTime, curAddress );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph.Update();
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CServerLogging::CurTimeDatetoLogString()
|
QString CServerLogging::CurTimeDatetoLogString()
|
||||||
{
|
{
|
||||||
// time and date to string conversion
|
// time and date to string conversion
|
||||||
|
|
|
@ -32,26 +32,19 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include "historygraph.h"
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
class CServerLogging
|
class CServerLogging
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CServerLogging ( const int iMaxDaysHistory ) :
|
CServerLogging() :
|
||||||
#ifndef HEADLESS
|
|
||||||
JpegHistoryGraph ( iMaxDaysHistory ),
|
|
||||||
#endif
|
|
||||||
SvgHistoryGraph ( iMaxDaysHistory ),
|
|
||||||
bDoLogging ( false ),
|
bDoLogging ( false ),
|
||||||
File ( DEFAULT_LOG_FILE_NAME ) {}
|
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 AddServerStopped();
|
void AddServerStopped();
|
||||||
void ParseLogFile ( const QString& strFileName );
|
|
||||||
|
|
||||||
void AddNewConnection ( const QHostAddress& ClientInetAddr,
|
void AddNewConnection ( const QHostAddress& ClientInetAddr,
|
||||||
const int iNumberOfConnectedClients );
|
const int iNumberOfConnectedClients );
|
||||||
|
@ -60,10 +53,6 @@ protected:
|
||||||
void operator<< ( const QString& sNewStr );
|
void operator<< ( const QString& sNewStr );
|
||||||
QString CurTimeDatetoLogString();
|
QString CurTimeDatetoLogString();
|
||||||
|
|
||||||
#ifndef HEADLESS
|
bool bDoLogging;
|
||||||
CJpegHistoryGraph JpegHistoryGraph;
|
QFile File;
|
||||||
#endif
|
|
||||||
CSvgHistoryGraph SvgHistoryGraph;
|
|
||||||
bool bDoLogging;
|
|
||||||
QFile File;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue