From a6cd44be8d8f0ab30f1da4254a100e132ed4447f Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 13 Jun 2014 11:46:40 +0100 Subject: [PATCH] refs #246 added ISimulator::aircraftModelChanged signal which can be sent via the contexts to CAirspaceMonitor, which needs the model when sending FSIPI(R) custom packets --- src/blackcore/airspace_monitor.cpp | 14 ++------------ src/blackcore/airspace_monitor.h | 4 ++++ src/blackcore/context_network_impl.cpp | 1 + src/blackcore/context_runtime.cpp | 6 +++--- src/blackcore/context_simulator.h | 3 +++ src/blackcore/context_simulator_impl.cpp | 1 + src/blackcore/simulator.h | 3 +++ src/plugins/simulator/fsx/simulator_fsx.cpp | 9 +++++++++ src/plugins/simulator/fsx/simulator_fsx.h | 2 +- 9 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/blackcore/airspace_monitor.cpp b/src/blackcore/airspace_monitor.cpp index fdc28b72d..91a3ad37c 100644 --- a/src/blackcore/airspace_monitor.cpp +++ b/src/blackcore/airspace_monitor.cpp @@ -287,12 +287,7 @@ namespace BlackCore { CAircraft me = this->m_ownAircraft; CAircraftIcao icao = me.getIcaoInfo(); - QString modelString; - // FIXME (MS) simulator or ownaircraft context should send an ownAircraftModelChanged signal, so we wouldn't need to interrogate the simulator context here. - //if (this->getIContextSimulator()) - //{ - // if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString(); - //} + QString modelString = this->m_ownAircraftModel.getQueriedModelString(); if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion(); this->m_network->sendFsipiCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString); } @@ -301,12 +296,7 @@ namespace BlackCore { CAircraft me = this->m_ownAircraft; CAircraftIcao icao = me.getIcaoInfo(); - QString modelString; - // FIXME (MS) simulator or ownaircraft context should send an ownAircraftModelChanged signal, so we wouldn't need to interrogate the simulator context here. - //if (this->getIContextSimulator()) - //{ - // if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString(); - //} + QString modelString = this->m_ownAircraftModel.getQueriedModelString(); if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion(); this->m_network->sendFsipirCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString); } diff --git a/src/blackcore/airspace_monitor.h b/src/blackcore/airspace_monitor.h index 914b09f86..5ac9fddb7 100644 --- a/src/blackcore/airspace_monitor.h +++ b/src/blackcore/airspace_monitor.h @@ -90,6 +90,9 @@ namespace BlackCore public slots: //! Own aircraft updated void setOwnAircraft(const BlackMisc::Aviation::CAircraft &ownAircraft) { m_ownAircraft = ownAircraft; } + + //! Own aircraft model updated + void setOwnAircraftModel(const BlackMisc::Network::CAircraftModel &model) { m_ownAircraftModel = model; } public: //! Clear the contents @@ -112,6 +115,7 @@ namespace BlackCore QMap m_flightPlanCache; BlackMisc::Aviation::CAircraft m_ownAircraft; + BlackMisc::Network::CAircraftModel m_ownAircraftModel; INetwork *m_network; CVatsimBookingReader *m_vatsimBookingReader; diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index cfeb0ce40..8965732ac 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -69,6 +69,7 @@ namespace BlackCore this->connect(this->m_airspace, &CAirspaceMonitor::changedAircraftsInRange, this, &CContextNetwork::changedAircraftsInRange); this->connect(this->m_airspace, &CAirspaceMonitor::changedAircraftSituation, this, &CContextNetwork::changedAircraftSituation); this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraft, this->m_airspace, &CAirspaceMonitor::setOwnAircraft); + this->connect(this->getIContextSimulator(), &IContextSimulator::ownAircraftModelChanged, this->m_airspace, &CAirspaceMonitor::setOwnAircraftModel); // FIXME (MS) conditional increases the number of scenarios which must be considered and continuously tested if (this->getIContextApplication()) diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index 5ab7f73b3..f432e206c 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -394,9 +394,6 @@ namespace BlackCore } times.insert("Audio", time.restart()); - this->m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), this->m_dbusServer, this->m_dbusConnection); - times.insert("Network", time.restart()); - switch (config.getModeSimulator()) { case CRuntimeConfig::Local: @@ -411,6 +408,9 @@ namespace BlackCore } times.insert("Simulator", time.restart()); + this->m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), this->m_dbusServer, this->m_dbusConnection); + times.insert("Network", time.restart()); + // checks -------------- // 1. own aircraft and simulator should reside in same location Q_ASSERT(!this->m_contextSimulator || (this->m_contextOwnAircraft->usingLocalObjects() == this->m_contextSimulator->usingLocalObjects())); diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 98332b1d9..9cd398406 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -52,6 +52,9 @@ namespace BlackCore //! Emitted when the simulator connection changes void connectionChanged(bool value); + //! Emitted when own aircraft model changes (TODO move to own aircraft context?) + void ownAircraftModelChanged(BlackMisc::Network::CAircraftModel model); + public slots: //! Return list of available simulator plugins diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index fef3a9ab6..658f195d7 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -114,6 +114,7 @@ namespace BlackCore Q_ASSERT(m_simulator); connect(m_simulator, SIGNAL(statusChanged(ISimulator::Status)), this, SLOT(setConnectionStatus(ISimulator::Status))); + connect(m_simulator, &ISimulator::aircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); return true; } diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index f9267f08a..ba1554521 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -87,6 +87,9 @@ namespace BlackCore //! Emitted when the connection status has changed void statusChanged(ISimulator::Status status); + //! Emitted when own aircraft model has changed + void aircraftModelChanged(BlackMisc::Network::CAircraftModel model); + //! Simulator started void simulatorStarted(); diff --git a/src/plugins/simulator/fsx/simulator_fsx.cpp b/src/plugins/simulator/fsx/simulator_fsx.cpp index d0aac2f48..83fdeb294 100644 --- a/src/plugins/simulator/fsx/simulator_fsx.cpp +++ b/src/plugins/simulator/fsx/simulator_fsx.cpp @@ -178,6 +178,15 @@ namespace BlackSimPlugin return this->m_simulatorInfo; } + void CSimulatorFsx::setAircraftModel(const BlackMisc::Network::CAircraftModel &model) + { + if (m_aircraftModel != model) + { + m_aircraftModel = model; + emit aircraftModelChanged(model); + } + } + bool CSimulatorFsx::updateOwnSimulatorCockpit(const CAircraft &ownAircraft) { CComSystem newCom1 = ownAircraft.getCom1System(); diff --git a/src/plugins/simulator/fsx/simulator_fsx.h b/src/plugins/simulator/fsx/simulator_fsx.h index c374bef69..603474c0d 100644 --- a/src/plugins/simulator/fsx/simulator_fsx.h +++ b/src/plugins/simulator/fsx/simulator_fsx.h @@ -144,7 +144,7 @@ namespace BlackSimPlugin void onSimExit(); //! \private - void setAircraftModel(const BlackMisc::Network::CAircraftModel &model) { m_aircraftModel = model; } + void setAircraftModel(const BlackMisc::Network::CAircraftModel &model); protected: //! Timer event