refactor: Remove ecosystem provider from WebDataServices

Spreading the information about the ecosystem into all
"low-level" readers, just to deactivate them when not using
a non-VATSIM ecosystem, should be avoided. Instead, the readers
should be disabled entirely from the outside . This will be done
in a upcoming refactoring (separate PR).
This commit is contained in:
Lars Toenning
2024-03-11 19:10:50 +01:00
parent 73689efa01
commit 9cdd624ae0
8 changed files with 7 additions and 52 deletions

View File

@@ -50,8 +50,7 @@ using namespace BlackCore::Data;
namespace BlackCore::Vatsim namespace BlackCore::Vatsim
{ {
CVatsimDataFileReader::CVatsimDataFileReader(QObject *owner) : CThreadedReader(owner, "CVatsimDataFileReader"), CVatsimDataFileReader::CVatsimDataFileReader(QObject *owner) : CThreadedReader(owner, "CVatsimDataFileReader")
CEcosystemAware(CEcosystemAware::providerIfPossible(owner))
{ {
this->reloadSettings(); this->reloadSettings();
} }
@@ -174,7 +173,6 @@ namespace BlackCore::Vatsim
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM data file")) { return; } if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM data file")) { return; }
if (this->isNotVATSIMEcosystem()) { return; }
// round robin for load balancing // round robin for load balancing
// remark: Don't use QThread to run network operations in the background // remark: Don't use QThread to run network operations in the background
@@ -192,7 +190,6 @@ namespace BlackCore::Vatsim
// required to use delete later as object is created in a different thread // required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr); QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isNotVATSIMEcosystem()) { return; }
// Worker thread, make sure to write only synced here! // Worker thread, make sure to write only synced here!
if (!this->doWorkCheck()) if (!this->doWorkCheck())

View File

