diff --git a/src/channel.cpp b/src/channel.cpp index 69effcdc..bcd880b0 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -284,6 +284,9 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, // the message here since the received data has to be put to the // channel first so that this channel is marked as connected bCreateChanList = true; + + // send message about new channel + emit ChannelConnected ( HostAdr ); } else { diff --git a/src/channel.h b/src/channel.h index 1452f871..b885e8c3 100755 --- a/src/channel.h +++ b/src/channel.h @@ -323,6 +323,7 @@ public slots: signals: void MessReadyForSending ( int iChID, CVector vecMessage ); + void ChannelConnected ( CHostAddress ChanAddr ); }; #endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */ diff --git a/src/main.cpp b/src/main.cpp index 3eb91a2d..12ef7e47 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ #include "settings.h" -/* Implementation *************************************************************/ +// Implementation ************************************************************** // these pointers are only used for the post-event routine QApplication* pApp = NULL; QDialog* pMainWindow = NULL; @@ -45,19 +45,19 @@ int main ( int argc, char** argv ) /* check if server or client application shall be started */ bool bIsClient = true; bool bUseGUI = true; - bool bUseServerLogging = false; bool bForceLowUploadRate = false; quint16 iPortNumber = LLCON_PORT_NUMBER; std::string strIniFileName = ""; std::string strHTMLStatusFileName = ""; std::string strServerName = ""; + std::string strLoggingFileName = ""; /* QT docu: argv()[0] is the program name, argv()[1] is the first argument and argv()[argc()-1] is the last argument. Start with first argument, therefore "i = 1" */ for ( int i = 1; i < argc; i++ ) { - /* Server mode flag ------------------------------------------------------- */ + // server mode flag ---------------------------------------------------------- if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) ) { bIsClient = false; @@ -65,7 +65,7 @@ int main ( int argc, char** argv ) continue; } - /* Use GUI flag ----------------------------------------------------------- */ + // use GUI flag -------------------------------------------------------------- if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) ) { bUseGUI = false; @@ -73,15 +73,15 @@ int main ( int argc, char** argv ) continue; } - /* Use logging flag ------------------------------------------------------- */ - if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) ) + // use logging --------------------------------------------------------------- + if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) ) { - bUseServerLogging = true; - cerr << "logging enabled" << std::endl; + strLoggingFileName = strArgument; + cerr << "logging file name: " << strLoggingFileName << std::endl; continue; } - /* Force low upload data rate flag ---------------------------------------- */ + // force low upload data rate flag ------------------------------------------- if ( GetFlagArgument ( argc, argv, i, "-u", "--lowuploadrate" ) ) { bForceLowUploadRate = true; @@ -89,7 +89,7 @@ int main ( int argc, char** argv ) continue; } - /* Port number ------------------------------------------------------------ */ + // port number --------------------------------------------------------------- if ( GetNumericArgument ( argc, argv, i, "-p", "--port", 0, 65535, rDbleArgument ) ) { @@ -98,7 +98,7 @@ int main ( int argc, char** argv ) continue; } - /* HTML status file ------------------------------------------------------- */ + // HTML status file ---------------------------------------------------------- if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) ) { strHTMLStatusFileName = strArgument; @@ -113,7 +113,7 @@ int main ( int argc, char** argv ) continue; } - /* Initialization file ---------------------------------------------------- */ + // initialization file ------------------------------------------------------- if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) { strIniFileName = strArgument; @@ -121,7 +121,7 @@ int main ( int argc, char** argv ) continue; } - /* Help (usage) flag ------------------------------------------------------ */ + // help (usage) flag --------------------------------------------------------- if ( ( !strcmp ( argv[i], "--help" ) ) || ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) { @@ -130,7 +130,7 @@ int main ( int argc, char** argv ) exit ( 1 ); } - /* Unknown option --------------------------------------------------------- */ + // unknown option ------------------------------------------------------------ cerr << argv[0] << ": "; cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help" << endl; @@ -190,7 +190,8 @@ int main ( int argc, char** argv ) // TODO use QString - CServer Server ( bUseServerLogging, iPortNumber, + CServer Server ( strLoggingFileName.c_str(), + iPortNumber, strHTMLStatusFileName.c_str(), strServerName.c_str(), bForceLowUploadRate ); diff --git a/src/server.cpp b/src/server.cpp index d14e7a07..5a7704c5 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -26,7 +26,8 @@ /* Implementation *************************************************************/ -CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber, +CServer::CServer ( const QString& strLoggingFileName, + const quint16 iPortNumber, const QString& strHTMLStatusFileName, const QString& strServerNameForHTMLStatusFile, const bool bForceLowUploadRate ) : @@ -47,6 +48,11 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber, SIGNAL ( MessReadyForSending ( int, CVector ) ), this, SLOT ( OnSendProtMessage ( int, CVector ) ) ); + // connection for logging + QObject::connect ( &ChannelSet, + SIGNAL ( ChannelConnected ( CHostAddress ) ), + this, SLOT ( OnNewChannel ( CHostAddress ) ) ); + #ifdef _WIN32 // event handling of custom events seems not to work under Windows in this // class, do not use automatic start/stop of server in Windows version @@ -54,9 +60,9 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber, #endif // enable logging (if requested) - if ( bUseLogging ) + if ( !strLoggingFileName.isEmpty() ) { - Logging.Start(); + Logging.Start ( strLoggingFileName ); } // HTML status file writing @@ -110,7 +116,18 @@ void CServer::Stop() Timer.stop(); // logging - QString strLogStr = CLogTimeDate::toString() + "Server stopped"; + const QString strLogStr = CLogTimeDate::toString() + ": server stopped " + "#####################################################"; + + qDebug() << strLogStr; // on console + Logging << strLogStr; // in log file +} + +void CServer::OnNewChannel ( CHostAddress ChanAddr ) +{ + // logging of new connected channel + const QString strLogStr = CLogTimeDate::toString() + ": " + + ChanAddr.InetAddr.toString() + " connected"; qDebug() << strLogStr; // on console Logging << strLogStr; // in log file diff --git a/src/server.h b/src/server.h index 459fc4aa..401de0ff 100755 --- a/src/server.h +++ b/src/server.h @@ -41,7 +41,8 @@ class CServer : public QObject Q_OBJECT public: - CServer ( const bool bUseLogging, const quint16 iPortNumber, + CServer ( const QString& strLoggingFileName, + const quint16 iPortNumber, const QString& strHTMLStatusFileName, const QString& strServerNameForHTMLStatusFile, const bool bForceLowUploadRate ); @@ -87,6 +88,7 @@ protected: public slots: void OnTimer(); void OnSendProtMessage ( int iChID, CVector vecMessage ); + void OnNewChannel ( CHostAddress ChanAddr ); }; #endif /* !defined ( SERVER_HOIHGE7LOKIH83JH8_3_43445KJIUHF1912__INCLUDED_ ) */ diff --git a/src/util.h b/src/util.h index a204ab50..c05ed954 100755 --- a/src/util.h +++ b/src/util.h @@ -487,10 +487,11 @@ public: } } - void Start() + void Start ( const QString& strLoggingFileName ) { // open file - if ( File.open ( QIODevice::Append ) ) + File.setFileName ( strLoggingFileName ); + if ( File.open ( QIODevice::Append | QIODevice::Text ) ) { bDoLogging = true; } @@ -503,6 +504,7 @@ public: // append new line in logging file QTextStream out ( &File ); out << sNewStr << endl; + File.flush(); } }