mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T150, use watchdog in application
* remove own checks * use watchdog * connect watchdog to other readers to avoid redundant checks
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a6855f1891
commit
b20c44a9f3
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "blackconfig/buildconfig.h"
|
#include "blackconfig/buildconfig.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
|
#include "blackcore/db/networkwatchdog.h"
|
||||||
#include "blackcore/context/contextapplication.h"
|
#include "blackcore/context/contextapplication.h"
|
||||||
#include "blackcore/cookiemanager.h"
|
#include "blackcore/cookiemanager.h"
|
||||||
#include "blackcore/corefacade.h"
|
#include "blackcore/corefacade.h"
|
||||||
@@ -139,25 +140,33 @@ namespace BlackCore
|
|||||||
QCoreApplication::instance()->installTranslator(&translator);
|
QCoreApplication::instance()->installTranslator(&translator);
|
||||||
|
|
||||||
// Init network
|
// Init network
|
||||||
|
sApp = this;
|
||||||
Q_ASSERT_X(m_accessManager, Q_FUNC_INFO, "Need QAM");
|
Q_ASSERT_X(m_accessManager, Q_FUNC_INFO, "Need QAM");
|
||||||
m_internetAccessTimer.setObjectName("Application::m_internetAccessTimer");
|
m_networkWatchDog.reset(new CNetworkWatchdog(this)); // not yet started
|
||||||
m_cookieManager.setParent(m_accessManager);
|
m_cookieManager.setParent(m_accessManager);
|
||||||
m_accessManager->setCookieJar(&m_cookieManager);
|
m_accessManager->setCookieJar(&m_cookieManager);
|
||||||
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, this, &CApplication::networkAccessibleChanged, Qt::QueuedConnection);
|
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, this, &CApplication::changedInternetAccessibility, Qt::QueuedConnection);
|
||||||
connect(&m_internetAccessTimer, &QTimer::timeout, this, [this] { this->checkInternetAccessible(true); });
|
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, this, &CApplication::onChangedNetworkAccessibility, Qt::QueuedConnection);
|
||||||
|
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, m_networkWatchDog.data(), &CNetworkWatchdog::onChangedNetworkAccessibility, Qt::QueuedConnection);
|
||||||
|
connect(m_networkWatchDog.data(), &CNetworkWatchdog::changedInternetAccessibility, this, &CApplication::onChangedInternetAccessibility, Qt::QueuedConnection);
|
||||||
|
connect(m_networkWatchDog.data(), &CNetworkWatchdog::changedSwiftDbAccessibility, this, &CApplication::onChangedSwiftDbAccessibility, Qt::QueuedConnection);
|
||||||
|
connect(m_networkWatchDog.data(), &CNetworkWatchdog::changedInternetAccessibility, this, &CApplication::changedInternetAccessibility, Qt::QueuedConnection);
|
||||||
|
connect(m_networkWatchDog.data(), &CNetworkWatchdog::changedSwiftDbAccessibility, this, &CApplication::changedSwiftDbAccessibility, Qt::QueuedConnection);
|
||||||
|
|
||||||
CLogMessage::preformatted(CNetworkUtils::createNetworkReport(m_accessManager));
|
CLogMessage::preformatted(CNetworkUtils::createNetworkReport(m_accessManager));
|
||||||
this->checkInternetAccessible();
|
m_networkWatchDog->start(QThread::LowestPriority);
|
||||||
|
m_networkWatchDog->startUpdating(10);
|
||||||
|
|
||||||
// global setup
|
// global setup
|
||||||
sApp = this;
|
|
||||||
m_setupReader.reset(new CSetupReader(this));
|
m_setupReader.reset(new CSetupReader(this));
|
||||||
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted);
|
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted, Qt::QueuedConnection);
|
||||||
connect(m_setupReader.data(), &CSetupReader::distributionInfoAvailable, this, &CApplication::distributionInfoAvailable);
|
connect(m_setupReader.data(), &CSetupReader::distributionInfoAvailable, this, &CApplication::distributionInfoAvailable, Qt::QueuedConnection);
|
||||||
|
connect(m_setupReader.data(), &CSetupReader::successfullyReadSharedUrl, m_networkWatchDog.data(), &CNetworkWatchdog::setWorkingSharedUrl, Qt::QueuedConnection);
|
||||||
|
|
||||||
m_parser.addOptions(m_setupReader->getCmdLineOptions()); // add options from reader
|
m_parser.addOptions(m_setupReader->getCmdLineOptions()); // add options from reader
|
||||||
|
|
||||||
// startup done
|
// startup done
|
||||||
connect(this, &CApplication::startUpCompleted, this, &CApplication::startupCompleted);
|
connect(this, &CApplication::startUpCompleted, this, &CApplication::onStartUpCompleted, Qt::QueuedConnection);
|
||||||
|
|
||||||
// notify when app goes down
|
// notify when app goes down
|
||||||
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CApplication::gracefulShutdown);
|
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CApplication::gracefulShutdown);
|
||||||
@@ -442,6 +451,7 @@ namespace BlackCore
|
|||||||
CWebDataServices *CApplication::getWebDataServices() const
|
CWebDataServices *CApplication::getWebDataServices() const
|
||||||
{
|
{
|
||||||
// use hasWebDataServices() to test if services are available
|
// use hasWebDataServices() to test if services are available
|
||||||
|
// getting the assert means web services are accessed before the are initialized
|
||||||
|
|
||||||
Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO, "Missing web data services, use hasWebDataServices to test if existing");
|
Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO, "Missing web data services, use hasWebDataServices to test if existing");
|
||||||
return m_webDataServices.data();
|
return m_webDataServices.data();
|
||||||
@@ -675,6 +685,17 @@ namespace BlackCore
|
|||||||
m_cookieManager.deleteAllCookies();
|
m_cookieManager.deleteAllCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CNetworkWatchdog *CApplication::getNetworkWatchdog() const
|
||||||
|
{
|
||||||
|
return m_networkWatchDog.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CApplication::triggerNetworkChecks()
|
||||||
|
{
|
||||||
|
if (!m_networkWatchDog) { return -1; }
|
||||||
|
return m_networkWatchDog->triggerCheck();
|
||||||
|
}
|
||||||
|
|
||||||
bool CApplication::isNetworkAccessible() const
|
bool CApplication::isNetworkAccessible() const
|
||||||
{
|
{
|
||||||
if (!m_accessManager) { return false; }
|
if (!m_accessManager) { return false; }
|
||||||
@@ -687,7 +708,14 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool CApplication::isInternetAccessible() const
|
bool CApplication::isInternetAccessible() const
|
||||||
{
|
{
|
||||||
return this->isNetworkAccessible() && m_internetAccessible;
|
if (!this->isNetworkAccessible()) { return false; }
|
||||||
|
return m_networkWatchDog && m_networkWatchDog->isInternetAccessible();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CApplication::isSwiftDbAccessible() const
|
||||||
|
{
|
||||||
|
if (!this->isNetworkAccessible()) { return false; }
|
||||||
|
return m_networkWatchDog && m_networkWatchDog->isSwiftDbAccessible();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::hasSetupReader() const
|
bool CApplication::hasSetupReader() const
|
||||||
@@ -702,6 +730,12 @@ namespace BlackCore
|
|||||||
return m_setupReader->getLastSuccessfulSetupUrl();
|
return m_setupReader->getLastSuccessfulSetupUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CUrl CApplication::getWorkingSharedUrl() const
|
||||||
|
{
|
||||||
|
if (!m_networkWatchDog || !this->isNetworkAccessible()) { return CUrl(); }
|
||||||
|
return m_networkWatchDog->getWorkingSharedUrl();
|
||||||
|
}
|
||||||
|
|
||||||
QString CApplication::getLastSuccesfulDistributionUrl() const
|
QString CApplication::getLastSuccesfulDistributionUrl() const
|
||||||
{
|
{
|
||||||
if (!this->hasSetupReader()) { return ""; }
|
if (!this->hasSetupReader()) { return ""; }
|
||||||
@@ -798,6 +832,12 @@ namespace BlackCore
|
|||||||
m_webDataServices.reset(
|
m_webDataServices.reset(
|
||||||
new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this)
|
new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (m_networkWatchDog)
|
||||||
|
{
|
||||||
|
connect(m_webDataServices.data(), &CWebDataServices::swiftDbDataRead, m_networkWatchDog.data(), &CNetworkWatchdog::setDbAccessibility);
|
||||||
|
}
|
||||||
|
|
||||||
emit webDataServicesStarted(true);
|
emit webDataServicesStarted(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -909,6 +949,12 @@ namespace BlackCore
|
|||||||
m_setupReader.reset();
|
m_setupReader.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_networkWatchDog)
|
||||||
|
{
|
||||||
|
m_networkWatchDog->quitAndWait();
|
||||||
|
m_networkWatchDog.reset();
|
||||||
|
}
|
||||||
|
|
||||||
m_fileLogger->close();
|
m_fileLogger->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -929,12 +975,12 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::startupCompleted()
|
void CApplication::onStartUpCompleted()
|
||||||
{
|
{
|
||||||
// void
|
// void
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible)
|
void CApplication::onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||||
{
|
{
|
||||||
switch (accessible)
|
switch (accessible)
|
||||||
{
|
{
|
||||||
@@ -949,7 +995,30 @@ namespace BlackCore
|
|||||||
CLogMessage(this).warning("Network accessibility unknown");
|
CLogMessage(this).warning("Network accessibility unknown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this->checkInternetAccessible();
|
}
|
||||||
|
|
||||||
|
void CApplication::onChangedInternetAccessibility(bool accessible)
|
||||||
|
{
|
||||||
|
if (accessible)
|
||||||
|
{
|
||||||
|
CLogMessage(this).info("Internet reported accessible");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("Internet not accessible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CApplication::onChangedSwiftDbAccessibility(bool accessible)
|
||||||
|
{
|
||||||
|
if (accessible)
|
||||||
|
{
|
||||||
|
CLogMessage(this).info("swift DB reported accessible");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("swift DB not accessible");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CStatusMessageList CApplication::asyncWebAndContextStart()
|
CStatusMessageList CApplication::asyncWebAndContextStart()
|
||||||
@@ -1345,7 +1414,7 @@ namespace BlackCore
|
|||||||
CNetworkUtils::ignoreSslVerification(copiedRequest);
|
CNetworkUtils::ignoreSslVerification(copiedRequest);
|
||||||
CNetworkUtils::setSwiftUserAgent(copiedRequest);
|
CNetworkUtils::setSwiftUserAgent(copiedRequest);
|
||||||
|
|
||||||
// If URL is one of the shared URLs, add swift client SSL certificate
|
// If URL is one of the shared URLs, add swift client SSL certificate to request
|
||||||
CNetworkUtils::setSwiftClientSslCertificate(copiedRequest, getGlobalSetup().getSwiftSharedUrls());
|
CNetworkUtils::setSwiftClientSslCertificate(copiedRequest, getGlobalSetup().getSwiftSharedUrls());
|
||||||
|
|
||||||
QNetworkReply *reply = requestOrPostMethod(*m_accessManager, copiedRequest);
|
QNetworkReply *reply = requestOrPostMethod(*m_accessManager, copiedRequest);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "blackcore/webreaderflags.h"
|
#include "blackcore/webreaderflags.h"
|
||||||
#include "blackmisc/db/distributionlist.h"
|
#include "blackmisc/db/distributionlist.h"
|
||||||
#include "blackmisc/network/urllist.h"
|
#include "blackmisc/network/urllist.h"
|
||||||
|
#include "blackmisc/network/networkutils.h"
|
||||||
#include "blackmisc/slot.h"
|
#include "blackmisc/slot.h"
|
||||||
#include "blackmisc/applicationinfolist.h"
|
#include "blackmisc/applicationinfolist.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
@@ -71,6 +72,7 @@ namespace BlackCore
|
|||||||
class IContextOwnAircraft;
|
class IContextOwnAircraft;
|
||||||
class IContextSimulator;
|
class IContextSimulator;
|
||||||
}
|
}
|
||||||
|
namespace Db { class CNetworkWatchdog; }
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Our runtime. Normally one instance is to be initialized at the beginning of main, and thereafter
|
* Our runtime. Normally one instance is to be initialized at the beginning of main, and thereafter
|
||||||
@@ -156,13 +158,27 @@ namespace BlackCore
|
|||||||
//! Delete all cookies from cookie manager
|
//! Delete all cookies from cookie manager
|
||||||
void deleteAllCookies();
|
void deleteAllCookies();
|
||||||
|
|
||||||
//! Network accessible?
|
//! Get the watchdog
|
||||||
|
//! \remark mostly for UNIT tests etc, normally not meant to be used directly
|
||||||
|
Db::CNetworkWatchdog *getNetworkWatchdog() const;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::Db::CNetworkWatchdog::triggerCheck
|
||||||
|
int triggerNetworkChecks();
|
||||||
|
|
||||||
|
//! Is network accessible
|
||||||
bool isNetworkAccessible() const;
|
bool isNetworkAccessible() const;
|
||||||
|
|
||||||
//! Internet accessible?
|
//! \copydoc BlackCore::Db::CNetworkWatchdog::isInternetAccessible
|
||||||
bool isInternetAccessible() const;
|
bool isInternetAccessible() const;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::Db::CNetworkWatchdog::isSwiftDbAccessible
|
||||||
|
bool isSwiftDbAccessible() const;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::Db::CNetworkWatchdog::getWorkingSharedUrl
|
||||||
|
BlackMisc::Network::CUrl getWorkingSharedUrl() const;
|
||||||
|
|
||||||
//! Access to access manager
|
//! Access to access manager
|
||||||
|
//! \remark supposed to be used only in special cases
|
||||||
const QNetworkAccessManager *getNetworkAccessManager() const { return m_accessManager; }
|
const QNetworkAccessManager *getNetworkAccessManager() const { return m_accessManager; }
|
||||||
|
|
||||||
//! Setup reader?
|
//! Setup reader?
|
||||||
@@ -186,6 +202,7 @@ namespace BlackCore
|
|||||||
bool hasWebDataServices() const;
|
bool hasWebDataServices() const;
|
||||||
|
|
||||||
//! Get the web data services
|
//! Get the web data services
|
||||||
|
//! \remark use hasWebDataServices to test if services are available
|
||||||
CWebDataServices *getWebDataServices() const;
|
CWebDataServices *getWebDataServices() const;
|
||||||
|
|
||||||
//! Currently running in application thread?
|
//! Currently running in application thread?
|
||||||
@@ -436,8 +453,11 @@ namespace BlackCore
|
|||||||
//! Web data services started
|
//! Web data services started
|
||||||
void webDataServicesStarted(bool success);
|
void webDataServicesStarted(bool success);
|
||||||
|
|
||||||
//! Internet accessinility changed
|
//! Internet accessibility changed
|
||||||
void internetAccessibleChanged(bool access);
|
void changedInternetAccessibility(bool accessible);
|
||||||
|
|
||||||
|
//! DB accessibility changed
|
||||||
|
void changedSwiftDbAccessibility(bool accessible);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Setup read/synchronized
|
//! Setup read/synchronized
|
||||||
@@ -501,6 +521,15 @@ namespace BlackCore
|
|||||||
bool m_alreadyRunning = false; //!< Application already running
|
bool m_alreadyRunning = false; //!< Application already running
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! 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);
|
||||||
|
|
||||||
//! init logging system
|
//! init logging system
|
||||||
void initLogging();
|
void initLogging();
|
||||||
|
|
||||||
@@ -510,9 +539,6 @@ namespace BlackCore
|
|||||||
//! Dev.environment
|
//! Dev.environment
|
||||||
bool initIsRunningInDeveloperEnvironment() const;
|
bool initIsRunningInDeveloperEnvironment() const;
|
||||||
|
|
||||||
//! Check that Internet is accessible
|
|
||||||
void checkInternetAccessible(bool logWarning = true);
|
|
||||||
|
|
||||||
//! Async. start when setup is loaded
|
//! Async. start when setup is loaded
|
||||||
BlackMisc::CStatusMessageList asyncWebAndContextStart();
|
BlackMisc::CStatusMessageList asyncWebAndContextStart();
|
||||||
|
|
||||||
@@ -529,22 +555,21 @@ namespace BlackCore
|
|||||||
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
|
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
|
||||||
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
|
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
|
||||||
QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services
|
QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services
|
||||||
|
QScopedPointer<Db::CNetworkWatchdog> m_networkWatchDog; //!< checking DB/internet access
|
||||||
QScopedPointer<BlackMisc::CFileLogger> m_fileLogger; //!< file logger
|
QScopedPointer<BlackMisc::CFileLogger> m_fileLogger; //!< file logger
|
||||||
CCookieManager m_cookieManager; //!< single cookie manager for our access manager
|
CCookieManager m_cookieManager; //!< single cookie manager for our access manager
|
||||||
QString m_applicationName; //!< application name
|
QString m_applicationName; //!< application name
|
||||||
QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe
|
QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe
|
||||||
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
||||||
CWebReaderFlags::WebReader m_webReadersUsed; //!< Readers to be used
|
CWebReaderFlags::WebReader m_webReadersUsed; //!< Readers to be used
|
||||||
BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< Load or used caching?
|
Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< Load or used caching?
|
||||||
std::atomic<bool> m_shutdown { false }; //!< is being shutdown?
|
std::atomic<bool> m_shutdown { false }; //!< is being shutdown?
|
||||||
QTimer m_internetAccessTimer { this };
|
|
||||||
bool m_useContexts = false; //!< use contexts
|
bool m_useContexts = false; //!< use contexts
|
||||||
bool m_useWebData = false; //!< use web data
|
bool m_useWebData = false; //!< use web data
|
||||||
bool m_signalStartup = true; //!< signal startup automatically
|
bool m_signalStartup = true; //!< signal startup automatically
|
||||||
bool m_devEnv = false; //!< dev. environment
|
bool m_devEnv = false; //!< dev. environment
|
||||||
bool m_unitTest = false; //!< is UNIT test
|
bool m_unitTest = false; //!< is UNIT test
|
||||||
bool m_autoSaveSettings = true; //!< automatically saving all settings
|
bool m_autoSaveSettings = true; //!< automatically saving all settings
|
||||||
bool m_internetAccessible = true; //!< Internet accessible
|
|
||||||
|
|
||||||
// -------------- crashpad -----------------
|
// -------------- crashpad -----------------
|
||||||
BlackMisc::CStatusMessageList initCrashHandler();
|
BlackMisc::CStatusMessageList initCrashHandler();
|
||||||
|
|||||||
Reference in New Issue
Block a user