added rudimental logging support
This commit is contained in:
parent
b00a299082
commit
c6717bbfee
5 changed files with 73 additions and 18 deletions
|
@ -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
|
||||
|
|
34
src/main.cpp
34
src/main.cpp
|
@ -37,9 +37,10 @@ QApplication* pApp = NULL;
|
|||
int main ( int argc, char** argv )
|
||||
{
|
||||
/* check if server or client application shall be started */
|
||||
bool bIsClient = true;
|
||||
bool bUseGUI = true;
|
||||
|
||||
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 */
|
||||
if ( argc > 1 )
|
||||
|
@ -58,7 +59,16 @@ int main ( int argc, char** argv )
|
|||
if ( !strShortOpt.compare ( argv[1] ) )
|
||||
{
|
||||
bIsClient = false;
|
||||
bUseGUI = 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
11
src/server.h
11
src/server.h
|
@ -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 );
|
||||
|
|
30
src/util.h
30
src/util.h
|
@ -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_) */
|
||||
|
|
Loading…
Reference in a new issue