@@ -14,7 +14,6 @@
#include "blackmisc/aviation/callsignset.h" #include "blackmisc/aviation/callsignset.h"
#include "blackmisc/aviation/flightplan.h" #include "blackmisc/aviation/flightplan.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/ecosystemprovider.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/userlist.h" #include "blackmisc/network/userlist.h"
#include "blackmisc/network/voicecapabilities.h" #include "blackmisc/network/voicecapabilities.h"
@@ -37,8 +36,7 @@ namespace BlackCore::Vatsim
{ {
//! Read vatsim data file //! Read vatsim data file
class BLACKCORE_EXPORT CVatsimDataFileReader : class BLACKCORE_EXPORT CVatsimDataFileReader :
public CThreadedReader, public CThreadedReader
public BlackMisc::Network::CEcosystemAware
{ {
Q_OBJECT Q_OBJECT

View File

@@ -31,8 +31,7 @@ using namespace BlackCore::Data;
namespace BlackCore::Vatsim namespace BlackCore::Vatsim
{ {
CVatsimMetarReader::CVatsimMetarReader(QObject *owner) : CThreadedReader(owner, "CVatsimMetarReader"), CVatsimMetarReader::CVatsimMetarReader(QObject *owner) : CThreadedReader(owner, "CVatsimMetarReader")
CEcosystemAware(CEcosystemAware::providerIfPossible(owner))
{ {
this->reloadSettings(); this->reloadSettings();
} }
@@ -68,7 +67,6 @@ namespace BlackCore::Vatsim
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isInternetAccessible("No network/internet access, cannot read METARs")) { return; } if (!this->isInternetAccessible("No network/internet access, cannot read METARs")) { return; }
if (this->isNotVATSIMEcosystem()) { return; }
CFailoverUrlList urls(sApp->getVatsimMetarUrls()); CFailoverUrlList urls(sApp->getVatsimMetarUrls());
const CUrl url(urls.obtainNextWorkingUrl(true)); const CUrl url(urls.obtainNextWorkingUrl(true));
@@ -85,7 +83,6 @@ namespace BlackCore::Vatsim
// Worker thread, make sure to write thread safe! // Worker thread, make sure to write thread safe!
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isNotVATSIMEcosystem()) { return; }
if (!this->doWorkCheck()) if (!this->doWorkCheck())
{ {

View File

@@ -10,7 +10,6 @@
#include "blackmisc/weather/metar.h" #include "blackmisc/weather/metar.h"
#include "blackmisc/weather/metardecoder.h" #include "blackmisc/weather/metardecoder.h"
#include "blackmisc/weather/metarlist.h" #include "blackmisc/weather/metarlist.h"
#include "blackmisc/network/ecosystemprovider.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/aviation/airporticaocode.h" #include "blackmisc/aviation/airporticaocode.h"
#include "blackcore/threadedreader.h" #include "blackcore/threadedreader.h"
@@ -23,8 +22,7 @@ namespace BlackCore::Vatsim
{ {
//! Read METARs from VATSIM //! Read METARs from VATSIM
class BLACKCORE_EXPORT CVatsimMetarReader : class BLACKCORE_EXPORT CVatsimMetarReader :
public BlackCore::CThreadedReader, public BlackCore::CThreadedReader
public BlackMisc::Network::CEcosystemAware
{ {
Q_OBJECT Q_OBJECT

View File

@@ -28,8 +28,7 @@ using namespace BlackCore::Data;
namespace BlackCore::Vatsim namespace BlackCore::Vatsim
{ {
CVatsimServerFileReader::CVatsimServerFileReader(QObject *owner) : CThreadedReader(owner, "CVatsimServerFileReader"), CVatsimServerFileReader::CVatsimServerFileReader(QObject *owner) : CThreadedReader(owner, "CVatsimServerFileReader")
CEcosystemAware(CEcosystemAware::providerIfPossible(owner))
{} {}
CServerList CVatsimServerFileReader::getFsdServers() const CServerList CVatsimServerFileReader::getFsdServers() const
@@ -56,7 +55,6 @@ namespace BlackCore::Vatsim
this->threadAssertCheck(); this->threadAssertCheck();
if (!this->doWorkCheck()) { return; } if (!this->doWorkCheck()) { return; }
if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM server file")) { return; } if (!this->isInternetAccessible("No network/internet access, cannot read VATSIM server file")) { return; }
if (this->isNotVATSIMEcosystem()) { return; }
Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application"); Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing application");
const QUrl url = sApp->getVatsimServerFileUrl(); const QUrl url = sApp->getVatsimServerFileUrl();
@@ -70,7 +68,6 @@ namespace BlackCore::Vatsim
// required to use delete later as object is created in a different thread // required to use delete later as object is created in a different thread
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr); QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> nwReply(nwReplyPtr);
this->threadAssertCheck(); this->threadAssertCheck();
if (this->isNotVATSIMEcosystem()) { return; }
// Worker thread, make sure to write only synced here! // Worker thread, make sure to write only synced here!
if (!this->doWorkCheck()) if (!this->doWorkCheck())

View File

@@ -14,7 +14,6 @@
#include "blackmisc/aviation/callsignset.h" #include "blackmisc/aviation/callsignset.h"
#include "blackmisc/aviation/flightplan.h" #include "blackmisc/aviation/flightplan.h"
#include "blackmisc/network/entityflags.h" #include "blackmisc/network/entityflags.h"
#include "blackmisc/network/ecosystemprovider.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/userlist.h" #include "blackmisc/network/userlist.h"
#include "blackmisc/network/voicecapabilities.h" #include "blackmisc/network/voicecapabilities.h"
@@ -34,8 +33,7 @@ namespace BlackCore::Vatsim
//! Read VATSIM server file //! Read VATSIM server file
//! \sa https://data.vatsim.net/v3/vatsim-servers.json //! \sa https://data.vatsim.net/v3/vatsim-servers.json
class BLACKCORE_EXPORT CVatsimServerFileReader : class BLACKCORE_EXPORT CVatsimServerFileReader :
public CThreadedReader, public CThreadedReader
public BlackMisc::Network::CEcosystemAware
{ {
Q_OBJECT Q_OBJECT

View File

@@ -82,11 +82,6 @@ namespace BlackCore
this->initWriters(); this->initWriters();
} }
if (sApp)
{
connect(sApp, &CApplication::coreFacadeStarted, this, &CWebDataServices::onCoreFacadeStarted, Qt::QueuedConnection);
}
// make sure this is called in event queue, so pending tasks cam be performed // make sure this is called in event queue, so pending tasks cam be performed
entities &= ~CEntityFlags::DbInfoObjectEntity; // triggered in init readers entities &= ~CEntityFlags::DbInfoObjectEntity; // triggered in init readers
entities &= ~CEntityFlags::VatsimStatusFile; // triggered in init readers entities &= ~CEntityFlags::VatsimStatusFile; // triggered in init readers
@@ -1517,21 +1512,6 @@ namespace BlackCore
} }
} }
void CWebDataServices::onCoreFacadeStarted()
{
if (sApp && sApp->supportsContexts() && sApp->getIContextNetwork())
{
connect(sApp->getIContextNetwork(), &IContextNetwork::connectedServerChanged, this, &CWebDataServices::onConnectedNetworkServerChanged, Qt::QueuedConnection);
}
}
void CWebDataServices::onConnectedNetworkServerChanged(const CServer &server)
{
const CEcosystem es(server.getEcosystem());
this->setCurrentEcosystem(es);
CLogMessage(this).info(u"Changed data service ecosystem to '%1'") << es.toQString(true);
}
bool CWebDataServices::writeDbDataToDisk(const QString &dir) bool CWebDataServices::writeDbDataToDisk(const QString &dir)
{ {
if (dir.isEmpty()) { return false; } if (dir.isEmpty()) { return false; }

View File

@@ -19,7 +19,6 @@
#include "blackmisc/aviation/airporticaocode.h" #include "blackmisc/aviation/airporticaocode.h"
#include "blackmisc/aviation/atcstationlist.h" #include "blackmisc/aviation/atcstationlist.h"
#include "blackmisc/aviation/liverylist.h" #include "blackmisc/aviation/liverylist.h"
#include "blackmisc/network/ecosystemprovider.h"
#include "blackmisc/network/serverlist.h" #include "blackmisc/network/serverlist.h"
#include "blackmisc/network/urllist.h" #include "blackmisc/network/urllist.h"
#include "blackmisc/network/userlist.h" #include "blackmisc/network/userlist.h"
@@ -80,11 +79,9 @@ namespace BlackCore
* Encapsulates reading data from web sources * Encapsulates reading data from web sources
*/ */
class BLACKCORE_EXPORT CWebDataServices : class BLACKCORE_EXPORT CWebDataServices :
public QObject, public QObject
public BlackMisc::Network::IEcosystemProvider
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BlackMisc::Network::IEcosystemProvider)
public: public:
//! Log categories //! Log categories
@@ -604,13 +601,6 @@ namespace BlackCore
//! \return true means info objects available //! \return true means info objects available
bool waitForInfoObjectsThenRead(BlackMisc::Network::CEntityFlags::Entity entities, const QString &info, BlackCore::Db::CInfoDataReader *infoReader, QDateTime &timeOut); bool waitForInfoObjectsThenRead(BlackMisc::Network::CEntityFlags::Entity entities, const QString &info, BlackCore::Db::CInfoDataReader *infoReader, QDateTime &timeOut);
//! \copydoc BlackCore::CApplication::coreFacadeStarted
void onCoreFacadeStarted();
//! \copydoc BlackCore::Context::IContextNetwork::connectedServerChanged
//! \remark sets the ecosystem
void onConnectedNetworkServerChanged(const BlackMisc::Network::CServer &server);
BlackMisc::Network::CEntityFlags::Entity m_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities permanently updated by timers BlackMisc::Network::CEntityFlags::Entity m_entitiesPeriodicallyRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities permanently updated by timers
BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read BlackMisc::Network::CEntityFlags::Entity m_swiftDbEntitiesRead = BlackMisc::Network::CEntityFlags::NoEntity; //!< entities read
BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data BlackCore::Db::CDatabaseReaderConfigList m_dbReaderConfig; //!< how to read DB data