HTML status file -> more work
This commit is contained in:
parent
1cc421fc56
commit
58243640e7
5 changed files with 79 additions and 42 deletions
|
@ -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<unsigned char>& 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<int>& 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<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()
|
||||
{
|
||||
// create channel list
|
||||
CVector<CChannelShortInfo> 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 << "<ul>" << 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 << " <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 *
|
||||
\******************************************************************************/
|
||||
|
|
|
@ -237,6 +237,9 @@ public:
|
|||
CHostAddress GetAddress ( const int iChanNum )
|
||||
{ return vecChannels[iChanNum].GetAddress(); }
|
||||
|
||||
void StartStatusHTMLFileWriting ( const QString& strNewFileName,
|
||||
const QString& strNewServerNameWithPort );
|
||||
|
||||
protected:
|
||||
CVector<CChannelShortInfo> 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
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -48,6 +48,7 @@ int main ( int argc, char** argv )
|
|||
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";
|
||||
}
|
||||
|
|
|
@ -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<int> ( iPortNumber ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue