HTML status file -> more work

This commit is contained in:
Volker Fischer 2008-08-08 18:51:25 +00:00
parent 1cc421fc56
commit 58243640e7
5 changed files with 79 additions and 42 deletions

View file

@ -121,6 +121,12 @@ void CChannelSet::CreateAndSendChanListForAllConChannels()
vecChannels[i].CreateConClientListMes ( vecChanInfo ); vecChannels[i].CreateConClientListMes ( vecChanInfo );
} }
} }
// create status HTML file if enabled
if ( bWriteStatusHTMLFile )
{
WriteHTMLChannelList();
}
} }
void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID ) void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChanID )
@ -138,6 +144,12 @@ void CChannelSet::CreateAndSendChanListForAllExceptThisChan ( const int iCurChan
vecChannels[i].CreateConClientListMes ( vecChanInfo ); vecChannels[i].CreateConClientListMes ( vecChanInfo );
} }
} }
// create status HTML file if enabled
if ( bWriteStatusHTMLFile )
{
WriteHTMLChannelList();
}
} }
void CChannelSet::CreateAndSendChanListForThisChan ( const int iCurChanID ) void CChannelSet::CreateAndSendChanListForThisChan ( const int iCurChanID )
@ -301,12 +313,6 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
// request, only the already connected clients get the list // request, only the already connected clients get the list
// automatically, because they don't know when new clients connect // automatically, because they don't know when new clients connect
CreateAndSendChanListForAllExceptThisChan ( iCurChanID ); CreateAndSendChanListForAllExceptThisChan ( iCurChanID );
// create status HTML file if enabled
if ( bWriteStatusHTMLFile )
{
WriteHTMLChannelList();
}
} }
} }
Mutex.unlock(); Mutex.unlock();
@ -391,12 +397,6 @@ void CChannelSet::GetBlockAllConC ( CVector<int>& vecChanID,
{ {
// update channel list for all currently connected clients // update channel list for all currently connected clients
CreateAndSendChanListForAllConChannels(); CreateAndSendChanListForAllConChannels();
// create status HTML file if enabled
if ( bWriteStatusHTMLFile )
{
WriteHTMLChannelList();
}
} }
} }
Mutex.unlock(); // release mutex Mutex.unlock(); // release mutex
@ -432,23 +432,25 @@ void CChannelSet::GetConCliParam ( CVector<CHostAddress>& 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() void CChannelSet::WriteHTMLChannelList()
{ {
// create channel list // create channel list
CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() ); CVector<CChannelShortInfo> vecChanInfo ( CChannelSet::CreateChannelList() );
// TEST
QString strServerHTMLFileListName = "llconserverxxx.txt";
// prepare file and stream // prepare file and stream
QFile serverFileListFile ( strServerHTMLFileListName ); QFile serverFileListFile ( strServerHTMLFileListName );
if ( !serverFileListFile.open ( QIODevice::WriteOnly | QIODevice::Text ) ) if ( !serverFileListFile.open ( QIODevice::WriteOnly | QIODevice::Text ) )
@ -457,10 +459,6 @@ QString strServerHTMLFileListName = "llconserverxxx.txt";
} }
QTextStream streamFileOut ( &serverFileListFile ); QTextStream streamFileOut ( &serverFileListFile );
// TEST
QString strServerNameWithPort = "llcon.dyndns.org:22122";
streamFileOut << strServerNameWithPort << endl << "<ul>" << endl; streamFileOut << strServerNameWithPort << endl << "<ul>" << endl;
// get the number of connected clients // get the number of connected clients
@ -477,7 +475,7 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122";
if ( iNumConnClients == 0 ) if ( iNumConnClients == 0 )
{ {
// no clients are connected -> empty server // no clients are connected -> empty server
streamFileOut << " Empty server" << endl; streamFileOut << " No client connected" << endl;
} }
else else
{ {
@ -486,7 +484,20 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122";
{ {
if ( vecChannels[i].IsConnected() ) if ( vecChannels[i].IsConnected() )
{ {
streamFileOut << " <li>" << vecChannels[i].GetName() << "</li>" << 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 << " <li>" << strCurChanName << "</li>" << endl;
} }
} }
} }
@ -497,13 +508,6 @@ QString strServerNameWithPort = "llcon.dyndns.org:22122";
/******************************************************************************\ /******************************************************************************\
* CChannel * * CChannel *
\******************************************************************************/ \******************************************************************************/

