refs #602, directly web access via application

* delegating functions
* removed from airspace monitor
This commit is contained in:
Klaus Basan
2016-02-24 04:21:59 +01:00
committed by Mathew Sutcliffe
parent 8a7eba74d9
commit a0cfa2e687
5 changed files with 30 additions and 30 deletions

View File

@@ -8,6 +8,7 @@
*/ */
#include "airspacemonitor.h" #include "airspacemonitor.h"
#include "blackcore/application.h"
#include "blackcore/registermetadata.h" #include "blackcore/registermetadata.h"
#include "blackcore/webdataservices.h" #include "blackcore/webdataservices.h"
#include "blackcore/vatsimbookingreader.h" #include "blackcore/vatsimbookingreader.h"
@@ -31,10 +32,9 @@ using namespace BlackMisc::Weather;
namespace BlackCore 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), : QObject(parent),
COwnAircraftAware(ownAircraftProvider), COwnAircraftAware(ownAircraftProvider),
CWebDataServicesAware(webDataReader),
m_network(network), m_network(network),
m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this)) m_analyzer(new CAirspaceAnalyzer(ownAircraftProvider, this, network, this))
{ {
@@ -61,12 +61,9 @@ namespace BlackCore
this->connect(&m_interimPositionUpdateTimer, &QTimer::timeout, this, &CAirspaceMonitor::ps_sendInterimPositions); this->connect(&m_interimPositionUpdateTimer, &QTimer::timeout, this, &CAirspaceMonitor::ps_sendInterimPositions);
// AutoConnection: this should also avoid race conditions by updating the bookings // AutoConnection: this should also avoid race conditions by updating the bookings
Q_ASSERT_X(webDataReader, Q_FUNC_INFO, "Missing data reader"); Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "Missing data reader");
if (webDataReader) this->connect(sApp->getWebDataServices()->getBookingReader(), &CVatsimBookingReader::atcBookingsRead, this, &CAirspaceMonitor::ps_receivedBookings);
{ this->connect(sApp->getWebDataServices()->getDataFileReader(), &CVatsimDataFileReader::dataFileRead, this, &CAirspaceMonitor::ps_receivedDataFile);
this->connect(webDataReader->getBookingReader(), &CVatsimBookingReader::atcBookingsRead, this, &CAirspaceMonitor::ps_receivedBookings);
this->connect(webDataReader->getDataFileReader(), &CVatsimDataFileReader::dataFileRead, this, &CAirspaceMonitor::ps_receivedDataFile);
}
// Force snapshot in the main event loop // Force snapshot in the main event loop
this->connect(this->m_analyzer, &CAirspaceAnalyzer::airspaceAircraftSnapshot, this, &CAirspaceMonitor::airspaceAircraftSnapshot, Qt::QueuedConnection); 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 // those are the ones not in range
for (const CCallsign &callsign : searchList) for (const CCallsign &callsign : searchList)
{ {
CUserList usersByCallsign = this->getUsersForCallsign(callsign); CUserList usersByCallsign = sApp->getWebDataServices()->getUsersForCallsign(callsign);
if (usersByCallsign.isEmpty()) if (usersByCallsign.isEmpty())
{ {
CUser user; CUser user;
@@ -453,7 +450,7 @@ namespace BlackCore
} }
// Client // Client
CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign); const CVoiceCapabilities caps = sApp->getWebDataServices()->getVoiceCapabilityForCallsign(callsign);
vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname); vm = CPropertyIndexVariantMap({CClient::IndexUser, CUser::IndexRealName}, realname);
vm.addValue({ CClient::IndexVoiceCapabilities }, caps); vm.addValue({ CClient::IndexVoiceCapabilities }, caps);
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); } 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)); capabilities.addValue(CClient::FsdWithAircraftConfig, (flags & INetwork::SupportsAircraftConfigs));
CPropertyIndexVariantMap vm(CClient::IndexCapabilities, CVariant::from(capabilities)); CPropertyIndexVariantMap vm(CClient::IndexCapabilities, CVariant::from(capabilities));
CVoiceCapabilities caps = this->getVoiceCapabilityForCallsign(callsign); const CVoiceCapabilities caps = sApp->getWebDataServices()->getVoiceCapabilityForCallsign(callsign);
vm.addValue({CClient::IndexVoiceCapabilities}, caps); vm.addValue({CClient::IndexVoiceCapabilities}, caps);
if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); } if (!this->m_otherClients.containsCallsign(callsign)) { this->m_otherClients.push_back(CClient(callsign)); }
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm); 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) for (auto client = this->m_otherClients.begin(); client != this->m_otherClients.end(); ++client)
{ {
if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps 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; } if (vc.isUnknown()) { continue; }
client->setVoiceCapabilities(vc); client->setVoiceCapabilities(vc);
} }
@@ -630,7 +627,7 @@ namespace BlackCore
if (stationsWithCallsign.isEmpty()) if (stationsWithCallsign.isEmpty())
{ {
// new station, init with data from data file // 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.setCallsign(callsign);
station.setRange(range); station.setRange(range);
station.setFrequency(frequency); station.setFrequency(frequency);
@@ -820,8 +817,12 @@ namespace BlackCore
if (model.hasModelString()) if (model.hasModelString())
{ {
// if we find the model here we have a fully defined DB model // if we find the model here we have a fully defined DB model
CAircraftModel modelFromDb(this->getModelForModelString(model.getModelString())); const CAircraftModel modelFromDb(sApp->getWebDataServices()->getModelForModelString(model.getModelString()));
if (modelFromDb.hasValidDbKey()) { model = modelFromDb; } 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 // only if not yet matched with DB
@@ -831,11 +832,11 @@ namespace BlackCore
if (CLivery::isValidCombinedCode(livery)) if (CLivery::isValidCombinedCode(livery))
{ {
// search DB model by livery // search DB model by livery
CAircraftModelList models(this->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery)); const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoDesignator, livery));
if (models.isEmpty()) if (models.isEmpty())
{ {
// no models for that livery, search for livery only // no models for that livery, search for livery only
CLivery databaseLivery(this->getLiveryForCombinedCode(livery)); const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(livery));
if (databaseLivery.hasValidDbKey()) if (databaseLivery.hasValidDbKey())
{ {
// we have found a livery in the DB // we have found a livery in the DB
@@ -853,7 +854,7 @@ namespace BlackCore
if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey()) if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey())
{ {
// create a pseudo livery, try to find airline first // 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()) if (!airlineIcao.hasValidDbKey())
{ {
// no DB data, we update as much as possible // no DB data, we update as much as possible
@@ -866,7 +867,7 @@ namespace BlackCore
if (!model.getAircraftIcaoCode().hasValidDbKey()) if (!model.getAircraftIcaoCode().hasValidDbKey())
{ {
CAircraftIcaoCode aircraftIcao(this->getAircraftIcaoCodeForDesignator(aircraftIcaoDesignator)); CAircraftIcaoCode aircraftIcao(sApp->getWebDataServices()->getAircraftIcaoCodeForDesignator(aircraftIcaoDesignator));
if (!aircraftIcao.hasValidDbKey()) if (!aircraftIcao.hasValidDbKey())
{ {
// no DB data, we update as much as possible // no DB data, we update as much as possible
@@ -913,7 +914,7 @@ namespace BlackCore
aircraft.setSituation(situation); aircraft.setSituation(situation);
aircraft.setTransponder(transponder); aircraft.setTransponder(transponder);
aircraft.calculcateDistanceAndBearingToOwnAircraft(getOwnAircraftPosition()); // distance from myself aircraft.calculcateDistanceAndBearingToOwnAircraft(getOwnAircraftPosition()); // distance from myself
this->updateWithVatsimDataFileData(aircraft); sApp->getWebDataServices()->updateWithVatsimDataFileData(aircraft);
// ICAO from cache if avialable // ICAO from cache if avialable
bool setModelFromCache = false; bool setModelFromCache = false;

View File

@@ -37,15 +37,14 @@ namespace BlackCore
class BLACKCORE_EXPORT CAirspaceMonitor : class BLACKCORE_EXPORT CAirspaceMonitor :
public QObject, public QObject,
public BlackMisc::Simulation::IRemoteAircraftProvider, // those data will be provided from the class CAirspaceMonitor 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::Simulation::COwnAircraftAware // used to obtain in memory information about own aircraft
public BlackMisc::Network::CWebDataServicesAware // used to get web service data
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider) Q_INTERFACES(BlackMisc::Simulation::IRemoteAircraftProvider)
public: public:
//! Constructor //! 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 //! \copydoc BlackMisc::Simulation::IRemoteAircraftProvider::getAircraftInRange
//! \ingroup remoteaircraftprovider //! \ingroup remoteaircraftprovider

View File

@@ -19,6 +19,7 @@
#include "blackmisc/dbusserver.h" #include "blackmisc/dbusserver.h"
#include "blackmisc/registermetadata.h" #include "blackmisc/registermetadata.h"
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/verify.h"
#include <QStandardPaths> #include <QStandardPaths>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
@@ -26,6 +27,9 @@
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Weather;
using namespace BlackCore; using namespace BlackCore;
BlackCore::CApplication *sApp = nullptr; // set by constructor BlackCore::CApplication *sApp = nullptr; // set by constructor
@@ -576,7 +580,4 @@ namespace BlackCore
if (!supportsContexts()) { return nullptr; } if (!supportsContexts()) { return nullptr; }
return this->m_coreFacade->getIContextSimulator(); return this->m_coreFacade->getIContextSimulator();
} }
// ---------------------------------------------------------------------------------
} // ns } // ns

View File

@@ -14,7 +14,7 @@
#include "corefacadeconfig.h" #include "corefacadeconfig.h"
#include "cookiemanager.h" #include "cookiemanager.h"
#include "webreaderflags.h" #include "webdataservices.h"
#include "blackmisc/network/url.h" #include "blackmisc/network/url.h"
#include "blackmisc/logcategorylist.h" #include "blackmisc/logcategorylist.h"
#include "blackmisc/filelogger.h" #include "blackmisc/filelogger.h"
@@ -30,7 +30,6 @@ namespace BlackCore
{ {
class CCoreFacade; class CCoreFacade;
class CSetupReader; class CSetupReader;
class CWebDataServices;
class IContextApplication; class IContextApplication;
class IContextAudio; class IContextAudio;

View File

@@ -67,7 +67,7 @@ namespace BlackCore
// 4. Airspace contents // 4. Airspace contents
Q_ASSERT_X(this->getRuntime()->getCContextOwnAircraft(), Q_FUNC_INFO, "this and own aircraft context must be local"); 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::changedAtcStationsOnline, this, &CContextNetwork::changedAtcStationsOnline);
connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked);
connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus); connect(this->m_airspace, &CAirspaceMonitor::changedAtcStationOnlineConnectionStatus, this, &CContextNetwork::changedAtcStationOnlineConnectionStatus);
@@ -632,7 +632,7 @@ namespace BlackCore
CMetar CContextNetwork::getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const CMetar CContextNetwork::getMetarForAirport(const BlackMisc::Aviation::CAirportIcaoCode &airportIcaoCode) const
{ {
if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << airportIcaoCode; } 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 CAtcStationList CContextNetwork::getSelectedAtcStations() const