some more server list implementation, some code style changes
This commit is contained in:
parent
daa8a0eecb
commit
cb2a72c996
6 changed files with 109 additions and 17 deletions
|
@ -894,6 +894,7 @@ void CLlconClientDlg::SetGUIDesign ( const EGUIDesign eNewDesign )
|
||||||
" font: bold; }"
|
" font: bold; }"
|
||||||
"QGroupBox::title { color: rgb(148, 148, 148); }" );
|
"QGroupBox::title { color: rgb(148, 148, 148); }" );
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
// Workaround QT-Windows problem: This should not be necessary since in the
|
// Workaround QT-Windows problem: This should not be necessary since in the
|
||||||
// background frame the style sheet for QRadioButton was already set. But it
|
// 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
|
// 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;" );
|
"font: bold;" );
|
||||||
RadioButtonRevSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
|
RadioButtonRevSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
|
||||||
"font: bold;" );
|
"font: bold;" );
|
||||||
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -909,9 +911,11 @@ RadioButtonRevSelR->setStyleSheet ( "color: rgb(148, 148, 148);"
|
||||||
// reset style sheet and set original paramters
|
// reset style sheet and set original paramters
|
||||||
backgroundFrame->setStyleSheet ( "" );
|
backgroundFrame->setStyleSheet ( "" );
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
// Workaround QT-Windows problem: See above description
|
// Workaround QT-Windows problem: See above description
|
||||||
RadioButtonRevSelL->setStyleSheet ( "" );
|
RadioButtonRevSelL->setStyleSheet ( "" );
|
||||||
RadioButtonRevSelR->setStyleSheet ( "" );
|
RadioButtonRevSelR->setStyleSheet ( "" );
|
||||||
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,8 @@ public:
|
||||||
bool GetTimingStdDev ( double& dCurTiStdDev );
|
bool GetTimingStdDev ( double& dCurTiStdDev );
|
||||||
|
|
||||||
bool PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
bool PutData ( const CVector<uint8_t>& vecbyRecBuf,
|
||||||
const int iNumBytesRead, const CHostAddress& HostAdr );
|
const int iNumBytesRead,
|
||||||
|
const CHostAddress& HostAdr );
|
||||||
|
|
||||||
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
void GetConCliParam ( CVector<CHostAddress>& vecHostAddresses,
|
||||||
CVector<QString>& vecsName,
|
CVector<QString>& vecsName,
|
||||||
|
|
|
@ -29,6 +29,24 @@
|
||||||
CServerListManager::CServerListManager ( const bool NbEbld )
|
CServerListManager::CServerListManager ( const bool NbEbld )
|
||||||
: bEnabled ( 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 -------------------------------------------------------------
|
// connections -------------------------------------------------------------
|
||||||
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
|
||||||
this, SLOT ( OnTimerPollList() ) );
|
this, SLOT ( OnTimerPollList() ) );
|
||||||
|
@ -46,8 +64,9 @@ void CServerListManager::OnTimerPollList()
|
||||||
{
|
{
|
||||||
QMutexLocker locker ( &Mutex );
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
||||||
// check all list entries if they are still valid
|
// check all list entries except of the very first one (which is the master
|
||||||
for ( int iIdx = 0; iIdx < ServerList.size(); iIdx++ )
|
// server entry) if they are still valid
|
||||||
|
for ( int iIdx = 1; iIdx < ServerList.size(); iIdx++ )
|
||||||
{
|
{
|
||||||
// 1 minute = 60 * 1000 ms
|
// 1 minute = 60 * 1000 ms
|
||||||
if ( ServerList[iIdx].RegisterTime.elapsed() >
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public:
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
false ) { RegisterTime.start(); }
|
false ) { UpdateRegistration(); }
|
||||||
|
|
||||||
CServerListEntry ( const CHostAddress& NHAddr,
|
CServerListEntry ( const CHostAddress& NHAddr,
|
||||||
const QString& NsName,
|
const QString& NsName,
|
||||||
|
@ -98,7 +98,21 @@ public:
|
||||||
NsCity,
|
NsCity,
|
||||||
NiNumClients,
|
NiNumClients,
|
||||||
NiMaxNumClients,
|
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:
|
public:
|
||||||
// time on which the entry was registered
|
// time on which the entry was registered
|
||||||
|
@ -112,6 +126,8 @@ class CServerListManager : public QObject
|
||||||
public:
|
public:
|
||||||
CServerListManager ( const bool NbEbld );
|
CServerListManager ( const bool NbEbld );
|
||||||
|
|
||||||
|
void RegisterServer ( const CHostAddress& InetAddr,
|
||||||
|
const CServerCoreInfo& ServerInfo );
|
||||||
protected:
|
protected:
|
||||||
QTimer TimerPollList;
|
QTimer TimerPollList;
|
||||||
QMutex Mutex;
|
QMutex Mutex;
|
||||||
|
|
|
@ -62,6 +62,8 @@ void CSocket::Init ( const quint16 iPortNumber )
|
||||||
void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
|
void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
|
||||||
const CHostAddress& HostAddr )
|
const CHostAddress& HostAddr )
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker ( &Mutex );
|
||||||
|
|
||||||
const int iVecSizeOut = vecbySendBuf.Size();
|
const int iVecSizeOut = vecbySendBuf.Size();
|
||||||
|
|
||||||
if ( iVecSizeOut != 0 )
|
if ( iVecSizeOut != 0 )
|
||||||
|
@ -72,7 +74,9 @@ void CSocket::SendPacket ( const CVector<uint8_t>& vecbySendBuf,
|
||||||
// const char*)
|
// const char*)
|
||||||
SocketDevice.writeDatagram (
|
SocketDevice.writeDatagram (
|
||||||
(const char*) &( (CVector<uint8_t>) vecbySendBuf )[0],
|
(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
|
// read block from network interface and query address of sender
|
||||||
const int iNumBytesRead =
|
const int iNumBytesRead =
|
||||||
SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
|
SocketDevice.readDatagram ( (char*) &vecbyRecBuf[0],
|
||||||
MAX_SIZE_BYTES_NETW_BUF, &SenderAddress, &SenderPort );
|
MAX_SIZE_BYTES_NETW_BUF,
|
||||||
|
&SenderAddress,
|
||||||
|
&SenderPort );
|
||||||
|
|
||||||
// check if an error occurred
|
// check if an error occurred
|
||||||
if ( iNumBytesRead < 0 )
|
if ( iNumBytesRead < 0 )
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
#include <qudpsocket.h>
|
#include <qudpsocket.h>
|
||||||
#include <qsocketnotifier.h>
|
#include <qsocketnotifier.h>
|
||||||
|
#include <qmutex.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
|
@ -63,6 +64,7 @@ protected:
|
||||||
void Init ( const quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER );
|
void Init ( const quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER );
|
||||||
|
|
||||||
QUdpSocket SocketDevice;
|
QUdpSocket SocketDevice;
|
||||||
|
QMutex Mutex;
|
||||||
|
|
||||||
CVector<uint8_t> vecbyRecBuf;
|
CVector<uint8_t> vecbyRecBuf;
|
||||||
CHostAddress RecHostAddr;
|
CHostAddress RecHostAddr;
|
||||||
|
|
Loading…
Reference in a new issue