View file

@ -237,6 +237,9 @@ public:
CHostAddress GetAddress ( const int iChanNum ) CHostAddress GetAddress ( const int iChanNum )
{ return vecChannels[iChanNum].GetAddress(); } { return vecChannels[iChanNum].GetAddress(); }
void StartStatusHTMLFileWriting ( const QString& strNewFileName,
const QString& strNewServerNameWithPort );
protected: protected:
CVector<CChannelShortInfo> CreateChannelList(); CVector<CChannelShortInfo> CreateChannelList();
void CreateAndSendChanListForAllConChannels(); void CreateAndSendChanListForAllConChannels();
@ -250,7 +253,10 @@ protected:
CChannel vecChannels[MAX_NUM_CHANNELS]; CChannel vecChannels[MAX_NUM_CHANNELS];
QMutex Mutex; QMutex Mutex;
// HTML file server status
bool bWriteStatusHTMLFile; bool bWriteStatusHTMLFile;
QString strServerHTMLFileListName;
QString strServerNameWithPort;
public slots: public slots:
// CODE TAG: MAX_NUM_CHANNELS_TAG // CODE TAG: MAX_NUM_CHANNELS_TAG

View file

@ -43,11 +43,12 @@ int main ( int argc, char** argv )
double rDbleArgument; double rDbleArgument;
/* check if server or client application shall be started */ /* check if server or client application shall be started */
bool bIsClient = true; bool bIsClient = true;
bool bUseGUI = true; bool bUseGUI = true;
bool bUseServerLogging = false; bool bUseServerLogging = false;
quint16 iPortNumber = LLCON_PORT_NUMBER; quint16 iPortNumber = LLCON_PORT_NUMBER;
std::string strIniFileName = ""; std::string strIniFileName = "";
std::string strHTMLStatusFileName = "";
/* QT docu: argv()[0] is the program name, argv()[1] is the first /* QT docu: argv()[0] is the program name, argv()[1] is the first
argument and argv()[argc()-1] is the last argument. argument and argv()[argc()-1] is the last argument.
@ -87,10 +88,19 @@ int main ( int argc, char** argv )
continue; 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 ---------------------------------------------------- */ /* Initialization file ---------------------------------------------------- */
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
{ {
strIniFileName = strArgument; strIniFileName = strArgument;
cerr << "initialization file name: " << strIniFileName << std::endl;
continue; continue;
} }
@ -155,7 +165,10 @@ int main ( int argc, char** argv )
{ {
// server // server
// actual server object // actual server object
CServer Server ( bUseServerLogging, iPortNumber );
// TODO use QString
CServer Server ( bUseServerLogging, iPortNumber, strHTMLStatusFileName.c_str() );
if ( bUseGUI ) if ( bUseGUI )
{ {
@ -208,6 +221,8 @@ std::string UsageArguments ( char **argv )
" -n, --nogui disable GUI (only avaiable for server)\n" " -n, --nogui disable GUI (only avaiable for server)\n"
" -l, --log enable logging\n" " -l, --log enable logging\n"
" -i, --inifile initialization file name (only available for client)\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" " -h, -?, --help this help text\n"
"Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n"; "Example: " + std::string ( argv[0] ) + " -l -inifile myinifile.ini\n";
} }

View file

@ -26,7 +26,8 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber ) : CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
const QString& strHTMLStatusFileName ) :
Socket ( &ChannelSet, this, iPortNumber ) Socket ( &ChannelSet, this, iPortNumber )
{ {
vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES ); vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES );
@ -54,6 +55,16 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber ) :
{ {
Logging.Start(); 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<int> ( iPortNumber ) ) );
}
} }
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ) void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )

View file

@ -41,7 +41,8 @@ class CServer : public QObject
Q_OBJECT Q_OBJECT
public: public:
CServer ( const bool bUseLogging, const quint16 iPortNumber ); CServer ( const bool bUseLogging, const quint16 iPortNumber,
const QString& strHTMLStatusFileName );
virtual ~CServer() {} virtual ~CServer() {}
void Start(); void Start();