mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
refactor: Remove CNetworkWatchdog
The watchdog was used in a few places as a shortcut to skip reading data. Further, it was used in some places in the UI to display connectivity. But it also introduced quite some complexity. In some cases it can be fragile: network accessibilty cannot be looked up on all platforms/hardware constellations. The connectivity could change between the last watchdog call and the real call. Hence all readers must still handle the case where the connection fails. To simplify swift and further reduce the dependency onto the project infrastructure (pings etc.), this removes the watchdog. This also removes the QNetworkConfigurationManager, which is deprecated and not available with Qt6.
This commit is contained in:
@@ -22,7 +22,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"pingIntervalSecs": 180,
|
||||
"predefinedServers": {
|
||||
"containerbase": [
|
||||
]
|
||||
|
||||
@@ -99,12 +99,10 @@ add_library(core SHARED
|
||||
db/databaseutils.h
|
||||
db/modeldatareader.h
|
||||
db/infodatareader.h
|
||||
db/networkwatchdog.h
|
||||
db/databasereader.h
|
||||
db/databaseauthentication.cpp
|
||||
db/databasewriter.cpp
|
||||
db/databasereaderconfig.h
|
||||
db/networkwatchdog.cpp
|
||||
db/backgrounddataupdater.h
|
||||
db/databaseutils.cpp
|
||||
db/modeldatareader.cpp
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "blackcore/application.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/context/contextsimulatorimpl.h"
|
||||
#include "blackcore/context/contextaudio.h"
|
||||
@@ -84,7 +83,6 @@ namespace BlackCore
|
||||
{}
|
||||
|
||||
CApplication::CApplication(const QString &applicationName, CApplicationInfo::Application application, bool init) : CIdentifiable(this),
|
||||
m_networkConfigManager(new QNetworkConfigurationManager(this)),
|
||||
m_accessManager(new QNetworkAccessManager(this)),
|
||||
m_applicationInfo(application),
|
||||
m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
||||
@@ -613,7 +611,6 @@ namespace BlackCore
|
||||
|
||||
QNetworkReply *CApplication::postToNetwork(const QNetworkRequest &request, int logId, QHttpMultiPart *multiPart, const CSlot<void(QNetworkReply *)> &callback)
|
||||
{
|
||||
if (!this->isNetworkAccessible()) { return nullptr; }
|
||||
if (multiPart->thread() != m_accessManager->thread())
|
||||
{
|
||||
multiPart->moveToThread(m_accessManager->thread());
|
||||
@@ -683,46 +680,6 @@ namespace BlackCore
|
||||
m_cookieManager->deleteAllCookies();
|
||||
}
|
||||
|
||||
CNetworkWatchdog *CApplication::getNetworkWatchdog() const
|
||||
{
|
||||
return m_networkWatchDog;
|
||||
}
|
||||
|
||||
void CApplication::setSwiftDbAccessibility(bool accessible)
|
||||
{
|
||||
if (!m_networkWatchDog) { return; }
|
||||
m_networkWatchDog->setDbAccessibility(accessible);
|
||||
}
|
||||
|
||||
int CApplication::triggerNetworkWatchdogChecks()
|
||||
{
|
||||
if (!m_networkWatchDog) { return -1; }
|
||||
return m_networkWatchDog->triggerCheck();
|
||||
}
|
||||
|
||||
bool CApplication::isNetworkAccessible() const
|
||||
{
|
||||
// skip test if there is no proper network config
|
||||
if (m_networkWatchDog && m_networkWatchDog->isNetworkAccessibilityCheckDisabled()) { return true; }
|
||||
|
||||
Q_ASSERT_X(m_accessManager, Q_FUNC_INFO, "no access manager");
|
||||
const QNetworkAccessManager::NetworkAccessibility a = m_accessManager->networkAccessible();
|
||||
if (a == QNetworkAccessManager::Accessible) { return true; }
|
||||
|
||||
// currently I also accept unknown because of that issue with Network Manager
|
||||
return a == QNetworkAccessManager::UnknownAccessibility;
|
||||
}
|
||||
|
||||
bool CApplication::isInternetAccessible() const
|
||||
{
|
||||
return m_networkWatchDog && m_networkWatchDog->isInternetAccessible();
|
||||
}
|
||||
|
||||
bool CApplication::isSwiftDbAccessible() const
|
||||
{
|
||||
return m_networkWatchDog && m_networkWatchDog->isSwiftDbAccessible();
|
||||
}
|
||||
|
||||
void CApplication::exit(int retcode)
|
||||
{
|
||||
if (sApp) { instance()->gracefulShutdown(); }
|
||||
@@ -861,12 +818,6 @@ namespace BlackCore
|
||||
new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this));
|
||||
Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO, "Missing web services");
|
||||
|
||||
// watchdog
|
||||
if (m_networkWatchDog)
|
||||
{
|
||||
connect(m_webDataServices.data(), &CWebDataServices::swiftDbDataRead, m_networkWatchDog, &CNetworkWatchdog::setDbAccessibility);
|
||||
}
|
||||
|
||||
emit this->webDataServicesStarted(true);
|
||||
}
|
||||
else
|
||||
@@ -955,9 +906,6 @@ namespace BlackCore
|
||||
m_inputManager->releaseDevices();
|
||||
}
|
||||
|
||||
// mark as shutdown
|
||||
if (m_networkWatchDog) { m_networkWatchDog->gracefulShutdown(); }
|
||||
|
||||
// save settings (but only when application was really alive)
|
||||
if (m_parsed && m_saveSettingsOnShutdown)
|
||||
{
|
||||
@@ -997,12 +945,6 @@ namespace BlackCore
|
||||
m_setupReader.reset();
|
||||
}
|
||||
|
||||
if (m_networkWatchDog)
|
||||
{
|
||||
m_networkWatchDog->quitAndWait();
|
||||
m_networkWatchDog = nullptr;
|
||||
}
|
||||
|
||||
CLogMessage(this).info(u"Graceful shutdown of CApplication, shutdown of logger");
|
||||
m_fileLogger->close();
|
||||
|
||||
@@ -1022,135 +964,18 @@ namespace BlackCore
|
||||
// void
|
||||
}
|
||||
|
||||
void CApplication::onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
{
|
||||
switch (accessible)
|
||||
{
|
||||
case QNetworkAccessManager::Accessible:
|
||||
m_accessManager->setNetworkAccessible(accessible); // for some reasons the queried value still is unknown
|
||||
CLogMessage(this).info(u"Network is accessible");
|
||||
break;
|
||||
case QNetworkAccessManager::NotAccessible:
|
||||
CLogMessage(this).error(u"Network not accessible");
|
||||
break;
|
||||
default:
|
||||
CLogMessage(this).warning(u"Network accessibility unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CApplication::onChangedInternetAccessibility(bool accessible)
|
||||
{
|
||||
if (accessible) { CLogMessage(this).info(u"Internet reported accessible"); }
|
||||
else { CLogMessage(this).warning(u"Internet not accessible"); }
|
||||
|
||||
emit this->changedInternetAccessibility(accessible);
|
||||
}
|
||||
|
||||
void CApplication::onChangedSwiftDbAccessibility(bool accessible, const CUrl &url)
|
||||
{
|
||||
if (accessible)
|
||||
{
|
||||
CLogMessage(this).info(u"swift DB reported accessible: '%1'") << url.toQString();
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).warning(u"swift DB not accessible: '%1'") << url.toQString();
|
||||
if (m_networkWatchDog)
|
||||
{
|
||||
CLogMessage(this).warning(m_networkWatchDog->getCheckInfo());
|
||||
}
|
||||
this->triggerNetworkAccessibilityCheck(10 * 1000); // crosscheck after some time
|
||||
}
|
||||
|
||||
emit this->changedSwiftDbAccessibility(accessible, url);
|
||||
}
|
||||
|
||||
void CApplication::onNetworkConfigurationsUpdateCompleted()
|
||||
{
|
||||
Q_ASSERT_X(m_networkConfigManager, Q_FUNC_INFO, "Need network config manager");
|
||||
if (this->isShuttingDown()) { return; }
|
||||
const QList<QNetworkConfiguration> allConfigurations = m_networkConfigManager->allConfigurations();
|
||||
if (allConfigurations.isEmpty())
|
||||
{
|
||||
// this is an odd situation we cannot handle, network check will be disabled
|
||||
if (m_networkWatchDog && m_networkWatchDog->isNetworkAccessibilityCheckEnabled())
|
||||
{
|
||||
m_networkWatchDog->disableNetworkAccessibilityCheck(true);
|
||||
m_accessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||
CLogMessage(this).warning(u"No network configurations found, disabling network accessibility checks");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int activeCount = 0;
|
||||
int validCount = 0;
|
||||
for (const QNetworkConfiguration &config : allConfigurations)
|
||||
{
|
||||
if (config.state() == QNetworkConfiguration::Active)
|
||||
{
|
||||
activeCount++;
|
||||
m_noNwAccessPoint = false;
|
||||
}
|
||||
if (config.isValid()) { validCount++; }
|
||||
}
|
||||
Q_UNUSED(validCount)
|
||||
|
||||
const bool canStartIAP = (m_networkConfigManager->capabilities() & QNetworkConfigurationManager::CanStartAndStopInterfaces);
|
||||
const bool disable = activeCount < 1; // only inactive
|
||||
if (disable && m_networkWatchDog && m_networkWatchDog->isNetworkAccessibilityCheckEnabled())
|
||||
{
|
||||
CLogMessage(this).warning(u"Disabling network accessibility check in watchdog");
|
||||
m_networkWatchDog->disableNetworkAccessibilityCheck(disable);
|
||||
}
|
||||
|
||||
// Is there default access point, use it
|
||||
const QNetworkConfiguration config = m_networkConfigManager->defaultConfiguration();
|
||||
if (!config.isValid() || (!canStartIAP && config.state() != QNetworkConfiguration::Active))
|
||||
{
|
||||
if (!m_noNwAccessPoint)
|
||||
{
|
||||
m_noNwAccessPoint = true;
|
||||
CLogMessage(this).warning(u"No network access point found for swift");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CApplication::initNetwork()
|
||||
{
|
||||
if (!m_accessManager) { m_accessManager = new QNetworkAccessManager(this); }
|
||||
if (!m_networkConfigManager) { m_networkConfigManager = new QNetworkConfigurationManager(this); }
|
||||
|
||||
if (!m_networkWatchDog)
|
||||
{
|
||||
// CNetworkWatchdog *nwWatchdog = new CNetworkWatchdog(this->isNetworkAccessible(), this);
|
||||
CNetworkWatchdog *nwWatchdog = new CNetworkWatchdog(true, this); // WLAN bug, default to true
|
||||
m_networkWatchDog = nwWatchdog; // not yet started
|
||||
m_cookieManager = new CCookieManager({}, this);
|
||||
m_cookieManager->setParent(m_accessManager);
|
||||
m_accessManager->setCookieJar(m_cookieManager);
|
||||
}
|
||||
m_cookieManager = new CCookieManager({}, this);
|
||||
m_cookieManager->setParent(m_accessManager);
|
||||
m_accessManager->setCookieJar(m_cookieManager);
|
||||
|
||||
// Init network
|
||||
Q_ASSERT_X(m_accessManager, Q_FUNC_INFO, "Need QAM");
|
||||
Q_ASSERT_X(m_networkConfigManager, Q_FUNC_INFO, "Need config manager");
|
||||
|
||||
// into watchdog
|
||||
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, m_networkWatchDog, &CNetworkWatchdog::setNetworkAccessibility, Qt::QueuedConnection);
|
||||
connect(m_networkConfigManager, &QNetworkConfigurationManager::onlineStateChanged, m_networkWatchDog, &CNetworkWatchdog::setOnline, Qt::QueuedConnection);
|
||||
connect(m_networkConfigManager, &QNetworkConfigurationManager::updateCompleted, m_networkWatchDog, &CNetworkWatchdog::networkConfigurationsUpdateCompleted, Qt::QueuedConnection);
|
||||
connect(m_networkConfigManager, &QNetworkConfigurationManager::updateCompleted, this, &CApplication::onNetworkConfigurationsUpdateCompleted, Qt::QueuedConnection);
|
||||
m_networkConfigManager->updateConfigurations();
|
||||
|
||||
// out from watchdog to application
|
||||
connect(m_networkWatchDog, &CNetworkWatchdog::changedNetworkAccessible, this, &CApplication::onChangedNetworkAccessibility, Qt::QueuedConnection);
|
||||
connect(m_networkWatchDog, &CNetworkWatchdog::changedInternetAccessibility, this, &CApplication::onChangedInternetAccessibility, Qt::QueuedConnection);
|
||||
connect(m_networkWatchDog, &CNetworkWatchdog::changedSwiftDbAccessibility, this, &CApplication::onChangedSwiftDbAccessibility, Qt::QueuedConnection);
|
||||
|
||||
CLogMessage::preformatted(CNetworkUtils::createNetworkReport(m_accessManager));
|
||||
m_networkWatchDog->start(QThread::LowestPriority);
|
||||
m_networkWatchDog->startUpdating(10);
|
||||
|
||||
// enable by setting accessible
|
||||
// http://doc.qt.io/qt-5/qnetworkaccessmanager.html#setNetworkAccessible
|
||||
@@ -1159,7 +984,7 @@ namespace BlackCore
|
||||
// create a network report in the log
|
||||
QTimer::singleShot(4000, this, [=] {
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
const QString r = CNetworkUtils::createNetworkConfigurationReport(m_networkConfigManager, m_accessManager);
|
||||
const QString r = CNetworkUtils::createNetworkAccessManagerReport(m_accessManager);
|
||||
CLogMessage(this).info(u"Network report:\n%1") << r;
|
||||
});
|
||||
}
|
||||
@@ -1601,19 +1426,6 @@ namespace BlackCore
|
||||
});
|
||||
}
|
||||
|
||||
void CApplication::triggerNetworkAccessibilityCheck(int deferredMs)
|
||||
{
|
||||
if (this->isShuttingDown()) { return; }
|
||||
if (!m_networkWatchDog) { return; }
|
||||
QTimer::singleShot(deferredMs, m_accessManager, [=] {
|
||||
// should be now in QAM thread
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
Q_ASSERT_X(CThreadUtils::isInThisThread(sApp->m_accessManager), Q_FUNC_INFO, "Wrong thread, must be QAM thread");
|
||||
const QNetworkAccessManager::NetworkAccessibility accessibility = m_accessManager->networkAccessible();
|
||||
m_networkWatchDog->setNetworkAccessibility(accessibility);
|
||||
});
|
||||
}
|
||||
|
||||
QNetworkReply *CApplication::httpRequestImpl(
|
||||
const QNetworkRequest &request, int logId,
|
||||
const CApplication::CallbackSlot &callback, int maxRedirects, NetworkRequestOrPostFunction requestOrPostMethod)
|
||||
@@ -1627,7 +1439,6 @@ namespace BlackCore
|
||||
const CallbackSlot &callback, const ProgressSlot &progress, int maxRedirects, NetworkRequestOrPostFunction getPostOrDeleteRequest)
|
||||
{
|
||||
if (this->isShuttingDown()) { return nullptr; }
|
||||
if (!this->isNetworkAccessible()) { return nullptr; }
|
||||
|
||||
QWriteLocker locker(&m_accessManagerLock);
|
||||
Q_ASSERT_X(m_accessManager->thread() == qApp->thread(), Q_FUNC_INFO, "Network manager supposed to be in main thread");
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <QCommandLineOption>
|
||||
#include <QCommandLineParser>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QReadWriteLock>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
@@ -69,10 +68,6 @@ namespace BlackCore
|
||||
class IContextOwnAircraft;
|
||||
class IContextSimulator;
|
||||
}
|
||||
namespace Db
|
||||
{
|
||||
class CNetworkWatchdog;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Our runtime. Normally one instance is to be initialized at the beginning of main, and thereafter
|
||||
@@ -433,26 +428,6 @@ namespace BlackCore
|
||||
//! Delete all cookies from cookie manager
|
||||
void deleteAllCookies();
|
||||
|
||||
//! Get the watchdog
|
||||
//! \private mostly for UNIT tests etc, normally not meant to be used directly
|
||||
Db::CNetworkWatchdog *getNetworkWatchdog() const;
|
||||
|
||||
//! Allows to mark the DB as "up" or "down"
|
||||
//! \see BlackCore::Db::CNetworkWatchdog::setDbAccessibility
|
||||
void setSwiftDbAccessibility(bool accessible);
|
||||
|
||||
//! \copydoc BlackCore::Db::CNetworkWatchdog::triggerCheck
|
||||
int triggerNetworkWatchdogChecks();
|
||||
|
||||
//! Is network accessible
|
||||
bool isNetworkAccessible() const;
|
||||
|
||||
//! \copydoc BlackCore::Db::CNetworkWatchdog::isInternetAccessible
|
||||
bool isInternetAccessible() const;
|
||||
|
||||
//! \copydoc BlackCore::Db::CNetworkWatchdog::isSwiftDbAccessible
|
||||
bool isSwiftDbAccessible() const;
|
||||
|
||||
//! Access to access manager
|
||||
//! \remark supposed to be used only in special cases
|
||||
const QNetworkAccessManager *getNetworkAccessManager() const { return m_accessManager; }
|
||||
@@ -461,10 +436,6 @@ namespace BlackCore
|
||||
//! \remark supposed to be used only in special cases
|
||||
QNetworkAccessManager *getNetworkAccessManager() { return m_accessManager; }
|
||||
|
||||
//! Access to configuration manager
|
||||
//! \remark supposed to be used only in special cases
|
||||
const QNetworkConfigurationManager *getNetworkConfigurationManager() const { return m_networkConfigManager; }
|
||||
|
||||
//! Web data services available?
|
||||
//! \threadsafe
|
||||
bool hasWebDataServices() const;
|
||||
@@ -545,12 +516,6 @@ namespace BlackCore
|
||||
//! Web data services started
|
||||
void webDataServicesStarted(bool success);
|
||||
|
||||
//! Internet accessibility changed
|
||||
void changedInternetAccessibility(bool accessible);
|
||||
|
||||
//! DB accessibility changed
|
||||
void changedSwiftDbAccessibility(bool accessible, const BlackMisc::Network::CUrl &testedUrl);
|
||||
|
||||
//! About to shutdown
|
||||
void aboutToShutdown();
|
||||
|
||||
@@ -623,18 +588,6 @@ namespace BlackCore
|
||||
//! Display version message
|
||||
void cmdLineVersionMessage();
|
||||
|
||||
//! Problem with network access manager
|
||||
void onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible);
|
||||
|
||||
//! Changed internet accessibility
|
||||
void onChangedInternetAccessibility(bool accessible);
|
||||
|
||||
//! Changed swift DB accessibility
|
||||
void onChangedSwiftDbAccessibility(bool accessible, const BlackMisc::Network::CUrl &url);
|
||||
|
||||
//! Network configurations update completed
|
||||
void onNetworkConfigurationsUpdateCompleted();
|
||||
|
||||
//! Init network
|
||||
void initNetwork();
|
||||
|
||||
@@ -669,10 +622,6 @@ namespace BlackCore
|
||||
int logId, const CallbackSlot &callback, const ProgressSlot &progress,
|
||||
int maxRedirects, NetworkRequestOrPostFunction getPostOrDeleteRequest);
|
||||
|
||||
//! Triggers a check of the network accessibility
|
||||
//! \remark this is a check that will double check that the watchdog will receive the correct QNetworkAccessManager::NetworkAccessibility
|
||||
void triggerNetworkAccessibilityCheck(int deferredMs);
|
||||
|
||||
//! Write meta information into the application directory so other swift versions can display them
|
||||
void tagApplicationDataDirectory();
|
||||
|
||||
@@ -691,9 +640,7 @@ namespace BlackCore
|
||||
bool parseCommandLineArguments();
|
||||
|
||||
CInputManager *m_inputManager = nullptr; //!< Input devices and hotkeys
|
||||
QNetworkConfigurationManager *m_networkConfigManager = nullptr; //!< configuration
|
||||
QNetworkAccessManager *m_accessManager = nullptr; //!< single network access manager
|
||||
Db::CNetworkWatchdog *m_networkWatchDog = nullptr; //!< checking DB/internet access
|
||||
BlackMisc::CApplicationInfo m_applicationInfo; //!< Application if specified
|
||||
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
|
||||
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
|
||||
@@ -706,7 +653,6 @@ namespace BlackCore
|
||||
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
||||
CWebReaderFlags::WebReader m_webReadersUsed; //!< Readers to be used
|
||||
Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< Load or used caching?
|
||||
bool m_noNwAccessPoint = false; //!< no network access point?
|
||||
bool m_useContexts = false; //!< use contexts
|
||||
bool m_devFlag = false; //!< dev. environment
|
||||
bool m_saveSettingsOnShutdown = true; //!< saving all settings on shutdown
|
||||
|
||||
@@ -271,10 +271,6 @@ namespace BlackCore::Context
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
CStatusMessageList msgs;
|
||||
if (!sApp || !sApp->isNetworkAccessible())
|
||||
{
|
||||
msgs.push_back(CStatusMessage(this).validationError(u"No network interface, simulation will not work properly"));
|
||||
}
|
||||
const CSimulatorInfo simulators = this->simulatorsWithInitializedModelSet();
|
||||
if (simulators.isNoSimulator())
|
||||
{
|
||||
|
||||
@@ -90,32 +90,6 @@ namespace BlackCore::Data
|
||||
return getDbRootDirectoryUrl().withAppendedPath("/service/jsonauthenticate.php").withSwitchedScheme("https", m_dbHttpsPort);
|
||||
}
|
||||
|
||||
CUrl CGlobalSetup::getDbClientPingServiceUrl() const
|
||||
{
|
||||
return getDbRootDirectoryUrl().withAppendedPath("/service/clientping.php").withSwitchedScheme("https", m_dbHttpsPort);
|
||||
}
|
||||
|
||||
CUrl CGlobalSetup::getDbClientPingServiceUrl(PingType type) const
|
||||
{
|
||||
CUrl pingUrl = this->getDbClientPingServiceUrl();
|
||||
if (pingUrl.isEmpty()) { CUrl(); }
|
||||
|
||||
pingUrl.appendQuery("uuid", QSysInfo::machineUniqueId());
|
||||
if (type.testFlag(PingLogoff)) { pingUrl.appendQuery("logoff", "true"); }
|
||||
if (type.testFlag(PingShutdown)) { pingUrl.appendQuery("shutdown", "true"); }
|
||||
if (type.testFlag(PingStarted)) { pingUrl.appendQuery("started", "true"); }
|
||||
pingUrl.appendQuery("os", CBuildConfig::getPlatformString());
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild()) { pingUrl.appendQuery("dev", "true"); }
|
||||
if (sApp)
|
||||
{
|
||||
const CCrashInfo ci = CCrashHandler::instance()->getCrashInfo();
|
||||
pingUrl.appendQuery("application", sApp->getApplicationNameAndVersion());
|
||||
if (!ci.getSimulatorString().isEmpty()) { pingUrl.appendQuery("fs", ci.getSimulatorString()); }
|
||||
if (!ci.getFlightNetworkString().isEmpty()) { pingUrl.appendQuery("network", ci.getFlightNetworkString()); }
|
||||
}
|
||||
return pingUrl;
|
||||
}
|
||||
|
||||
CUrl CGlobalSetup::getAlphaXSwiftBusFilesServiceUrl() const
|
||||
{
|
||||
return getDbRootDirectoryUrl().withAppendedPath("/service/jsonalphaxswiftbusfiles.php").withSwitchedScheme("https", m_dbHttpsPort);
|
||||
@@ -181,7 +155,7 @@ namespace BlackCore::Data
|
||||
|
||||
% u"Help URLs: " % m_onlineHelpUrls.toQString(i18n) % separator;
|
||||
s +=
|
||||
u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " % getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " % getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " % getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " % getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " % getDbLoginServiceUrl().toQString(i18n) % separator % u"DB client ping service: " % getDbClientPingServiceUrl().toQString(i18n);
|
||||
u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " % getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " % getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " % getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " % getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " % getDbLoginServiceUrl().toQString(i18n) % separator;
|
||||
s +=
|
||||
u"VATSIM METARs: " % getVatsimMetarsUrls().toQString(i18n) % separator % u"VATSIM data file: " % getVatsimDataFileUrls().toQString(i18n) % separator % u"VATSIM server file: " % getVatsimServerFileUrl().toQString(i18n) % separator
|
||||
|
||||
@@ -207,7 +181,6 @@ namespace BlackCore::Data
|
||||
case IndexDbHttpPort: return QVariant::fromValue(m_dbHttpPort);
|
||||
case IndexDbHttpsPort: return QVariant::fromValue(m_dbHttpsPort);
|
||||
case IndexDbLoginService: return QVariant::fromValue(this->getDbLoginServiceUrl());
|
||||
case IndexDbClientPingService: return QVariant::fromValue(this->getDbClientPingServiceUrl());
|
||||
case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrls);
|
||||
case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrls);
|
||||
case IndexVatsimServer: return QVariant::fromValue(m_vatsimServerFileUrl);
|
||||
@@ -239,7 +212,6 @@ namespace BlackCore::Data
|
||||
case IndexDbHttpPort: m_dbHttpPort = variant.toInt(); break;
|
||||
case IndexDbHttpsPort: m_dbHttpsPort = variant.toInt(); break;
|
||||
case IndexDbLoginService: break; // cannot be changed
|
||||
case IndexDbClientPingService: break; // cannot be changed
|
||||
case IndexVatsimData: m_vatsimDataFileUrls = variant.value<CUrlList>(); break;
|
||||
case IndexVatsimServer: m_vatsimServerFileUrl = variant.value<CUrl>(); break;
|
||||
case IndexVatsimHttpFsd: m_vatsimFsdHttpUrl = variant.value<CUrl>(); break;
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace BlackCore::Data
|
||||
IndexDbHttpPort,
|
||||
IndexDbHttpsPort,
|
||||
IndexDbLoginService,
|
||||
IndexDbClientPingService,
|
||||
IndexVatsimStatus,
|
||||
IndexVatsimMetars,
|
||||
IndexVatsimData,
|
||||
@@ -53,17 +52,6 @@ namespace BlackCore::Data
|
||||
IndexAfvMapUrl
|
||||
};
|
||||
|
||||
//! Add info when pinging
|
||||
enum PingTypeFlag
|
||||
{
|
||||
PingUnspecific = 0,
|
||||
PingLogoff = 1 << 0,
|
||||
PingStarted = 1 << 1,
|
||||
PingShutdown = 1 << 2,
|
||||
PingCompleteShutdown = PingLogoff | PingShutdown
|
||||
};
|
||||
Q_DECLARE_FLAGS(PingType, PingTypeFlag)
|
||||
|
||||
//! Default constructor
|
||||
CGlobalSetup();
|
||||
|
||||
@@ -114,16 +102,6 @@ namespace BlackCore::Data
|
||||
//! \remark based on getDbRootDirectoryUrl
|
||||
BlackMisc::Network::CUrl getDbLoginServiceUrl() const;
|
||||
|
||||
//! DB ping service
|
||||
//! \remark based on getDbRootDirectoryUrl
|
||||
BlackMisc::Network::CUrl getDbClientPingServiceUrl() const;
|
||||
|
||||
//! Ping the DB server, fire and forget (no feedback etc)
|
||||
BlackMisc::Network::CUrl getDbClientPingServiceUrl(PingType type) const;
|
||||
|
||||
//! Seconds between pings
|
||||
qint64 getDbClientPingIntervalSecs() const { return m_pingIntervalSecs; }
|
||||
|
||||
//! alpha XSwiftBus files available
|
||||
BlackMisc::Network::CUrl getAlphaXSwiftBusFilesServiceUrl() const;
|
||||
|
||||
@@ -202,7 +180,6 @@ namespace BlackCore::Data
|
||||
private:
|
||||
int m_dbHttpPort = 80; //!< port
|
||||
int m_dbHttpsPort = 443; //!< SSL port
|
||||
qint64 m_pingIntervalSecs = 180; //!< seconds between datastore pings
|
||||
QString m_mappingMinimumVersion; //!< minimum version
|
||||
BlackMisc::Network::CUrl m_crashReportServerUrl; //!< crash report server
|
||||
BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB
|
||||
@@ -228,7 +205,6 @@ namespace BlackCore::Data
|
||||
BLACK_METAMEMBER(dbRootDirectoryUrl, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(dbHttpPort, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(dbHttpsPort, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(pingIntervalSecs, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(vatsimStatusFileUrls, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(vatsimDataFileUrls, 0, RequiredForJson),
|
||||
BLACK_METAMEMBER(vatsimServerFileUrl, 0, RequiredForJson),
|
||||
@@ -250,8 +226,5 @@ namespace BlackCore::Data
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup)
|
||||
Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup::PingTypeFlag)
|
||||
Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup::PingType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::Data::CGlobalSetup::PingType)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -244,11 +244,6 @@ namespace BlackCore::Db
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
entity &= CEntityFlags::AirportEntity;
|
||||
if (!this->isInternetAccessible())
|
||||
{
|
||||
emit this->dataRead(entity, CEntityFlags::ReadSkipped, 0, {});
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.testFlag(CEntityFlags::AirportEntity))
|
||||
{
|
||||
|
||||
@@ -213,7 +213,6 @@ namespace BlackCore::Db
|
||||
|
||||
// ps_read is implemented in the derived classes
|
||||
if (entities == CEntityFlags::NoEntity) { return; }
|
||||
if (!this->isInternetAccessible(QStringLiteral("No network/internet access, will not read %1").arg(CEntityFlags::flagToString(entities)))) { return; }
|
||||
|
||||
//! https://dev.swift-project.org/T490
|
||||
QPointer<CDatabaseReader> myself(this);
|
||||
@@ -381,8 +380,6 @@ namespace BlackCore::Db
|
||||
|
||||
int CDatabaseReader::requestHeadersOfSharedFiles(CEntityFlags::Entity entities)
|
||||
{
|
||||
if (!this->isInternetAccessible(QStringLiteral("No network/internet access, will not read shared file headers for %1").arg(CEntityFlags::flagToString(entities)))) { return false; }
|
||||
|
||||
CEntityFlags::Entity allEntities = entities & CEntityFlags::AllDbEntitiesNoInfoObjects;
|
||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities);
|
||||
const CUrl urlSharedDbdata = CDatabaseReader::getSharedDbdataDirectoryUrl();
|
||||
|
||||
@@ -171,12 +171,6 @@ namespace BlackCore::Db
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
entities &= CEntityFlags::AllIcaoCountriesCategory;
|
||||
|
||||
if (!this->isInternetAccessible())
|
||||
{
|
||||
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0, {});
|
||||
return;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity entitiesTriggered = CEntityFlags::NoEntity;
|
||||
CUrl url;
|
||||
if (entities.testFlag(CEntityFlags::AircraftIcaoEntity))
|
||||
|
||||
@@ -182,11 +182,6 @@ namespace BlackCore::Db
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
entities &= CEntityFlags::DistributorLiveryModel;
|
||||
if (!this->isInternetAccessible())
|
||||
{
|
||||
emit this->dataRead(entities, CEntityFlags::ReadSkipped, 0, {});
|
||||
return;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||
CUrl url;
|
||||
|
||||
@@ -1,356 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QDateTime>
|
||||
#include <QPointer>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackCore::Data;
|
||||
|
||||
namespace BlackCore::Db
|
||||
{
|
||||
const QStringList &CNetworkWatchdog::getLogCategories()
|
||||
{
|
||||
static const QStringList cats = CContinuousWorker::getLogCategories() + QStringList {
|
||||
CLogCategories::swiftDbWebservice(), CLogCategories::webservice(), CLogCategories::network()
|
||||
};
|
||||
return cats;
|
||||
}
|
||||
|
||||
CNetworkWatchdog::CNetworkWatchdog(bool networkAccessible, QObject *owner) : CContinuousWorker(owner, "swift DB watchdog")
|
||||
{
|
||||
Q_ASSERT_X(owner, Q_FUNC_INFO, "Need owner (normally sApp)");
|
||||
|
||||
m_networkAccessible = networkAccessible;
|
||||
m_internetAccessible = networkAccessible;
|
||||
m_dbAccessible = networkAccessible && m_checkDbAccessibility;
|
||||
|
||||
m_updateTimer.setInterval(10 * 1000);
|
||||
connect(&m_updateTimer, &QTimer::timeout, this, &CNetworkWatchdog::doWork);
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::setDbAccessibility(bool accessible)
|
||||
{
|
||||
m_dbAccessible = accessible;
|
||||
m_internetAccessible = m_internetAccessible && this->isNetworkkAccessibleOrCheckDisabled();
|
||||
|
||||
// restart timer
|
||||
QPointer<CNetworkWatchdog> myself(this);
|
||||
QTimer::singleShot(0, &m_updateTimer, [=] {
|
||||
if (!myself) { return; }
|
||||
m_updateTimer.start();
|
||||
});
|
||||
}
|
||||
|
||||
bool CNetworkWatchdog::hasWorkingSharedUrl() const
|
||||
{
|
||||
if (!this->isNetworkkAccessibleOrCheckDisabled()) { return false; }
|
||||
return !this->getWorkingSharedUrl().isEmpty();
|
||||
}
|
||||
|
||||
CUrl CNetworkWatchdog::getWorkingSharedUrl() const
|
||||
{
|
||||
if (!this->isNetworkkAccessibleOrCheckDisabled()) { return CUrl(); }
|
||||
QReadLocker l(&m_lockUrl);
|
||||
return m_workingSharedUrl;
|
||||
}
|
||||
|
||||
int CNetworkWatchdog::triggerCheck()
|
||||
{
|
||||
if (!this->doWorkCheck()) { return false; } // senseless
|
||||
if (m_checkInProgress) { return -1; }
|
||||
|
||||
const int n = this->getCheckCount();
|
||||
const QPointer<CNetworkWatchdog> myself(this);
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
if (!myself) { return; }
|
||||
this->doWork();
|
||||
});
|
||||
return n; // triggered
|
||||
}
|
||||
|
||||
QString CNetworkWatchdog::getLastPingDbUrl() const
|
||||
{
|
||||
QReadLocker l(&m_lockUrl);
|
||||
return m_lastPingUrl;
|
||||
}
|
||||
|
||||
QString CNetworkWatchdog::getCheckInfo() const
|
||||
{
|
||||
static const QString info("Network accessibility check: %1 | Internet accessible: %2 (good: %3 / bad: %4), swift DB accessible: %5 (good: %6 / bad: %7) DB last ping URL: '%8' canConnect: %9ms");
|
||||
const QString pUrl(this->getLastPingDbUrl());
|
||||
static const QString cct = QString::number(CanConnectTimeMs);
|
||||
return info.arg(boolToEnabledDisabled(!this->isNetworkAccessibilityCheckDisabled()), boolToYesNo(this->isInternetAccessible())).arg(m_totalGoodCountInternet).arg(m_totalBadCountInternet).arg(boolToYesNo(this->isSwiftDbAccessible())).arg(m_totalGoodCountDb).arg(m_totalBadCountDb).arg(pUrl, cct); // cct has to be string, otherwise the % in the URL will be replaced
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::setWorkingSharedUrl(const CUrl &workingUrl)
|
||||
{
|
||||
QWriteLocker l(&m_lockUrl);
|
||||
m_workingSharedUrl = workingUrl;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::doWork()
|
||||
{
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
if (m_checkInProgress) { return; }
|
||||
m_checkInProgress = true;
|
||||
|
||||
// lazy init
|
||||
if (!this->hasWorkingSharedUrl())
|
||||
{
|
||||
this->initWorkingSharedUrlFromSetup();
|
||||
}
|
||||
|
||||
// checks
|
||||
do
|
||||
{
|
||||
const bool wasDbAvailable = m_dbAccessible;
|
||||
const bool wasInternetAvailable = m_internetAccessible;
|
||||
const bool networkAccessible = this->isNetworkkAccessibleOrCheckDisabled();
|
||||
const CUrl testUrl(CNetworkWatchdog::dbTestUrl());
|
||||
bool canConnectDb = m_checkDbAccessibility && networkAccessible;
|
||||
if (canConnectDb)
|
||||
{
|
||||
// running here in background worker check twice
|
||||
canConnectDb = CNetworkUtils::canConnect(testUrl, CanConnectTimeMs);
|
||||
if (!canConnectDb)
|
||||
{
|
||||
canConnectDb = CNetworkUtils::canConnect(testUrl, CanConnectTimeMs);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_checkDbAccessibility && m_doDetailedCheck && canConnectDb)
|
||||
{
|
||||
const qint64 pingIntervalSecs = sApp->getGlobalSetup().getDbClientPingIntervalSecs();
|
||||
if (QDateTime::currentSecsSinceEpoch() >= pingIntervalSecs)
|
||||
{
|
||||
m_nextPingSecsSinceEpoch = QDateTime::currentSecsSinceEpoch() + pingIntervalSecs;
|
||||
this->pingDbClientService(CGlobalSetup::PingStarted);
|
||||
canConnectDb = m_lastClientPingSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
bool canConnectInternet = canConnectDb;
|
||||
bool checkInternetAccess = !canConnectDb;
|
||||
|
||||
m_dbAccessible = canConnectDb;
|
||||
if (canConnectDb)
|
||||
{
|
||||
// DB available means internet available
|
||||
m_internetAccessible = canConnectDb;
|
||||
}
|
||||
|
||||
// check shared URL
|
||||
if (!this->doWorkCheck()) { break; }
|
||||
if (m_checkSharedUrl && networkAccessible)
|
||||
{
|
||||
if (CNetworkUtils::canConnect(this->getWorkingSharedUrl()))
|
||||
{
|
||||
canConnectInternet = true;
|
||||
checkInternetAccess = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
const CUrl sharedUrl = this->getWorkingSharedUrl();
|
||||
if (!sharedUrl.isEmpty())
|
||||
{
|
||||
canConnectInternet = true;
|
||||
checkInternetAccess = false;
|
||||
this->setWorkingSharedUrl(sharedUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check internet access
|
||||
if (!this->doWorkCheck()) { break; }
|
||||
if (checkInternetAccess)
|
||||
{
|
||||
QString message;
|
||||
static const QString testHost1("www.google.com"); // what else?
|
||||
canConnectInternet = CNetworkUtils::canConnect(testHost1, 443, message, CanConnectTimeMs); // running in background worker
|
||||
if (!canConnectInternet)
|
||||
{
|
||||
static const QString testHost2("www.microsoft.com"); // secondary test
|
||||
canConnectInternet = CNetworkUtils::canConnect(testHost2, 80, message, CanConnectTimeMs); // running in background worker
|
||||
}
|
||||
if (canConnectInternet) { m_totalGoodCountInternet++; }
|
||||
else { m_totalBadCountInternet++; }
|
||||
}
|
||||
m_internetAccessible = networkAccessible && canConnectInternet;
|
||||
|
||||
// signals
|
||||
this->triggerChangedSignals(wasDbAvailable, wasInternetAvailable);
|
||||
}
|
||||
while (false);
|
||||
|
||||
m_updateTimer.start(); // restart
|
||||
m_totalCheckCount++;
|
||||
m_checkInProgress = false;
|
||||
}
|
||||
|
||||
bool CNetworkWatchdog::doWorkCheck() const
|
||||
{
|
||||
if (!sApp || sApp->isShuttingDown()) { return false; }
|
||||
if (!this->isEnabled()) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::setNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessibility)
|
||||
{
|
||||
// avoid unnecessary signals
|
||||
const int accessiblityInt = static_cast<int>(accessibility);
|
||||
if (m_networkAccessibility == accessiblityInt) { return; }
|
||||
if (m_disableNetworkCheck) { return; } // ignore with disabled check
|
||||
|
||||
// shift to thread
|
||||
if (!CThreadUtils::isInThisThread(this))
|
||||
{
|
||||
QPointer<CNetworkWatchdog> myself(this);
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
if (!sApp || sApp->isShuttingDown() || !myself) { return; }
|
||||
this->setNetworkAccessibility(accessibility);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// set values
|
||||
m_networkAccessibility = accessiblityInt;
|
||||
const bool db = m_dbAccessible;
|
||||
const bool internet = m_internetAccessible;
|
||||
|
||||
// Intentionally rating unknown as "accessible"
|
||||
if (accessibility == QNetworkAccessManager::NotAccessible)
|
||||
{
|
||||
m_networkAccessible = false;
|
||||
m_dbAccessible = false;
|
||||
m_internetAccessible = false;
|
||||
this->triggerChangedSignals(db, internet);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_networkAccessible = true;
|
||||
const QPointer<CNetworkWatchdog> myself(this);
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
if (!myself) { return; }
|
||||
this->doWork();
|
||||
});
|
||||
}
|
||||
|
||||
emit this->changedNetworkAccessible(accessibility);
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::networkConfigurationsUpdateCompleted()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::setOnline(bool online)
|
||||
{
|
||||
m_online = online;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::gracefulShutdown()
|
||||
{
|
||||
this->pingDbClientService(CGlobalSetup::PingCompleteShutdown);
|
||||
this->quit();
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::pingDbClientService(CGlobalSetup::PingType type, bool force)
|
||||
{
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
if (!force && !this->isSwiftDbAccessible()) { return; }
|
||||
const CGlobalSetup gs = sApp->getGlobalSetup();
|
||||
const CUrl pingUrl = gs.getDbClientPingServiceUrl(type);
|
||||
sApp->getFromNetwork(pingUrl, { this, &CNetworkWatchdog::replyPingClientService });
|
||||
}
|
||||
|
||||
bool CNetworkWatchdog::disableNetworkAccessibilityCheck(bool disable)
|
||||
{
|
||||
if (disable == m_disableNetworkCheck) { return false; }
|
||||
m_disableNetworkCheck = disable;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::replyPingClientService(QNetworkReply *nwReply)
|
||||
{
|
||||
// init and clean up
|
||||
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nw(nwReply); // delete reply
|
||||
const bool ok = (nw->error() == QNetworkReply::NoError);
|
||||
const QString errorString = nw->errorString();
|
||||
const QString url = nw->url().toString();
|
||||
nw->close();
|
||||
|
||||
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||
Q_ASSERT_X(CThreadUtils::isInThisThread(this), Q_FUNC_INFO, "Wrong thread");
|
||||
|
||||
m_lastClientPingSuccess = ok;
|
||||
{
|
||||
QWriteLocker l(&m_lockUrl);
|
||||
m_lastPingUrl = url;
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
// be a little less verbose
|
||||
if ((m_totalGoodCountDb % 5 == 0) || m_consecutivePingBadCount > 0)
|
||||
{
|
||||
CLogMessage(this).info(u"Watchdog pinged '%1'") << url;
|
||||
}
|
||||
m_totalGoodCountDb++;
|
||||
m_consecutivePingBadCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_totalBadCountDb++;
|
||||
m_consecutivePingBadCount++;
|
||||
if (m_logOwnMessages)
|
||||
{
|
||||
CStatusMessage(this).warning(u"Watchdog ping failed, error: '%1', total good/bad DB counts: %2/%3") << errorString << m_totalGoodCountDb << m_totalBadCountDb;
|
||||
}
|
||||
}
|
||||
this->setDbAccessibility(ok);
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::triggerChangedSignals(bool oldDbAccessible, bool oldInternetAccessible)
|
||||
{
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
|
||||
if (oldDbAccessible != m_dbAccessible)
|
||||
{
|
||||
const CUrl testUrl(this->dbTestUrl());
|
||||
emit this->changedSwiftDbAccessibility(m_dbAccessible, testUrl);
|
||||
}
|
||||
if (oldInternetAccessible != m_internetAccessible)
|
||||
{
|
||||
emit this->changedInternetAccessibility(m_internetAccessible);
|
||||
}
|
||||
}
|
||||
|
||||
void CNetworkWatchdog::initWorkingSharedUrlFromSetup()
|
||||
{
|
||||
const CUrl workingUrl(CNetworkWatchdog::workingSharedUrlFromSetup()); // takes long
|
||||
this->setWorkingSharedUrl(workingUrl);
|
||||
}
|
||||
|
||||
CUrl CNetworkWatchdog::dbTestUrl()
|
||||
{
|
||||
// requires global setup to be read
|
||||
if (!sApp || sApp->isShuttingDown()) { return CUrl(); }
|
||||
const CUrl testUrl(sApp->getGlobalSetup().getDbHomePageUrl());
|
||||
return testUrl;
|
||||
}
|
||||
|
||||
CUrl CNetworkWatchdog::workingSharedUrlFromSetup()
|
||||
{
|
||||
const CUrlList urls(sApp->getGlobalSetup().getSwiftSharedUrls());
|
||||
CFailoverUrlList failoverUrls(urls);
|
||||
return failoverUrls.getRandomWorkingUrl(2, CanConnectTimeMs); // uses CNetworkUtils::canConnect
|
||||
}
|
||||
} // ns
|
||||
@@ -1,192 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_DB_NETWORKWATCHDOG_H
|
||||
#define BLACKCORE_DB_NETWORKWATCHDOG_H
|
||||
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/network/url.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/logcategories.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <QReadWriteLock>
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
namespace BlackCore::Db
|
||||
{
|
||||
//! Monitoring the swift DB, internet access, shared URLs
|
||||
class BLACKCORE_EXPORT CNetworkWatchdog : public BlackMisc::CContinuousWorker
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Log categories
|
||||
static const QStringList &getLogCategories();
|
||||
|
||||
//! Ctor
|
||||
explicit CNetworkWatchdog(bool networkAccessible, QObject *owner);
|
||||
|
||||
//! Network status changed, use this function to inform the watchdog
|
||||
//! \threadsafe
|
||||
void setNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessibility);
|
||||
|
||||
//! Configuration updates completed as reported by QNetworkConfigurationManager::updateCompleted
|
||||
void networkConfigurationsUpdateCompleted();
|
||||
|
||||
//! Set online as reported by QNetworkConfigurationManager::onlineStateChanged
|
||||
//! \threadsafe
|
||||
void setOnline(bool online);
|
||||
|
||||
//! DB available?
|
||||
//! \threadsafe
|
||||
bool isSwiftDbAccessible() const { return m_dbAccessible; }
|
||||
|
||||
//! Set DB as avialable (from external)
|
||||
//! \remark if data was read from DB, this can save another check
|
||||
//! \threadsafe
|
||||
void setDbAccessibility(bool accessible);
|
||||
|
||||
//! DB is accessible
|
||||
//! \threadsafe
|
||||
void setDbIsAccessible() { this->setDbAccessibility(true); }
|
||||
|
||||
//! DB is NOT accessible
|
||||
//! \threadsafe
|
||||
void setDbIsNotAccessible() { this->setDbAccessibility(false); }
|
||||
|
||||
//! Check the DB availability, can disable the check
|
||||
//! \threadsafe
|
||||
void setCheckDbAccessibility(bool check) { m_checkDbAccessibility = check; }
|
||||
|
||||
//! Check the shared URL, can disable the check
|
||||
//! \threadsafe
|
||||
void setCheckSharedUrl(bool check) { m_checkSharedUrl = check; }
|
||||
|
||||
//! Do a detailed check via HTTP
|
||||
//! \threadsafe
|
||||
void setDoDetailedCheck(bool check) { m_doDetailedCheck = check; }
|
||||
|
||||
//! Internet available?
|
||||
//! \threadsafe
|
||||
bool isInternetAccessible() const { return m_internetAccessible; }
|
||||
|
||||
//! Accesible or check disabled?
|
||||
bool isNetworkkAccessibleOrCheckDisabled() const { return m_networkAccessible || m_disableNetworkCheck; }
|
||||
|
||||
//! Has working shared URL?
|
||||
//! \threadsafe
|
||||
bool hasWorkingSharedUrl() const;
|
||||
|
||||
//! A working shared URL
|
||||
//! \threadsafe
|
||||
BlackMisc::Network::CUrl getWorkingSharedUrl() const;
|
||||
|
||||
//! Log.own status messages
|
||||
//! \threadsafe
|
||||
void setLogOwnMessages(bool log) { m_logOwnMessages = log; }
|
||||
|
||||
//! Run a check
|
||||
int triggerCheck();
|
||||
|
||||
//! Number of completed checks
|
||||
//! \threadsafe
|
||||
int getCheckCount() const { return m_totalCheckCount; }
|
||||
|
||||
//! Last URL used for ping /DB ping service)
|
||||
QString getLastPingDbUrl() const;
|
||||
|
||||
//! Number of completed checks
|
||||
//! \threadsafe
|
||||
QString getCheckInfo() const;
|
||||
|
||||
//! Set working URL from external
|
||||
//! \threadsafe
|
||||
void setWorkingSharedUrl(const BlackMisc::Network::CUrl &workingUrl);
|
||||
|
||||
//! Graceful shutdown
|
||||
void gracefulShutdown();
|
||||
|
||||
//! Ping the DB server, fire and forget (no feedback etc)
|
||||
void pingDbClientService(Data::CGlobalSetup::PingType type = Data::CGlobalSetup::PingUnspecific, bool force = false);
|
||||
|
||||
//! Disable the network check
|
||||
//! \remark if disabled network reports always accessible
|
||||
//! \threadsafe
|
||||
bool disableNetworkAccessibilityCheck(bool disable);
|
||||
|
||||
//! Has network check been disabled?
|
||||
//! \threadsafe
|
||||
bool isNetworkAccessibilityCheckDisabled() const { return m_disableNetworkCheck; }
|
||||
|
||||
//! Network check enabled?
|
||||
//! \threadsafe
|
||||
bool isNetworkAccessibilityCheckEnabled() const { return !this->isNetworkAccessibilityCheckDisabled(); }
|
||||
|
||||
//! The URL being tested
|
||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||
//! \private primarily accessible for unit tests
|
||||
static BlackMisc::Network::CUrl dbTestUrl();
|
||||
|
||||
signals:
|
||||
//! DB was available, but not longer is and vice versa
|
||||
void changedSwiftDbAccessibility(bool available, const BlackMisc::Network::CUrl &url);
|
||||
|
||||
//! Internet was available, but not longer is and vice versa
|
||||
void changedInternetAccessibility(bool available);
|
||||
|
||||
//! Cleaned version of QNetworkAccessManager::networkAccessibleChanged
|
||||
//! \remark does only fire if the accessibility changed
|
||||
void changedNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible);
|
||||
|
||||
private:
|
||||
static constexpr int CanConnectTimeMs = 5000;
|
||||
|
||||
//! Do work, i.e. check connectivity
|
||||
void doWork();
|
||||
|
||||
//! Do check
|
||||
bool doWorkCheck() const;
|
||||
|
||||
//! Trigger the changed signals and avoid unneccessary signals
|
||||
void triggerChangedSignals(bool oldDbAccessible, bool oldInternetAccessible);
|
||||
|
||||
//! Init a working shared URL
|
||||
void initWorkingSharedUrlFromSetup();
|
||||
|
||||
//! Received reply of client service ping
|
||||
void replyPingClientService(QNetworkReply *nwReply);
|
||||
|
||||
//! Obtain working DB data file location URL
|
||||
//! \remark depends on BlackCore::Application::getGlobalSetup()
|
||||
static BlackMisc::Network::CUrl workingSharedUrlFromSetup();
|
||||
|
||||
std::atomic_bool m_logOwnMessages { true };
|
||||
std::atomic_bool m_doDetailedCheck { true };
|
||||
std::atomic_bool m_networkAccessible { true };
|
||||
std::atomic_bool m_disableNetworkCheck { false }; //!< if this is true, network accessible always reports true/accessible
|
||||
std::atomic_bool m_online { true };
|
||||
std::atomic_bool m_internetAccessible { true };
|
||||
std::atomic_bool m_dbAccessible { true };
|
||||
std::atomic_bool m_lastClientPingSuccess { true }; //!< ping swift DB client service, real HTTP response
|
||||
std::atomic_bool m_checkDbAccessibility { true };
|
||||
std::atomic_bool m_checkSharedUrl { true };
|
||||
std::atomic_bool m_checkInProgress { false }; //!< a check is currently in progress
|
||||
std::atomic<qint64> m_nextPingSecsSinceEpoch { 0 }; //!< time at which next ping will be sent
|
||||
std::atomic_int m_networkAccessibility { QNetworkAccessManager::Accessible }; //!< last state
|
||||
std::atomic_int m_totalCheckCount { 0 }; //!< counting number of checks
|
||||
std::atomic_int m_totalBadCountDb { 0 }; //!< Total number of DB failing counts (only real responses when tried)
|
||||
std::atomic_int m_totalBadCountInternet { 0 }; //!< Total number of Internet failing count (only when network is accessible)
|
||||
std::atomic_int m_totalGoodCountDb { 0 };
|
||||
std::atomic_int m_totalGoodCountInternet { 0 };
|
||||
std::atomic_int m_consecutivePingBadCount { 0 }; //!< Bad count of ping until a godd state is received
|
||||
QString m_lastPingUrl;
|
||||
BlackMisc::Network::CUrl m_workingSharedUrl;
|
||||
mutable QReadWriteLock m_lockUrl;
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -61,16 +61,6 @@ namespace BlackCore
|
||||
return delta <= timeLastMs;
|
||||
}
|
||||
|
||||
bool CThreadedReader::isInternetAccessible(const QString &logWarningMessage) const
|
||||
{
|
||||
const bool a = sApp->isInternetAccessible();
|
||||
if (!a && !logWarningMessage.isEmpty())
|
||||
{
|
||||
CLogMessage(this).warning(logWarningMessage);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void CThreadedReader::startReader()
|
||||
{
|
||||
Q_ASSERT(m_initialTime > 0);
|
||||
|
||||
@@ -50,10 +50,6 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
bool updatedWithinLastMs(qint64 timeLastMs);
|
||||
|
||||
//! Network accessible?
|
||||
//! \param logWarningMessage optional warning if not accessible
|
||||
bool isInternetAccessible(const QString &logWarningMessage = {}) const;
|
||||
|
||||
//! Is marked as read failed
|
||||
//! \threadsafe
|
||||
//! \deprecated likely to be removed
|
||||
|
||||
@@ -172,7 +172,6 @@ namespace BlackCore::Vatsim
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM data file")) { return; }
|
||||
|
||||
// round robin for load balancing
|
||||
// remark: Don't use QThread to run network operations in the background
|
||||
|
||||
@@ -66,7 +66,6 @@ namespace BlackCore::Vatsim
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
if (!this->isInternetAccessible("No network/internet access, cannot read METARs")) { return; }
|
||||
|
||||
CFailoverUrlList urls(sApp->getVatsimMetarUrls());
|
||||
const CUrl url(urls.obtainNextWorkingUrl(true));
|
||||
|
||||
@@ -54,7 +54,6 @@ namespace BlackCore::Vatsim
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM server file")) { return; }
|
||||
|
||||
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
|
||||
const QUrl url = sApp->getVatsimServerFileUrl();
|
||||
|
||||
@@ -59,7 +59,6 @@ namespace BlackCore::Vatsim
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
if (!this->doWorkCheck()) { return; }
|
||||
if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM status file")) { return; }
|
||||
|
||||
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
|
||||
const CUrlList urls(sApp->getGlobalSetup().getVatsimStatusFileUrls());
|
||||
|
||||
@@ -282,11 +282,6 @@ namespace BlackCore
|
||||
{
|
||||
if (m_shuttingDown) { return CEntityFlags::NoEntity; }
|
||||
if (!sApp || sApp->isShuttingDown()) { return CEntityFlags::NoEntity; }
|
||||
if (!sApp->isSwiftDbAccessible())
|
||||
{
|
||||
CLogMessage(this).warning(u"Not triggering load of '%1' because swift DB is not accessible") << CEntityFlags::flagToString(whatToRead);
|
||||
return CEntityFlags::NoEntity;
|
||||
}
|
||||
|
||||
CEntityFlags::Entity triggeredRead = CEntityFlags::NoEntity;
|
||||
if (m_dbInfoDataReader)
|
||||
@@ -1013,20 +1008,10 @@ namespace BlackCore
|
||||
// 1a. If any DB data, read the info objects upfront
|
||||
if (needsDbInfoObjects)
|
||||
{
|
||||
const bool databaseUp = sApp->isSwiftDbAccessible();
|
||||
if (!databaseUp) { dbReaderConfig.markAsDbDown(); }
|
||||
|
||||
if (anyDbEntities && readersNeeded.testFlag(CWebReaderFlags::WebReaderFlag::DbInfoDataReader))
|
||||
{
|
||||
// info data reader has a special role, it will not be triggered in triggerRead()
|
||||
if (databaseUp)
|
||||
{
|
||||
this->initDbInfoObjectReaderAndTriggerRead();
|
||||
}
|
||||
else
|
||||
{
|
||||
CLogMessage(this).warning(u"DB unreachable, skipping read from DB info data reader");
|
||||
}
|
||||
this->initDbInfoObjectReaderAndTriggerRead();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,10 +205,9 @@ namespace BlackGui::Components
|
||||
ui->le_CategoriesSharedFileTs->setText(sharedFileTimestampForEntity(CEntityFlags::AircraftCategoryEntity));
|
||||
|
||||
// DB URL
|
||||
const QString dbUrlHtml("<img src=\"%1\"> <a href=\"%2\">%3</a>");
|
||||
const QString dbUrlHtml("<a href=\"%2\">%3</a>");
|
||||
const QString url = sGui->getGlobalSetup().getDbHomePageUrl().getFullUrl();
|
||||
bool canConnect = sGui->isSwiftDbAccessible();
|
||||
ui->lbl_DatabaseUrl->setText(dbUrlHtml.arg(canConnect ? m_imgOk : m_imgFailed, url, url));
|
||||
ui->lbl_DatabaseUrl->setText(dbUrlHtml.arg(url, url));
|
||||
ui->lbl_DatabaseUrl->setToolTip(url);
|
||||
|
||||
// Shared URLs
|
||||
@@ -378,9 +377,8 @@ namespace BlackGui::Components
|
||||
{
|
||||
direct = true;
|
||||
}
|
||||
else if (sGui->isSwiftDbAccessible())
|
||||
else
|
||||
{
|
||||
// do not trigger if cannot be connected
|
||||
sGui->getWebDataServices()->triggerReadOfDbInfoObjects();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ namespace BlackGui::Components
|
||||
{
|
||||
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::onSimulatorStatusChanged, Qt::QueuedConnection);
|
||||
connect(sGui->getIContextSimulator(), &IContextSimulator::modelSetChanged, this, &CInfoBarStatusComponent::onMapperReady);
|
||||
connect(sGui, &CGuiApplication::changedInternetAccessibility, this, &CInfoBarStatusComponent::onInternetAccessibleChanged);
|
||||
|
||||
// initial values
|
||||
this->onMapperReady();
|
||||
@@ -104,7 +103,6 @@ namespace BlackGui::Components
|
||||
shape = CLedWidget::Rounded;
|
||||
ui->led_Ptt->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Ptt", "Silence", 18);
|
||||
ui->led_Audio->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "On", "Muted", 18);
|
||||
this->onInternetAccessibleChanged(sGui->isInternetAccessible());
|
||||
}
|
||||
|
||||
void CInfoBarStatusComponent::adjustTextSize()
|
||||
@@ -289,20 +287,6 @@ namespace BlackGui::Components
|
||||
*/
|
||||
}
|
||||
|
||||
void CInfoBarStatusComponent::onInternetAccessibleChanged(bool access)
|
||||
{
|
||||
if (access)
|
||||
{
|
||||
ui->led_Network->setOffColor(CLedWidget::Black);
|
||||
ui->led_Network->setOffToolTip("Network disconnected");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->led_Network->setOffColor(CLedWidget::Red);
|
||||
ui->led_Network->setOffToolTip("No network/internet access");
|
||||
}
|
||||
}
|
||||
|
||||
void CInfoBarStatusComponent::updateValues()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
|
||||
@@ -98,9 +98,6 @@ namespace BlackGui::Components
|
||||
//! PTT, as received in in audio
|
||||
void onAudioPtt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier);
|
||||
|
||||
//! Internet accessible?
|
||||
void onInternetAccessibleChanged(bool access);
|
||||
|
||||
//! Update values
|
||||
void updateValues();
|
||||
|
||||
|
||||
@@ -28,11 +28,7 @@ namespace BlackGui::Components
|
||||
m_timer.setInterval(30 * 1000);
|
||||
m_timer.start();
|
||||
m_timer.setObjectName("CInfoBarWebReadersStatusBase::CheckSwiftDbTimer");
|
||||
bool c = connect(&m_timer, &QTimer::timeout, this, &CInfoBarWebReadersStatusBase::checkServerAndData);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect");
|
||||
c = connect(sGui, &CGuiApplication::changedInternetAccessibility, this, &CInfoBarWebReadersStatusBase::networkAccessibilityChanged);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect");
|
||||
c = connect(sGui, &CGuiApplication::changedSwiftDbAccessibility, this, &CInfoBarWebReadersStatusBase::dbAccessibilityChanged);
|
||||
bool c = connect(&m_timer, &QTimer::timeout, this, &CInfoBarWebReadersStatusBase::checkData);
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect");
|
||||
|
||||
if (sGui->hasWebDataServices())
|
||||
@@ -58,7 +54,6 @@ namespace BlackGui::Components
|
||||
void CInfoBarWebReadersStatusBase::initLeds()
|
||||
{
|
||||
CLedWidget::LedShape shape = CLedWidget::Rounded;
|
||||
m_ledSwiftDb->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "DB online", "DB offline", 14);
|
||||
m_ledDataReady->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "all data ready", "data missing", 14);
|
||||
if (m_ledConsolidation) { m_ledConsolidation->setValues(CLedWidget::Blue, CLedWidget::Black, shape, "consolidation running", "idle", 14); }
|
||||
|
||||
@@ -77,24 +72,8 @@ namespace BlackGui::Components
|
||||
if (!leds.isEmpty()) { this->setLedReadStates(leds, readState); }
|
||||
}
|
||||
|
||||
void CInfoBarWebReadersStatusBase::networkAccessibilityChanged(bool accessible)
|
||||
void CInfoBarWebReadersStatusBase::checkData()
|
||||
{
|
||||
Q_UNUSED(accessible);
|
||||
this->checkServerAndData();
|
||||
}
|
||||
|
||||
void CInfoBarWebReadersStatusBase::dbAccessibilityChanged(bool accessible, const CUrl &testedUrl)
|
||||
{
|
||||
Q_UNUSED(accessible);
|
||||
Q_UNUSED(testedUrl);
|
||||
this->checkServerAndData();
|
||||
}
|
||||
|
||||
void CInfoBarWebReadersStatusBase::checkServerAndData()
|
||||
{
|
||||
const bool swift = sGui && sGui->isSwiftDbAccessible();
|
||||
m_ledSwiftDb->setOn(swift);
|
||||
|
||||
const bool allData = hasAllData();
|
||||
m_ledDataReady->setOn(allData);
|
||||
}
|
||||
@@ -165,10 +144,9 @@ namespace BlackGui::Components
|
||||
}
|
||||
|
||||
void CInfoBarWebReadersStatusBase::setLeds(
|
||||
CLedWidget *ledDb, CLedWidget *ledDataReady, CLedWidget *ledConsolidation, CLedWidget *ledIcaoAircraft,
|
||||
CLedWidget *ledDataReady, CLedWidget *ledConsolidation, CLedWidget *ledIcaoAircraft,
|
||||
CLedWidget *ledIcaoAirline, CLedWidget *ledCountries, CLedWidget *ledDistributors, CLedWidget *ledLiveries, CLedWidget *ledModels)
|
||||
{
|
||||
m_ledSwiftDb = ledDb;
|
||||
m_ledDataReady = ledDataReady;
|
||||
m_ledConsolidation = ledConsolidation;
|
||||
m_ledIcaoAircraft = ledIcaoAircraft;
|
||||
@@ -182,7 +160,7 @@ namespace BlackGui::Components
|
||||
CInfoBarWebReadersStatusComponent::CInfoBarWebReadersStatusComponent(QWidget *parent) : CInfoBarWebReadersStatusBase(parent), ui(new Ui::CInfoBarWebReadersStatusComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setLeds(ui->led_SwiftDb, ui->led_DataReady, ui->led_Consolidation, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models);
|
||||
this->setLeds(ui->led_DataReady, ui->led_Consolidation, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models);
|
||||
this->init();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,28 +61,21 @@ namespace BlackGui
|
||||
bool hasAllData() const;
|
||||
|
||||
//! Initial setup of leds
|
||||
void setLeds(BlackGui::CLedWidget *ledDb, BlackGui::CLedWidget *ledDataReady, CLedWidget *ledConsolidation,
|
||||
void setLeds(BlackGui::CLedWidget *ledDataReady, CLedWidget *ledConsolidation,
|
||||
BlackGui::CLedWidget *ledIcaoAircraft, BlackGui::CLedWidget *ledIcaoAirline, BlackGui::CLedWidget *ledCountries,
|
||||
BlackGui::CLedWidget *ledDistributors, BlackGui::CLedWidget *ledLiveries, BlackGui::CLedWidget *ledModels);
|
||||
|
||||
//! Data have been read
|
||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Network::CEntityFlags::ReadState readState, int count);
|
||||
|
||||
//! Network accessibility changed
|
||||
void networkAccessibilityChanged(bool accessible);
|
||||
|
||||
//! DB accessibility changed
|
||||
void dbAccessibilityChanged(bool accessible, const BlackMisc::Network::CUrl &testedUrl);
|
||||
|
||||
//! Check server status
|
||||
void checkServerAndData();
|
||||
//! Check data status
|
||||
void checkData();
|
||||
|
||||
//! Show the consolidation status
|
||||
virtual void showConsolidationStatus(bool show);
|
||||
|
||||
private:
|
||||
QTimer m_timer; //!< check timer
|
||||
BlackGui::CLedWidget *m_ledSwiftDb = nullptr;
|
||||
BlackGui::CLedWidget *m_ledDataReady = nullptr;
|
||||
BlackGui::CLedWidget *m_ledConsolidation = nullptr;
|
||||
BlackGui::CLedWidget *m_ledIcaoAircraft = nullptr;
|
||||
|
||||
@@ -26,16 +26,6 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_SwiftDb">
|
||||
<property name="text">
|
||||
<string>swift DB</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::CLedWidget" name="led_SwiftDb" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_DataReady">
|
||||
<property name="toolTip">
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace BlackGui::Components
|
||||
ui(new Ui::CInfoBarWebReadersStatusSmallComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setLeds(ui->led_SwiftDb, ui->led_DataReady, nullptr, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models);
|
||||
this->setLeds(ui->led_DataReady, nullptr, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models);
|
||||
this->init();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "blackgui/registermetadata.h"
|
||||
#include "blackcore/context/contextnetwork.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/db/infodatareader.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackcore/setupreader.h"
|
||||
@@ -659,14 +658,8 @@ namespace BlackGui
|
||||
a = menu.addAction(CIcons::monitorError16(), "Network config. (console)");
|
||||
c = connect(a, &QAction::triggered, this, [=]() {
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
const QString r = CNetworkUtils::createNetworkConfigurationReport(this->getNetworkConfigurationManager(), this->getNetworkAccessManager());
|
||||
const QString r = CNetworkUtils::createNetworkAccessManagerReport(this->getNetworkAccessManager());
|
||||
this->displayTextInConsole(r);
|
||||
|
||||
if (this->getNetworkWatchdog())
|
||||
{
|
||||
const QString w = this->getNetworkWatchdog()->getCheckInfo();
|
||||
this->displayTextInConsole(w);
|
||||
}
|
||||
});
|
||||
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
|
||||
Q_UNUSED(c)
|
||||
|
||||
@@ -321,52 +321,6 @@ namespace BlackMisc::Network
|
||||
return msgs;
|
||||
}
|
||||
|
||||
QString CNetworkUtils::createNetworkConfigurationReport(const QNetworkConfigurationManager *qcm, const QNetworkAccessManager *qam, const QString &separator)
|
||||
{
|
||||
if (!qcm) { return QStringLiteral("No configuration manager"); }
|
||||
|
||||
static const QString empty;
|
||||
QString report;
|
||||
int c = 0;
|
||||
|
||||
int active = 0;
|
||||
int inActive = 0;
|
||||
int valid = 0;
|
||||
for (const QNetworkConfiguration &config : qcm->allConfigurations())
|
||||
{
|
||||
if (config.state() == QNetworkConfiguration::Active) { active++; }
|
||||
else { inActive++; }
|
||||
if (config.isValid()) { valid++; }
|
||||
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
QString::number(++c) % u": " %
|
||||
CNetworkUtils::networkConfigurationToString(config);
|
||||
}
|
||||
|
||||
if (c < 1)
|
||||
{
|
||||
report = QStringLiteral("No network configurations!");
|
||||
}
|
||||
else
|
||||
{
|
||||
static const QString count("Network configurations: active %1 / inactive %2 / valid %3");
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
count.arg(active).arg(inActive).arg(valid);
|
||||
}
|
||||
|
||||
if (qam)
|
||||
{
|
||||
report +=
|
||||
(report.isEmpty() ? empty : separator) %
|
||||
u"QAM: " %
|
||||
CNetworkUtils::createNetworkAccessManagerReport(qam);
|
||||
}
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
QString CNetworkUtils::createNetworkAccessManagerReport(const QNetworkAccessManager *qam)
|
||||
{
|
||||
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkConfigurationManager>
|
||||
#include <QNetworkConfiguration>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -132,9 +131,6 @@ namespace BlackMisc::Network
|
||||
//! \remark that can take a moment to complete, as it checks network
|
||||
static BlackMisc::CStatusMessageList createNetworkReport(const QUrl &url, const QNetworkAccessManager *qam = nullptr);
|
||||
|
||||
//! Info about network configurations
|
||||
static QString createNetworkConfigurationReport(const QNetworkConfigurationManager *qcm, const QNetworkAccessManager *qam, const QString &separator = "\n");
|
||||
|
||||
//! Report for QAM
|
||||
static QString createNetworkAccessManagerReport(const QNetworkAccessManager *qam);
|
||||
|
||||
|
||||
@@ -148,12 +148,6 @@ namespace BlackWxPlugin::Gfs
|
||||
m_maxRange = range;
|
||||
if (m_gribData.isEmpty())
|
||||
{
|
||||
if (!sApp || !sApp->isInternetAccessible())
|
||||
{
|
||||
CLogMessage(this).error(u"No weather download since network/internet not accessible");
|
||||
return;
|
||||
}
|
||||
|
||||
const QUrl url = getDownloadUrl().toQUrl();
|
||||
CLogMessage(this).debug() << "Started to download GFS data from" << url.toString();
|
||||
QNetworkRequest request(url);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//! \ingroup testblackcore
|
||||
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/setupreader.h"
|
||||
#include "blackmisc/applicationinfo.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
@@ -43,23 +42,11 @@ namespace BlackCoreTest
|
||||
|
||||
//! Ping test server
|
||||
void pingServer();
|
||||
|
||||
//! Test the watchdog BlackCore::Db::CNetworkWatchdog
|
||||
void testNetworkWatchdog();
|
||||
|
||||
private:
|
||||
int m_networkCheckCount = -1;
|
||||
};
|
||||
|
||||
void CTestConnectivity::initTestCase()
|
||||
{
|
||||
QVERIFY2(sApp, "sApp not available");
|
||||
QVERIFY2(sApp->getNetworkWatchdog(), "No network watchdog");
|
||||
|
||||
const int n = sApp->triggerNetworkWatchdogChecks();
|
||||
QVERIFY2(n >= 0, "Cannot trigger setup reader");
|
||||
m_networkCheckCount = n;
|
||||
qDebug() << "Initial network check count:" << n;
|
||||
}
|
||||
|
||||
void CTestConnectivity::checkSetupReader()
|
||||
@@ -101,20 +88,6 @@ namespace BlackCoreTest
|
||||
qDebug() << "Completed" << max << "ping tests in" << elapsedMs << "ms to" << url.getFullUrl();
|
||||
QVERIFY2(true, "pingServer");
|
||||
}
|
||||
|
||||
void CTestConnectivity::testNetworkWatchdog()
|
||||
{
|
||||
QVERIFY2(sApp->getNetworkWatchdog(), "No network watchdog");
|
||||
const CUrl dbUrl = CNetworkWatchdog::dbTestUrl();
|
||||
qDebug() << "Using DB test URL: " << dbUrl.toQString();
|
||||
const bool ok = canPing(dbUrl);
|
||||
if (!ok) { QSKIP(qPrintable("Cannot ping " + dbUrl.getFullUrl())); }
|
||||
|
||||
// only if URL is reachable
|
||||
QTRY_VERIFY2_WITH_TIMEOUT(sApp->isSwiftDbAccessible(), "Watchdog cannot connect db", 20000);
|
||||
QTRY_VERIFY2_WITH_TIMEOUT(sApp->getNetworkWatchdog()->getCheckCount() >= m_networkCheckCount + 1, "Timeout of network check", 30000);
|
||||
qDebug() << "Current network check count:" << sApp->getNetworkWatchdog()->getCheckCount();
|
||||
}
|
||||
} // ns
|
||||
|
||||
//! main
|
||||
|
||||
Reference in New Issue
Block a user