added rudimental logging support

This commit is contained in:
Volker Fischer 2007-05-06 12:27:41 +00:00
parent b00a299082
commit c6717bbfee
5 changed files with 73 additions and 18 deletions

View file

@ -45,6 +45,8 @@
#define VERSION "1.0cvs"
#define APP_NAME "llcon"
// file name for logging file
#define LOG_FILE_NAME "llconsrvlog.txt"
/* defined port number for client and server */
#define LLCON_PORT_NUMBER 22122

View file

@ -39,6 +39,7 @@ int main ( int argc, char** argv )
/* check if server or client application shall be started */
bool bIsClient = true;
bool bUseGUI = true;
bool bUseServerLogging = false;
/* QT docu: argv()[0] is the program name, argv()[1] is the first
argument and argv()[argc()-1] is the last argument */
@ -60,6 +61,15 @@ int main ( int argc, char** argv )
bIsClient = false;
bUseGUI = false;
}
/* "-sln": start server with GUI disabled and logging enabled */
strShortOpt = "-sln";
if ( !strShortOpt.compare ( argv[1] ) )
{
bIsClient = false;
bUseGUI = false;
bUseServerLogging = true;
}
}
/* Application object */
@ -83,17 +93,17 @@ int main ( int argc, char** argv )
pApp = &app; /* Needed for post-event routine */
/* Show dialog */
ClientDlg.show ();
app.exec ();
ClientDlg.show();
app.exec();
/* Save settings to init-file */
Settings.Save ();
Settings.Save();
}
else
{
/* server */
// actual server object
CServer Server;
CServer Server ( bUseServerLogging );
if ( bUseGUI )
{
@ -106,14 +116,14 @@ int main ( int argc, char** argv )
pApp = &app; /* Needed for post-event routine */
/* Show dialog */
ServerDlg.show ();
app.exec ();
ServerDlg.show();
app.exec();
}
else
{
// only start application without using the GUI
qDebug ( CAboutDlg::GetVersionAndNameStr ( false ) );
app.exec ();
app.exec();
}
}
@ -130,6 +140,6 @@ void PostWinMessage ( const _MESSAGE_IDENT MessID, const int iMessageParam,
new CLlconEvent ( MessID, iMessageParam, iChanNum );
/* Qt will delete the event object when done */
QThread::postEvent ( pApp->mainWidget (), LlconEv );
QThread::postEvent ( pApp->mainWidget(), LlconEv );
}
}

View file

@ -26,7 +26,7 @@
/* Implementation *************************************************************/
CServer::CServer() : Socket ( &ChannelSet, this )
CServer::CServer ( const bool bUseLogging ) : Socket ( &ChannelSet, this )
{
vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES );
@ -47,6 +47,12 @@ CServer::CServer() : Socket ( &ChannelSet, this )
// class, do not use automatic start/stop of server in Windows version
Start();
#endif
// enable logging (if requested)
if ( bUseLogging )
{
Logging.Start();
}
}
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
@ -80,7 +86,11 @@ void CServer::Stop()
// stop main timer
Timer.stop();
qDebug ( CLogTimeDate::toString() + "Server stopped" );
// logging
QString strLogStr = CLogTimeDate::toString() + "Server stopped";
qDebug ( strLogStr ); // on console
Logging << strLogStr; // in log file
}
void CServer::OnTimer()

View file

@ -42,12 +42,12 @@ class CServer : public QObject
Q_OBJECT
public:
CServer ();
virtual ~CServer () {}
CServer ( const bool bUseLogging );
virtual ~CServer() {}
void Start ();
void Stop ();
bool IsRunning() { return Timer.isActive (); }
bool IsRunning() { return Timer.isActive(); }
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<std::string>& vecsName,
@ -60,7 +60,7 @@ public:
bool GetTimingStdDev ( double& dCurTiStdDev );
CChannelSet* GetChannelSet () { return &ChannelSet; }
CChannelSet* GetChannelSet() { return &ChannelSet; }
protected:
CVector<short> ProcessData ( CVector<CVector<double> >& vecvecdData,
@ -79,6 +79,9 @@ protected:
CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock;
// logging
CLogging Logging;
public slots:
void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );

View file

@ -467,5 +467,35 @@ public:
};
/* Time and Data to String conversion --------------------------------------- */
class CLogging
{
public:
CLogging() : bDoLogging ( false ), pFile ( NULL ) {}
virtual ~CLogging()
{
if ( pFile != NULL )
{
fclose ( pFile );
}
}
void Start()
{
// open file
pFile = fopen ( LOG_FILE_NAME, "a" );
}
CLogging& operator<< ( const QString & sNewStr )
{
fprintf ( pFile, "%s\n", sNewStr.latin1() );
fflush ( pFile );
return *this;
}
protected:
bool bDoLogging;
FILE* pFile;
};
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */