support for the ping time measurement for each server list item

This commit is contained in:
Volker Fischer 2011-04-14 20:47:55 +00:00
parent 043a7f28e1
commit 375a9f2908
4 changed files with 64 additions and 20 deletions

View file

@ -61,6 +61,7 @@ void CConnectDlg::showEvent ( QShowEvent* )
// updated server list per definition) // updated server list per definition)
bServerListReceived = false; bServerListReceived = false;
// TEST // TEST
QString strNAddr = "llcon.dyndns.org:22122"; QString strNAddr = "llcon.dyndns.org:22122";
@ -78,14 +79,6 @@ QString strNAddr = "llcon.dyndns.org:22122";
// the server list request message // the server list request message
TimerReRequestServList.start ( SERV_LIST_REQ_UPDATE_TIME_MS ); TimerReRequestServList.start ( SERV_LIST_REQ_UPDATE_TIME_MS );
} }
// TODO
// only activate ping timer if window is actually shown
//TimerPing.start ( PING_UPDATE_TIME_MS );
// UpdateDisplay();
} }
void CConnectDlg::hideEvent ( QHideEvent* ) void CConnectDlg::hideEvent ( QHideEvent* )
@ -115,7 +108,9 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
ListViewServers->clear(); ListViewServers->clear();
// add list item for each server in the server list // add list item for each server in the server list
for ( int iIdx = 0; iIdx < vecServerInfo.Size(); iIdx++ ) const int iServerInfoLen = vecServerInfo.Size();
for ( int iIdx = 0; iIdx < iServerInfoLen; iIdx++ )
{ {
QTreeWidgetItem* pNewListViewItem = QTreeWidgetItem* pNewListViewItem =
new QTreeWidgetItem ( ListViewServers ); new QTreeWidgetItem ( ListViewServers );
@ -131,28 +126,70 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
pNewListViewItem->setText ( 2, pNewListViewItem->setText ( 2,
QString().setNum ( vecServerInfo[iIdx].iNumClients ) ); QString().setNum ( vecServerInfo[iIdx].iNumClients ) );
// store host address // store host address, note that for the very first entry which is
pNewListViewItem->setData ( 0, Qt::UserRole, // the central server, we have to use the receive host address
vecServerInfo[iIdx].HostAddr.toString() ); // instead
if ( iIdx > 0 )
{
pNewListViewItem->setData ( 0, Qt::UserRole,
vecServerInfo[iIdx].HostAddr.toString() );
}
else
{
// substitude the receive host address for central server
pNewListViewItem->setData ( 0, Qt::UserRole, InetAddr.toString() );
}
// TEST
pNewListViewItem->setText ( 2,
pNewListViewItem->data ( 0, Qt::UserRole ).toString() );
} }
// start the ping timer since the server list is filled now
TimerPing.start ( PING_UPDATE_TIME_MS );
} }
void CConnectDlg::OnTimerPing() void CConnectDlg::OnTimerPing()
{ {
// send ping message to server // send ping messages to the servers in the list
const int iServerListLen = ListViewServers->topLevelItemCount();
// TEST for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
//QHostAddress test ( "127.0.0.1" ); {
//emit CreateCLPingMes ( CHostAddress ( test, 22124 ) ); CHostAddress CurServerAddress;
// try to parse host address string which is stored as user data
// in the server list item GUI control element
if ( LlconNetwUtil().ParseNetworkAddress (
ListViewServers->topLevelItem ( iIdx )->
data ( 0, Qt::UserRole ).toString(),
CurServerAddress ) )
{
// if address is valid, send ping
emit CreateCLPingMes ( CurServerAddress );
}
}
} }
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr, void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime ) const int iPingTime )
{ {
// apply the received ping time to the correct server list entry
const int iServerListLen = ListViewServers->topLevelItemCount();
// ListViewServers-> for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
//// TEST {
//pListViewItem->setText ( 0, QString().setNum ( iPingTime ) ); // compare the received address with the user data string of the
// host address by a string compare
if ( !ListViewServers->topLevelItem ( iIdx )->
data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) )
{
ListViewServers->topLevelItem ( iIdx )->
setText ( 3, QString().setNum ( iPingTime ) );
}
}
} }

View file

@ -76,4 +76,5 @@ public slots:
signals: signals:
void ReqServerListQuery ( CHostAddress InetAddr ); void ReqServerListQuery ( CHostAddress InetAddr );
void CreateCLPingMes ( CHostAddress InetAddr );
}; };

View file

@ -446,6 +446,9 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
QObject::connect ( &ConnectDlg, SIGNAL ( ReqServerListQuery ( CHostAddress ) ), QObject::connect ( &ConnectDlg, SIGNAL ( ReqServerListQuery ( CHostAddress ) ),
this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) ); this, SLOT ( OnReqServerListQuery ( CHostAddress ) ) );
QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLPingMes ( CHostAddress ) ),
this, SLOT ( OnCreateCLPingMes ( CHostAddress ) ) );
// Timers ------------------------------------------------------------------ // Timers ------------------------------------------------------------------
// start timer for status bar // start timer for status bar

View file

@ -143,6 +143,9 @@ public slots:
void OnReqServerListQuery ( CHostAddress InetAddr ) void OnReqServerListQuery ( CHostAddress InetAddr )
{ pClient->CreateCLReqServerListMes ( InetAddr ); } { pClient->CreateCLReqServerListMes ( InetAddr ); }
void OnCreateCLPingMes ( CHostAddress InetAddr )
{ pClient->CreateCLPingMes ( InetAddr ); }
void OnCLServerListReceived ( CHostAddress InetAddr, void OnCLServerListReceived ( CHostAddress InetAddr,
CVector<CServerInfo> vecServerInfo ) CVector<CServerInfo> vecServerInfo )
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); } { ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }