some more server list preparation work
This commit is contained in:
parent
1d4a7df6b5
commit
8dbb1949db
5 changed files with 62 additions and 12 deletions
19
src/main.cpp
19
src/main.cpp
|
@ -58,6 +58,7 @@ int main ( int argc, char** argv )
|
|||
bool bConnectOnStartup = false;
|
||||
bool bDisalbeLEDs = false;
|
||||
bool bIsCentralServer = false;
|
||||
bool bServerListEnabled = false;
|
||||
quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER;
|
||||
QString strIniFileName = "";
|
||||
QString strHTMLStatusFileName = "";
|
||||
|
@ -247,6 +248,14 @@ int main ( int argc, char** argv )
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Dependencies ------------------------------------------------------------
|
||||
|
||||
|
||||
// TEST for implementation and debugging, always enable the server list
|
||||
bServerListEnabled = true;
|
||||
|
||||
|
||||
// per definition: if we are in "GUI" server mode and no central server
|
||||
// address is given, we use the default central server address
|
||||
if ( !bIsClient && bUseGUI && strCentralServer.isEmpty() )
|
||||
|
@ -254,15 +263,20 @@ int main ( int argc, char** argv )
|
|||
strCentralServer = DEFAULT_SERVER_ADDRESS;
|
||||
}
|
||||
|
||||
// per definition: if we are in server mode and the central server address
|
||||
// is the localhost address, we are in central server mode
|
||||
// per definition: If we are in server mode and the central server address
|
||||
// is the localhost address, we are in central server mode. For the central
|
||||
// server, the server list is always enabled.
|
||||
if ( !bIsClient && !strCentralServer.isEmpty() )
|
||||
{
|
||||
bIsCentralServer =
|
||||
( !strCentralServer.toLower().compare ( "localhost" ) ||
|
||||
!strCentralServer.compare ( "127.0.0.1" ) );
|
||||
|
||||
bServerListEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
// Application/GUI setup ---------------------------------------------------
|
||||
// Application object
|
||||
QApplication app ( argc, argv, bUseGUI );
|
||||
|
||||
|
@ -334,6 +348,7 @@ int main ( int argc, char** argv )
|
|||
strHTMLStatusFileName,
|
||||
strHistoryFileName,
|
||||
strServerName,
|
||||
bServerListEnabled,
|
||||
bIsCentralServer,
|
||||
strCentralServer );
|
||||
|
||||
|
|
|
@ -169,11 +169,12 @@ CServer::CServer ( const QString& strLoggingFileName,
|
|||
const QString& strHTMLStatusFileName,
|
||||
const QString& strHistoryFileName,
|
||||
const QString& strServerNameForHTMLStatusFile,
|
||||
const bool bServerListEnabled,
|
||||
const bool bIsCentralServer,
|
||||
const QString& strCentralServer ) :
|
||||
Socket ( this, iPortNumber ),
|
||||
bWriteStatusHTMLFile ( false ),
|
||||
ServerListManager ( bIsCentralServer ) // enable server list for central server
|
||||
ServerListManager ( bServerListEnabled, bIsCentralServer )
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ public:
|
|||
const QString& strHTMLStatusFileName,
|
||||
const QString& strHistoryFileName,
|
||||
const QString& strServerNameForHTMLStatusFile,
|
||||
const bool bServerListEnabled,
|
||||
const bool bIsCentralServer,
|
||||
const QString& strCentralServer );
|
||||
|
||||
|
|
|
@ -26,8 +26,9 @@
|
|||
|
||||
|
||||
/* Implementation *************************************************************/
|
||||
CServerListManager::CServerListManager ( const bool NbEbld )
|
||||
: bEnabled ( NbEbld )
|
||||
CServerListManager::CServerListManager ( const bool NbEbld,
|
||||
const bool NbIsCentralServer )
|
||||
: bIsCentralServer ( NbIsCentralServer )
|
||||
{
|
||||
// per definition, the very first entry is this server and this entry will
|
||||
// never be deleted
|
||||
|
@ -52,15 +53,38 @@ ServerList.append ( CServerListEntry (
|
|||
this, SLOT ( OnTimerPollList() ) );
|
||||
|
||||
|
||||
// Timers ------------------------------------------------------------------
|
||||
// start timer for polling the server list
|
||||
// call set enable function after the connection of the timer since in this
|
||||
// function the timer gets started
|
||||
SetEnabled ( NbEbld );
|
||||
}
|
||||
|
||||
void CServerListManager::SetEnabled ( const bool bState )
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
bEnabled = bState;
|
||||
|
||||
if ( bEnabled )
|
||||
{
|
||||
// 1 minute = 60 * 1000 ms
|
||||
TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 );
|
||||
if ( bIsCentralServer )
|
||||
{
|
||||
// start timer for polling the server list if enabled
|
||||
// 1 minute = 60 * 1000 ms
|
||||
TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( bIsCentralServer )
|
||||
{
|
||||
// disable service -> stop timer
|
||||
TimerPollList.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Central server functionality ***********************************************/
|
||||
void CServerListManager::OnTimerPollList()
|
||||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
@ -84,7 +108,7 @@ void CServerListManager::RegisterServer ( const CHostAddress& InetAddr,
|
|||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
if ( bEnabled )
|
||||
if ( bIsCentralServer && bEnabled )
|
||||
{
|
||||
const int iCurServerListSize = ServerList.size();
|
||||
|
||||
|
@ -137,7 +161,7 @@ void CServerListManager::QueryServerList ( const CHostAddress& InetAddr )
|
|||
{
|
||||
QMutexLocker locker ( &Mutex );
|
||||
|
||||
if ( bEnabled )
|
||||
if ( bIsCentralServer && bEnabled )
|
||||
{
|
||||
|
||||
// TODO
|
||||
|
@ -148,3 +172,8 @@ void CServerListManager::QueryServerList ( const CHostAddress& InetAddr )
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Slave server functionality *************************************************/
|
||||
|
||||
// TODO
|
||||
|
|
|
@ -124,7 +124,10 @@ class CServerListManager : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CServerListManager ( const bool NbEbld );
|
||||
CServerListManager ( const bool NbEbld,
|
||||
const bool NbIsCentralServer );
|
||||
|
||||
void SetEnabled ( const bool bState );
|
||||
|
||||
void RegisterServer ( const CHostAddress& InetAddr,
|
||||
const CServerCoreInfo& ServerInfo );
|
||||
|
@ -136,6 +139,7 @@ protected:
|
|||
QMutex Mutex;
|
||||
QList<CServerListEntry> ServerList;
|
||||
bool bEnabled;
|
||||
bool bIsCentralServer;
|
||||
|
||||
public slots:
|
||||
void OnTimerPollList();
|
||||
|
|
Loading…
Reference in a new issue