diff --git a/src/channel.cpp b/src/channel.cpp index b662fc94..29163cc1 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -121,6 +121,12 @@ void CChannelSet::CreateAndSendChanListForAllConChannels() vecChannels[i].CreateConClientListMes ( vecChanInfo ); } } + + // create status HTML file if enabled + if ( bWriteStatusHTMLFile ) + { + WriteHTMLChannelList(); + } } void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ) @@ -138,6 +144,12 @@ void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChan vecChannels[i].CreateConClientListMes ( vecChanInfo ); } } + + // create status HTML file if enabled + if ( bWriteStatusHTMLFile ) + { + WriteHTMLChannelList(); + } } void CChannelSet::CreateAndSendChanListForThisChan ( const int iCurChanID ) @@ -301,12 +313,6 @@ bool CChannelSet::PutData ( const CVector& vecbyRecBuf, // request, only the already connected clients get the list // automatically, because they don't know when new clients connect CreateAndSendChanListForAllExceptThisChan ( iCurChanID ); - - // create status HTML file if enabled - if ( bWriteStatusHTMLFile ) - { - WriteHTMLChannelList(); - } } } Mutex.unlock(); @@ -391,12 +397,6 @@ void CChannelSet::GetBlockAllConC ( CVector& vecChanID, { // update channel list for all currently connected clients CreateAndSendChanListForAllConChannels(); - - // create status HTML file if enabled - if ( bWriteStatusHTMLFile ) - { - WriteHTMLChannelList(); - } } } Mutex.unlock(); // release mutex @@ -432,23 +432,25 @@ void CChannelSet::GetConCliParam ( CVector& vecHostAddresses, } } +void CChannelSet::StartStatusHTMLFileWriting ( const QString& strNewFileName, + const QString& strNewServerNameWithPort ) +{ + // set important parameters + strServerHTMLFileListName = strNewFileName; + strServerNameWithPort = strNewServerNameWithPort; + // set flag + bWriteStatusHTMLFile = true; + // write initial file + WriteHTMLChannelList(); +} - - - - - -// TEST void CChannelSet::WriteHTMLChannelList() { // create channel list CVector vecChanInfo ( CChannelSet::CreateChannelList() ); -// TEST -QString strServerHTMLFileListName = "llconserverxxx.txt"; - // prepare file and stream QFile serverFileListFile ( strServerHTMLFileListName ); if ( !serverFileListFile.open ( QIODevice::WriteOnly | QIODevice::Text ) ) @@ -457,10 +459,6 @@ QString strServerHTMLFileListName = "llconserverxxx.txt"; } QTextStream streamFileOut ( &serverFileListFile ); - -// TEST -QString strServerNameWithPort = "llcon.dyndns.org:22122"; - streamFileOut << strServerNameWithPort << endl << "
    " << endl; // get the number of connected clients @@ -477,7 +475,7 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122"; if ( iNumConnClients == 0 ) { // no clients are connected -> empty server - streamFileOut << " Empty server" << endl; + streamFileOut << " No client connected" << endl; } else { @@ -486,7 +484,20 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122"; { if ( vecChannels[i].IsConnected() ) { - streamFileOut << "
  • " << vecChannels[i].GetName() << "
  • " << endl; + QString strCurChanName = vecChannels[i].GetName(); + + // if text is empty, show IP address instead + if ( strCurChanName.isEmpty() ) + { + // convert IP address to text and show it + const QHostAddress addrTest ( vecChannels[i].GetAddress().InetAddr ); + strCurChanName = addrTest.toString(); + + // remove last digits + strCurChanName = strCurChanName.section ( ".", 0, 2 ) + ".x"; + } + + streamFileOut << "
  • " << strCurChanName << "
  • " << endl; } } } @@ -497,13 +508,6 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122"; - - - - - - - /******************************************************************************\ * CChannel * \******************************************************************************/ diff --git a/src/channel.h b/src/channel.h index c1a9fce9..f672d7ce 100755 --- a/src/channel.h +++ b/src/channel.h @@ -237,6 +237,9 @@ public: CHostAddress GetAddress ( const int iChanNum ) { return vecChannels[iChanNum].GetAddress(); } + void StartStatusHTMLFileWriting ( const QString& strNewFileName, + const QString& strNewServerNameWithPort ); + protected: CVector CreateChannelList(); void CreateAndSendChanListForAllConChannels(); @@ -250,7 +253,10 @@ protected: CChannel vecChannels[MAX_NUM_CHANNELS]; QMutex Mutex; + // HTML file server status bool bWriteStatusHTMLFile; + QString strServerHTMLFileListName; + QString strServerNameWithPort; public slots: // CODE TAG: MAX_NUM_CHANNELS_TAG diff --git a/src/main.cpp b/src/main.cpp index c767be9c..0f2c2337 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,11 +43,12 @@ int main ( int argc, char** argv ) double rDbleArgument; /* check if server or client application shall be started */ - bool bIsClient = true; - bool bUseGUI = true; - bool bUseServerLogging = false; - quint16 iPortNumber = LLCON_PORT_NUMBER; - std::string strIniFileName = ""; + bool bIsClient = true; + bool bUseGUI = true; + bool bUseServerLogging = false; + quint16 iPortNumber = LLCON_PORT_NUMBER; + std::string strIniFileName = ""; + std::string strHTMLStatusFileName = ""; /* QT docu: argv()[0] is the program name, argv()[1] is the first argument and argv()[argc()-1] is the last argument. @@ -87,10 +88,19 @@ int main ( int argc, char** argv ) continue; } + /* HTML status file ------------------------------------------------------- */ + if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) ) + { + strHTMLStatusFileName = strArgument; + cerr << "HTML status file name: " << strHTMLStatusFileName << std::endl; + continue; + } + /* Initialization file ---------------------------------------------------- */ if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) { strIniFileName = strArgument; + cerr << "initialization file name: " << strIniFileName << std::endl; continue; } @@ -155,7 +165,10 @@ int main ( int argc, char** argv ) { // server // actual server object - CServer Server ( bUseServerLogging, iPortNumber ); + +// TODO use QString + + CServer Server ( bUseServerLogging, iPortNumber, strHTMLStatusFileName.c_str() ); if ( bUseGUI ) { @@ -208,6 +221,8 @@ std::string UsageArguments ( char **argv ) " -n, --nogui disable GUI (only avaiable for server)\n" " -l, --log enable logging\n" " -i, --inifile initialization file name (only available for client)\n" + " -p, --port local port number (only avaiable for server)\n" + " -m, --htmlstatus enable HTML status file, set file name (only avaiable for server)\n" " -h, -?, --help this help text\n" "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; } diff --git a/src/server.cpp b/src/server.cpp index dd3813ca..659cf06a 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 bool bUseLogging, const quint16 iPortNumber, + const QString& strHTMLStatusFileName ) : Socket ( &ChannelSet, this, iPortNumber ) { vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES ); @@ -54,6 +55,16 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber ) : { Logging.Start(); } + + // HTML status file writing + if ( !strHTMLStatusFileName.isEmpty() ) + { +// TEST only use port number as the server name right now + // (the static cast to integer of the port number is required so that it + // works correctly under Linux) + ChannelSet.StartStatusHTMLFileWriting ( strHTMLStatusFileName, + QString().number( static_cast ( iPortNumber ) ) ); + } } void CServer::OnSendProtMessage ( int iChID, CVector vecMessage ) diff --git a/src/server.h b/src/server.h index 60218c1f..43a17c94 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 bool bUseLogging, const quint16 iPortNumber, + const QString& strHTMLStatusFileName ); virtual ~CServer() {} void Start();