some more server list implementation, some code style changes

This commit is contained in:
Volker Fischer 2011-04-04 18:57:49 +00:00
parent daa8a0eecb
commit cb2a72c996
6 changed files with 109 additions and 17 deletions

View file

@ -894,6 +894,7 @@ void CLlconClientDlg::SetGUIDesign ( const EGUIDesign eNewDesign )
" font: bold; }"
"QGroupBox::title { color: rgb(148, 148, 148); }" );
#ifdef _WIN32
// Workaround QT-Windows problem: This should not be necessary since in the
// background frame the style sheet for QRadioButton was already set. But it
// seems that it is only applied if the style was set to default and then back
@ -902,6 +903,7 @@ RadioButtonRevSelL->setStyleSheet ( "color: rgb(148, 148, 148);"
"font: bold;" );
RadioButtonRevSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
"font: bold;" );
#endif
break;
@ -909,9 +911,11 @@ RadioButtonRevSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
// reset style sheet and set original paramters
backgroundFrame->setStyleSheet ( "" );
#ifdef _WIN32
// Workaround QT-Windows problem: See above description
RadioButtonRevSelL->setStyleSheet ( "" );
RadioButtonRevSelR->setStyleSheet ( "" );
#endif
break;
}

View file

@ -115,12 +115,13 @@ public:
bool GetTimingStdDev ( double& dCurTiStdDev );
bool PutData ( const CVector<uint8_t>& vecbyRecBuf,
const int iNumBytesRead, const CHostAddress& HostAdr );
const int iNumBytesRead,
const CHostAddress& HostAdr );
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact );
CVector<QString>& vecsName,
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact );
protected:
// access functions for actual channels
@ -135,14 +136,14 @@ protected:
CVector<CChannelShortInfo> CreateChannelList();
void CreateAndSendChanListForAllConChannels();
void CreateAndSendChanListForThisChan ( const int iCurChanID );
void CreateAndSendChatTextForAllConChannels ( const int iCurChanID,
void CreateAndSendChatTextForAllConChannels ( const int iCurChanID,
const QString& strChatText );
void WriteHTMLChannelList();
CVector<int16_t> ProcessData ( const int iCurIndex,
CVector<int16_t> ProcessData ( const int iCurIndex,
CVector<CVector<int16_t> >& vecvecsData,
CVector<double>& vecdGains,
CVector<int>& vecNumAudioChannels );
CVector<double>& vecdGains,
CVector<int>& vecNumAudioChannels );
virtual void customEvent ( QEvent* Event );

View file

@ -29,6 +29,24 @@
CServerListManager::CServerListManager ( const bool NbEbld )
: bEnabled ( NbEbld )
{
// per definition, the very first entry is this server and this entry will
// never be deleted
ServerList.clear();
// per definition the client substitudes the IP address of the master server
// itself for his server list
ServerList.append ( CServerListEntry (
CHostAddress(),
"Master Server", // TEST
"",
QLocale::Germany, // TEST
"Munich", // TEST
0, // will be updated later
USED_NUM_CHANNELS,
true ) ); // TEST
// connections -------------------------------------------------------------
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPollList() ) );
@ -46,8 +64,9 @@ void CServerListManager::OnTimerPollList()
{
QMutexLocker locker ( &Mutex );
// check all list entries if they are still valid
for ( int iIdx = 0; iIdx < ServerList.size(); iIdx++ )
// check all list entries except of the very first one (which is the master
// server entry) if they are still valid
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
{
// 1 minute = 60 * 1000 ms
if ( ServerList[iIdx].RegisterTime.elapsed() >
@ -58,3 +77,47 @@ void CServerListManager::OnTimerPollList()
}
}
}
void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
const CServerCoreInfo& ServerInfo )
{
QMutexLocker locker ( &Mutex );
// define invalid index used as a flag
const int ciInvalidIdx = -1;
// Check if server is already registered. Use IP number and port number to
// fully identify a server. The very first list entry must not be checked
// since this is per definition the master server (i.e., this server)
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
{
if ( ServerList[iIdx].HostAddr == InetAddr )
{
// store entry index
iSelIdx = iIdx;
// entry found, leave for-loop
continue;
}
}
// if server is not yet registered, we have to create a new entry
if ( iSelIdx == ciInvalidIdx )
{
// create a new server list entry and init with received data
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
}
else
{
// update all data and call update registration function
ServerList[iSelIdx].strName = ServerInfo.strName;
ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
ServerList[iSelIdx].strCity = ServerInfo.strCity;
ServerList[iSelIdx].iNumClients = ServerInfo.iNumClients;
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
ServerList[iSelIdx].UpdateRegistration();
}
}

