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
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -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 */
|
||||
|
@ -93,7 +103,7 @@ int main ( int argc, char** argv )
|
|||
{
|
||||
/* server */
|
||||
// actual server object
|
||||
CServer Server;
|
||||
CServer Server ( bUseServerLogging );
|
||||
|
||||
if ( bUseGUI )
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -42,7 +42,7 @@ class CServer : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CServer ();
|
||||
CServer ( const bool bUseLogging );
|
||||
virtual ~CServer() {}
|
||||
|
||||
void Start ();
|
||||
|
@ -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