mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +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 "blackcore/application.h"
|
||||
#include "blackcore/db/networkwatchdog.h"
|
||||
#include "blackcore/context/contextapplication.h"
|
||||
#include "blackcore/cookiemanager.h"
|
||||
#include "blackcore/corefacade.h"
|
||||
@@ -139,25 +140,33 @@ namespace BlackCore
|
||||
QCoreApplication::instance()->installTranslator(&translator);
|
||||
|
||||
// Init network
|
||||
sApp = this;
|
||||
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_accessManager->setCookieJar(&m_cookieManager);
|
||||
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, this, &CApplication::networkAccessibleChanged, Qt::QueuedConnection);
|
||||
connect(&m_internetAccessTimer, &QTimer::timeout, this, [this] { this->checkInternetAccessible(true); });
|
||||
connect(m_accessManager, &QNetworkAccessManager::networkAccessibleChanged, this, &CApplication::changedInternetAccessibility, Qt::QueuedConnection);
|
||||
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));
|
||||
this->checkInternetAccessible();
|
||||
m_networkWatchDog->start(QThread::LowestPriority);
|
||||
m_networkWatchDog->startUpdating(10);
|
||||
|
||||
// global setup
|
||||
sApp = this;
|
||||
m_setupReader.reset(new CSetupReader(this));
|
||||
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted);
|
||||
connect(m_setupReader.data(), &CSetupReader::distributionInfoAvailable, this, &CApplication::distributionInfoAvailable);
|
||||
connect(m_setupReader.data(), &CSetupReader::setupHandlingCompleted, this, &CApplication::setupHandlingIsCompleted, Qt::QueuedConnection);
|
||||
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
|
||||
|
||||
// startup done
|
||||
connect(this, &CApplication::startUpCompleted, this, &CApplication::startupCompleted);
|
||||
connect(this, &CApplication::startUpCompleted, this, &CApplication::onStartUpCompleted, Qt::QueuedConnection);
|
||||
|
||||
// notify when app goes down
|
||||
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CApplication::gracefulShutdown);
|
||||
@@ -442,6 +451,7 @@ namespace BlackCore
|
||||
CWebDataServices *CApplication::getWebDataServices() const
|
||||
{
|
||||
// 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");
|
||||
return m_webDataServices.data();
|
||||
@@ -675,6 +685,17 @@ namespace BlackCore
|
||||
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
|
||||
{
|
||||
if (!m_accessManager) { return false; }
|
||||
@@ -687,7 +708,14 @@ namespace BlackCore
|
||||
|
||||
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
|
||||
@@ -702,6 +730,12 @@ namespace BlackCore
|
||||
return m_setupReader->getLastSuccessfulSetupUrl();
|
||||
}
|
||||
|
||||
CUrl CApplication::getWorkingSharedUrl() const
|
||||
{
|
||||
if (!m_networkWatchDog || !this->isNetworkAccessible()) { return CUrl(); }
|
||||
return m_networkWatchDog->getWorkingSharedUrl();
|
||||
}
|
||||
|
||||
QString CApplication::getLastSuccesfulDistributionUrl() const
|
||||
{
|
||||
if (!this->hasSetupReader()) { return ""; }
|
||||
@@ -798,6 +832,12 @@ namespace BlackCore
|
||||
m_webDataServices.reset(
|
||||
new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this)
|
||||
);
|
||||
|
||||
if (m_networkWatchDog)
|
||||
{
|
||||
connect(m_webDataServices.data(), &CWebDataServices::swiftDbDataRead, m_networkWatchDog.data(), &CNetworkWatchdog::setDbAccessibility);
|
||||
}
|
||||
|
||||
emit webDataServicesStarted(true);
|
||||
}
|
||||
else
|
||||
@@ -909,6 +949,12 @@ namespace BlackCore
|
||||
m_setupReader.reset();
|
||||
}
|
||||
|
||||
if (m_networkWatchDog)
|
||||
{
|
||||
m_networkWatchDog->quitAndWait();
|
||||
m_networkWatchDog.reset();
|
||||
}
|
||||
|
||||
m_fileLogger->close();
|
||||
}
|
||||
|
||||
@@ -929,12 +975,12 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CApplication::startupCompleted()
|
||||
void CApplication::onStartUpCompleted()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CApplication::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
void CApplication::onChangedNetworkAccessibility(QNetworkAccessManager::NetworkAccessibility accessible)
|
||||
{
|
||||
switch (accessible)
|
||||
{
|
||||
@@ -949,7 +995,30 @@ namespace BlackCore
|
||||
CLogMessage(this).warning("Network accessibility unknown");
|
||||
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()
|
||||
@@ -1345,7 +1414,7 @@ namespace BlackCore
|
||||
CNetworkUtils::ignoreSslVerification(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());
|
||||
|
||||
QNetworkReply *reply = requestOrPostMethod(*m_accessManager, copiedRequest);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "blackcore/webreaderflags.h"
|
||||
#include "blackmisc/db/distributionlist.h"
|
||||
#include "blackmisc/network/urllist.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/slot.h"
|
||||
#include "blackmisc/applicationinfolist.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
@@ -71,6 +72,7 @@ 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
|
||||
@@ -156,13 +158,27 @@ namespace BlackCore
|
||||
//! Delete all cookies from cookie manager
|
||||
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;
|
||||
|
||||
//! Internet accessible?
|
||||
//! \copydoc BlackCore::Db::CNetworkWatchdog::isInternetAccessible
|
||||
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
|
||||
//! \remark supposed to be used only in special cases
|
||||
const QNetworkAccessManager *getNetworkAccessManager() const { return m_accessManager; }
|
||||
|
||||
//! Setup reader?
|
||||
@@ -186,6 +202,7 @@ namespace BlackCore
|
||||
bool hasWebDataServices() const;
|
||||
|
||||
//! Get the web data services
|
||||
//! \remark use hasWebDataServices to test if services are available
|
||||
CWebDataServices *getWebDataServices() const;
|
||||
|
||||
//! Currently running in application thread?
|
||||
@@ -436,8 +453,11 @@ namespace BlackCore
|
||||
//! Web data services started
|
||||
void webDataServicesStarted(bool success);
|
||||
|
||||
//! Internet accessinility changed
|
||||
void internetAccessibleChanged(bool access);
|
||||
//! Internet accessibility changed
|
||||
void changedInternetAccessibility(bool accessible);
|
||||
|
||||
//! DB accessibility changed
|
||||
void changedSwiftDbAccessibility(bool accessible);
|
||||
|
||||
protected:
|
||||
//! Setup read/synchronized
|
||||
@@ -501,6 +521,15 @@ namespace BlackCore
|
||||
bool m_alreadyRunning = false; //!< Application already running
|
||||
|
||||
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
|
||||
void initLogging();
|
||||
|
||||
@@ -510,9 +539,6 @@ namespace BlackCore
|
||||
//! Dev.environment
|
||||
bool initIsRunningInDeveloperEnvironment() const;
|
||||
|
||||
//! Check that Internet is accessible
|
||||
void checkInternetAccessible(bool logWarning = true);
|
||||
|
||||
//! Async. start when setup is loaded
|
||||
BlackMisc::CStatusMessageList asyncWebAndContextStart();
|
||||
|
||||
@@ -529,22 +555,21 @@ namespace BlackCore
|
||||
QScopedPointer<CCoreFacade> m_coreFacade; //!< core facade if any
|
||||
QScopedPointer<CSetupReader> m_setupReader; //!< setup reader
|
||||
QScopedPointer<CWebDataServices> m_webDataServices; //!< web data services
|
||||
QScopedPointer<Db::CNetworkWatchdog> m_networkWatchDog; //!< checking DB/internet access
|
||||
QScopedPointer<BlackMisc::CFileLogger> m_fileLogger; //!< file logger
|
||||
CCookieManager m_cookieManager; //!< single cookie manager for our access manager
|
||||
QString m_applicationName; //!< application name
|
||||
QReadWriteLock m_accessManagerLock; //!< lock to make access manager access threadsafe
|
||||
CCoreFacadeConfig m_coreFacadeConfig; //!< Core facade config if any
|
||||
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?
|
||||
QTimer m_internetAccessTimer { this };
|
||||
bool m_useContexts = false; //!< use contexts
|
||||
bool m_useWebData = false; //!< use web data
|
||||
bool m_signalStartup = true; //!< signal startup automatically
|
||||
bool m_devEnv = false; //!< dev. environment
|
||||
bool m_unitTest = false; //!< is UNIT test
|
||||
bool m_autoSaveSettings = true; //!< automatically saving all settings
|
||||
bool m_internetAccessible = true; //!< Internet accessible
|
||||
|
||||
// -------------- crashpad -----------------
|
||||
BlackMisc::CStatusMessageList initCrashHandler();
|
||||
|
||||
Reference in New Issue
Block a user