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