diff --git a/src/main.cpp b/src/main.cpp index fa9c7f4e..68c506f5 100755 --- a/src/main.cpp +++ b/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 ); diff --git a/src/server.cpp b/src/server.cpp index 7c37fc02..c20ebfbe 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -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; diff --git a/src/server.h b/src/server.h index 4dec9083..e371d4bb 100755 --- a/src/server.h +++ b/src/server.h @@ -108,6 +108,7 @@ public: const QString& strHTMLStatusFileName, const QString& strHistoryFileName, const QString& strServerNameForHTMLStatusFile, + const bool bServerListEnabled, const bool bIsCentralServer, const QString& strCentralServer ); diff --git a/src/serverlist.cpp b/src/serverlist.cpp index a457e606..bb5304ca 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -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 diff --git a/src/serverlist.h b/src/serverlist.h index 5bd82baa..b4f041aa 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -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 ServerList; bool bEnabled; + bool bIsCentralServer; public slots: void OnTimerPollList();