diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 47ec09d33..dacc1899e 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -8,6 +8,7 @@ */ #include "airspacemonitor.h" +#include "blackcore/application.h" #include "blackcore/registermetadata.h" #include "blackcore/webdataservices.h" #include "blackcore/vatsimbookingreader.h" @@ -31,10 +32,9 @@ using namespace BlackMisc::Weather; namespace BlackCore { - CAirspaceMonitor::CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, INetwork *network, CWebDataServices *webDataReader, QObject *parent) + CAirspaceMonitor::CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, INetwork *network, QObject *parent) : QObject(parent), COwnAircraftAware(ownAircraftProvider), - CWebDataServicesAware(webDataReader), m_network(network), m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this)) { @@ -61,12 +61,9 @@ namespace BlackCore this->connect(&m_interimPositionUpdateTimer, &QTimer::timeout, this, &CAirspaceMonitor::ps_sendInterimPositions); // AutoConnection: this should also avoid race conditions by updating the bookings - Q_ASSERT_X(webDataReader, Q_FUNC_INFO, "Missing data reader"); - if (webDataReader) - { - this->connect(webDataReader->getBookingReader(), &CVatsimBookingReader::atcBookingsRead, this, &CAirspaceMonitor::ps_receivedBookings); - this->connect(webDataReader->getDataFileReader(), &CVatsimDataFileReader::dataFileRead, this, &CAirspaceMonitor::ps_receivedDataFile); - } + Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader"); + this->connect(sApp->getWebDataServices()->getBookingReader(), &CVatsimBookingReader::atcBookingsRead, this, &CAirspaceMonitor::ps_receivedBookings); + this->connect(sApp->getWebDataServices()->getDataFileReader(), &CVatsimDataFileReader::dataFileRead, this, &CAirspaceMonitor::ps_receivedDataFile); // Force snapshot in the main event loop this->connect(this->m_analyzer, &CAirspaceAnalyzer::airspaceAircraftSnapshot, this, &CAirspaceMonitor::airspaceAircraftSnapshot, Qt::QueuedConnection); @@ -305,7 +302,7 @@ namespace BlackCore // those are the ones not in range for (const CCallsign &callsign : searchList) { - CUserList usersByCallsign = this->getUsersForCallsign(callsign); + CUserList usersByCallsign = sApp->getWebDataServices()->getUsersForCallsign(callsign); if (usersByCallsign.isEmpty()) { CUser user; @@ -453,7 +450,7 @@ namespace BlackCore } // Client - CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign); + const CVoiceCapabilities caps = sApp->getWebDataServices()->getVoiceCapabilityForCallsign(callsign); vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname); vm.addValue({ CClient::IndexVoiceCapabilities }, caps); if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); } @@ -470,7 +467,7 @@ namespace BlackCore capabilities.addValue(CClient::FsdWithAircraftConfig, (flags & INetwork::SupportsAircraftConfigs)); CPropertyIndexVariantMap vm(CClient::IndexCapabilities, CVariant::from(capabilities)); - CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign); + const CVoiceCapabilities caps = sApp->getWebDataServices()->getVoiceCapabilityForCallsign(callsign); vm.addValue({CClient::IndexVoiceCapabilities}, caps); if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); } this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm); @@ -569,7 +566,7 @@ namespace BlackCore for (auto client = this->m_otherClients.begin(); client != this->m_otherClients.end(); ++client) { if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps - CVoiceCapabilities vc = this->getVoiceCapabilityForCallsign(client->getCallsign()); + const CVoiceCapabilities vc = sApp->getWebDataServices()->getVoiceCapabilityForCallsign(client->getCallsign()); if (vc.isUnknown()) { continue; } client->setVoiceCapabilities(vc); } @@ -630,7 +627,7 @@ namespace BlackCore if (stationsWithCallsign.isEmpty()) { // new station, init with data from data file - CAtcStation station(this->getAtcStationsForCallsign(callsign).frontOrDefault()); + CAtcStation station(sApp->getWebDataServices()->getAtcStationsForCallsign(callsign).frontOrDefault()); station.setCallsign(callsign); station.setRange(range); station.setFrequency(frequency); @@ -820,8 +817,12 @@ namespace BlackCore if (model.hasModelString()) { // if we find the model here we have a fully defined DB model - CAircraftModel modelFromDb(this->getModelForModelString(model.getModelString())); - if (modelFromDb.hasValidDbKey()) { model = modelFromDb; } + const CAircraftModel modelFromDb(sApp->getWebDataServices()->getModelForModelString(model.getModelString())); + if (modelFromDb.hasValidDbKey()) + { + model = modelFromDb; + this->logMatching(QString("Reverse looked up DB model `%1` for %2").arg(modelFromDb.getDbKey()).arg(callsign.toQString())); + } } // only if not yet matched with DB @@ -831,11 +832,11 @@ namespace BlackCore if (CLivery::isValidCombinedCode(livery)) { // search DB model by livery - CAircraftModelList models(this->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery)); + const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery)); if (models.isEmpty()) { // no models for that livery, search for livery only - CLivery databaseLivery(this->getLiveryForCombinedCode(livery)); + const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(livery)); if (databaseLivery.hasValidDbKey()) { // we have found a livery in the DB @@ -853,7 +854,7 @@ namespace BlackCore if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey()) { // create a pseudo livery, try to find airline first - CAirlineIcaoCode airlineIcao(this->smartAirlineIcaoSelector(CAirlineIcaoCode(airlineIcaoDesignator))); + CAirlineIcaoCode airlineIcao(sApp->getWebDataServices()->smartAirlineIcaoSelector(CAirlineIcaoCode(airlineIcaoDesignator))); if (!airlineIcao.hasValidDbKey()) { // no DB data, we update as much as possible @@ -866,7 +867,7 @@ namespace BlackCore if (!model.getAircraftIcaoCode().hasValidDbKey()) { - CAircraftIcaoCode aircraftIcao(this->getAircraftIcaoCodeForDesignator(aircraftIcaoDesignator)); + CAircraftIcaoCode aircraftIcao(sApp->getWebDataServices()->getAircraftIcaoCodeForDesignator(aircraftIcaoDesignator)); if (!aircraftIcao.hasValidDbKey()) { // no DB data, we update as much as possible @@ -913,7 +914,7 @@ namespace BlackCore aircraft.setSituation(situation); aircraft.setTransponder(transponder); aircraft.calculcateDistanceAndBearingToOwnAircraft(getOwnAircraftPosition()); // distance from myself - this->updateWithVatsimDataFileData(aircraft); + sApp->getWebDataServices()->updateWithVatsimDataFileData(aircraft); // ICAO from cache if avialable bool setModelFromCache = false; diff --git a/src/blackcore/airspacemonitor.h b/src/blackcore/airspacemonitor.h index 4a6300180..8ca8c0cc9 100644 --- a/src/blackcore/airspacemonitor.h +++ b/src/blackcore/airspacemonitor.h @@ -37,15 +37,14 @@ namespace BlackCore class BLACKCORE_EXPORT CAirspaceMonitor : public QObject, public BlackMisc::Simulation::IRemoteAircraftProvider, // those data will be provided from the class CAirspaceMonitor - public BlackMisc::Simulation::COwnAircraftAware, // used to obtain in memory information about own aircraft - public BlackMisc::Network::CWebDataServicesAware // used to get web service data + public BlackMisc::Simulation::COwnAircraftAware // used to obtain in memory information about own aircraft { Q_OBJECT Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider) public: //! Constructor - CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, INetwork *network, CWebDataServices *webDataReader, QObject *parent); + CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, INetwork *network, QObject *parent); //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRange //! \ingroup remoteaircraftprovider diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 0b58fb760..46090181c 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -19,6 +19,7 @@ #include "blackmisc/dbusserver.h" #include "blackmisc/registermetadata.h" #include "blackmisc/network/networkutils.h" +#include "blackmisc/verify.h" #include #include #include @@ -26,6 +27,9 @@ using namespace BlackMisc; using namespace BlackMisc::Network; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; +using namespace BlackMisc::Weather; using namespace BlackCore; BlackCore::CApplication *sApp = nullptr; // set by constructor @@ -576,7 +580,4 @@ namespace BlackCore if (!supportsContexts()) { return nullptr; } return this->m_coreFacade->getIContextSimulator(); } - - // --------------------------------------------------------------------------------- - } // ns diff --git a/src/blackcore/application.h b/src/blackcore/application.h index cd5c0604a..acb2acba8 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -14,7 +14,7 @@ #include "corefacadeconfig.h" #include "cookiemanager.h" -#include "webreaderflags.h" +#include "webdataservices.h" #include "blackmisc/network/url.h" #include "blackmisc/logcategorylist.h" #include "blackmisc/filelogger.h" @@ -30,7 +30,6 @@ namespace BlackCore { class CCoreFacade; class CSetupReader; - class CWebDataServices; class IContextApplication; class IContextAudio; diff --git a/src/blackcore/contextnetworkimpl.cpp b/src/blackcore/contextnetworkimpl.cpp index b980597c8..8dd00561b 100644 --- a/src/blackcore/contextnetworkimpl.cpp +++ b/src/blackcore/contextnetworkimpl.cpp @@ -67,7 +67,7 @@ namespace BlackCore // 4. Airspace contents Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local"); - this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, sApp->getWebDataServices(), this); + this->m_airspace = new CAirspaceMonitor(this->getRuntime()->getCContextOwnAircraft(), this->m_network, this); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); @@ -632,7 +632,7 @@ namespace BlackCore CMetar CContextNetwork::getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const { if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << airportIcaoCode; } - return m_airspace->getMetarForAirport(airportIcaoCode); + return sApp->getWebDataServices()->getMetarForAirport(airportIcaoCode); } CAtcStationList CContextNetwork::getSelectedAtcStations() const