View file

@ -74,14 +74,14 @@ class CServerListEntry : public CServerInfo
{
public:
CServerListEntry() :
CServerInfo ( CHostAddress(),
CServerInfo ( CHostAddress(),
"",
"",
QLocale::AnyCountry,
"",
0,
0,
false ) { RegisterTime.start(); }
false ) { UpdateRegistration(); }
CServerListEntry ( const CHostAddress& NHAddr,
const QString& NsName,
@ -91,14 +91,28 @@ public:
const int NiNumClients,
const int NiMaxNumClients,
const bool NbPermOnline)
: CServerInfo ( NHAddr,
: CServerInfo ( NHAddr,
NsName,
NsTopic,
NeCountry,
NsCity,
NiNumClients,
NiMaxNumClients,
NbPermOnline ) { RegisterTime.start(); }
NbPermOnline ) { UpdateRegistration(); }
CServerListEntry ( const CHostAddress& NHAddr,
const CServerCoreInfo& NewCoreServerInfo )
: CServerInfo ( NHAddr,
NewCoreServerInfo.strName,
NewCoreServerInfo.strTopic,
NewCoreServerInfo.eCountry,
NewCoreServerInfo.strCity,
NewCoreServerInfo.iNumClients,
NewCoreServerInfo.iMaxNumClients,
NewCoreServerInfo.bPermanentOnline )
{ UpdateRegistration(); }
void UpdateRegistration() { RegisterTime.start(); }
public:
// time on which the entry was registered
@ -112,6 +126,8 @@ class CServerListManager : public QObject
public:
CServerListManager ( const bool NbEbld );
void RegisterServer ( const CHostAddress& InetAddr,
const CServerCoreInfo& ServerInfo );
protected:
QTimer TimerPollList;
QMutex Mutex;

View file

@ -60,8 +60,10 @@ void CSocket::Init ( const quint16 iPortNumber )
}
void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
const CHostAddress& HostAddr )
const CHostAddress& HostAddr )
{
QMutexLocker locker ( &Mutex );
const int iVecSizeOut = vecbySendBuf.Size();
if ( iVecSizeOut != 0 )
@ -72,7 +74,9 @@ void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
// const char*)
SocketDevice.writeDatagram (
(const char*) &( (CVector<uint8_t>) vecbySendBuf )[0],
iVecSizeOut, HostAddr.InetAddr, HostAddr.iPort );
iVecSizeOut,
HostAddr.InetAddr,
HostAddr.iPort );
}
}
@ -86,7 +90,9 @@ void CSocket::OnDataReceived()
// read block from network interface and query address of sender
const int iNumBytesRead =
SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
MAX_SIZE_BYTES_NETW_BUF, &SenderAddress, &SenderPort );
MAX_SIZE_BYTES_NETW_BUF,
&SenderAddress,
&SenderPort );
// check if an error occurred
if ( iNumBytesRead < 0 )

View file

@ -29,6 +29,7 @@
#include <qmessagebox.h>
#include <qudpsocket.h>
#include <qsocketnotifier.h>
#include <qmutex.h>
#include <vector>
#include "global.h"
#include "channel.h"
@ -63,6 +64,7 @@ protected:
void Init ( const quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER );
QUdpSocket SocketDevice;
QMutex Mutex;
CVector<uint8_t> vecbyRecBuf;
CHostAddress RecHostAddr;