From 62491ad4e6a2011dbed52ccd5f4449c0a8702075 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 5 Jun 2016 22:51:44 +0200 Subject: [PATCH] Add another CWeatherManager API to request weather grid Instead of the existing one, this newly added API allows to request a weather grid without a callback as argument. Instead the final grid will be emitted as signal. This API is also made available in ISimulatorContext for GUI access. refs #663 --- src/blackcore/contextsimulator.h | 8 ++++++++ src/blackcore/contextsimulatorempty.h | 8 ++++++++ src/blackcore/contextsimulatorimpl.cpp | 6 ++++++ src/blackcore/contextsimulatorimpl.h | 3 +++ src/blackcore/contextsimulatorproxy.cpp | 8 ++++++++ src/blackcore/contextsimulatorproxy.h | 3 +++ src/blackcore/weathermanager.cpp | 14 ++++++++++++-- src/blackcore/weathermanager.h | 12 +++++++++++- 8 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/blackcore/contextsimulator.h b/src/blackcore/contextsimulator.h index 00b8a4f62..10429d860 100644 --- a/src/blackcore/contextsimulator.h +++ b/src/blackcore/contextsimulator.h @@ -30,6 +30,7 @@ #include "blackcore/corefacadeconfig.h" #include "blackcore/simulator.h" #include "blackmisc/aviation/airportlist.h" +#include "blackmisc/identifier.h" #include "blackmisc/pixmap.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/time.h" @@ -37,6 +38,7 @@ #include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/simulatorsetup.h" +#include "blackmisc/weather/weathergrid.h" #include #include @@ -99,6 +101,9 @@ namespace BlackCore //! An airspace snapshot was handled void airspaceSnapshotHandled(); + //! A weather grid, requested with requestWeatherGrid(), is received + void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); + public slots: //! Simulator info, currently loaded plugin virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0; @@ -186,6 +191,9 @@ namespace BlackCore //! Highlight aircraft in simulator virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) = 0; + //! Request weather grid. Argument identifier is past in the signal to identify the requestor + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) = 0; + protected: //! Constructor IContextSimulator(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContext(mode, runtime) {} diff --git a/src/blackcore/contextsimulatorempty.h b/src/blackcore/contextsimulatorempty.h index bc25b5255..1edab6a15 100644 --- a/src/blackcore/contextsimulatorempty.h +++ b/src/blackcore/contextsimulatorempty.h @@ -208,6 +208,14 @@ namespace BlackCore logEmptyContextWarning(Q_FUNC_INFO); } + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override + { + Q_UNUSED(weatherGrid); + Q_UNUSED(identifier); + logEmptyContextWarning(Q_FUNC_INFO); + } + //! \copydoc ISimulator::enableDebugMessages virtual void enableDebugMessages(bool driver, bool interpolator) override { diff --git a/src/blackcore/contextsimulatorimpl.cpp b/src/blackcore/contextsimulatorimpl.cpp index a13d54ee9..c0c9bf1bf 100644 --- a/src/blackcore/contextsimulatorimpl.cpp +++ b/src/blackcore/contextsimulatorimpl.cpp @@ -48,6 +48,7 @@ namespace BlackCore m_plugins(new CPluginManagerSimulator(this)) { this->setObjectName("CContextSimulator"); + connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived); m_plugins->collectPlugins(); } @@ -607,6 +608,11 @@ namespace BlackCore m_simulatorPlugin.second->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime); } + void CContextSimulator::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) + { + m_weatherManager.requestWeatherGrid(weatherGrid, identifier); + } + void CContextSimulator::ps_simulatorStarted(const CSimulatorPluginInfo &info) { stopSimulatorListeners(); diff --git a/src/blackcore/contextsimulatorimpl.h b/src/blackcore/contextsimulatorimpl.h index f70dd861c..0498a6826 100644 --- a/src/blackcore/contextsimulatorimpl.h +++ b/src/blackcore/contextsimulatorimpl.h @@ -143,6 +143,9 @@ namespace BlackCore //! \copydoc IContextSimulator::highlightAircraft virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; + protected: //! Constructor CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime); diff --git a/src/blackcore/contextsimulatorproxy.cpp b/src/blackcore/contextsimulatorproxy.cpp index 4c6479f8a..d26fbfd10 100644 --- a/src/blackcore/contextsimulatorproxy.cpp +++ b/src/blackcore/contextsimulatorproxy.cpp @@ -58,6 +58,9 @@ namespace BlackCore s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "airspaceSnapshotHandled", this, SIGNAL(airspaceSnapshotHandled())); Q_ASSERT(s); + s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), + "weatherGridReceived", this, SIGNAL(weatherGridReceived())); + Q_ASSERT(s); Q_UNUSED(s); } @@ -186,6 +189,11 @@ namespace BlackCore m_dBusInterface->callDBus(QLatin1Literal("highlightAircraft"), aircraftToHighlight, enableHighlight, displayTime); } + void CContextSimulatorProxy::requestWeatherGrid(const Weather::CWeatherGrid &weatherGrid, const CIdentifier &identifier) + { + m_dBusInterface->callDBus(QLatin1Literal("requestWeatherGrid"), weatherGrid, identifier); + } + void CContextSimulatorProxy::enableDebugMessages(bool driver, bool interpolator) { m_dBusInterface->callDBus(QLatin1Literal("enableDebugMessages"), driver, interpolator); diff --git a/src/blackcore/contextsimulatorproxy.h b/src/blackcore/contextsimulatorproxy.h index 11a7e71f1..5b12294b4 100644 --- a/src/blackcore/contextsimulatorproxy.h +++ b/src/blackcore/contextsimulatorproxy.h @@ -139,6 +139,9 @@ namespace BlackCore //! \copydoc IContextSimulator::highlightAircraft virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override; + //! \copydoc IContextSimulator::requestWeatherGrid + virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) override; + //! \copydoc ISimulator::enableDebugMessages virtual void enableDebugMessages(bool driver, bool interpolator) override; }; diff --git a/src/blackcore/weathermanager.cpp b/src/blackcore/weathermanager.cpp index 17c4440aa..b5a31c7e9 100644 --- a/src/blackcore/weathermanager.cpp +++ b/src/blackcore/weathermanager.cpp @@ -12,6 +12,7 @@ #include "blackmisc/logmessage.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/units.h" +#include "blackmisc/range.h" #include "blackmisc/statusmessage.h" #include "blackmisc/weather/gridpoint.h" #include "blackmisc/weather/weatherdataplugininfo.h" @@ -39,6 +40,14 @@ namespace BlackCore // todo: send weather grid to drivers from here } + void CWeatherManager::requestWeatherGrid(const CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier) + { + WeatherRequest request { identifier, weatherGrid, {} }; + m_pendingRequests.append(request); + // Serialize the requests, since plugins can handle only one at a time + if (m_pendingRequests.size() == 1) { fetchNextWeatherData(); } + } + void CWeatherManager::requestWeatherGrid(const CWeatherGrid &weatherGrid, const BlackMisc::CSlot &callback) { @@ -48,7 +57,7 @@ namespace BlackCore return; } - WeatherRequest weatherRequest { weatherGrid, callback }; + WeatherRequest weatherRequest { CIdentifier::anonymous(), weatherGrid, callback }; m_pendingRequests.append(weatherRequest); // Serialize the requests, since plugins can handle only one at a time @@ -116,7 +125,8 @@ namespace BlackCore gridPoint.copyWeatherDataFrom(nearestGridPoint); } - weatherRequest.callback(requestedWeatherGrid); + if (weatherRequest.callback) { weatherRequest.callback(requestedWeatherGrid); } + if (!weatherRequest.identifier.isAnonymous()) { emit weatherGridReceived(requestedWeatherGrid, weatherRequest.identifier); } m_pendingRequests.pop_front(); // In case there are pending requests, start over again diff --git a/src/blackcore/weathermanager.h b/src/blackcore/weathermanager.h index 3962526de..43ff3a074 100644 --- a/src/blackcore/weathermanager.h +++ b/src/blackcore/weathermanager.h @@ -14,6 +14,7 @@ #include "blackcore/blackcoreexport.h" #include "blackcore/pluginmanagerweatherdata.h" +#include "blackmisc/identifier.h" #include "blackmisc/slot.h" #include "blackmisc/weather/weathergrid.h" #include "blackmisc/weather/weathergridprovider.h" @@ -45,13 +46,22 @@ namespace BlackCore //! Is weather overwritten to clear? bool isWeatherClear() const { return m_isWeatherClear; } - //! Request weather by grid + //! Request weather grid + void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); + + //! \copydoc BlackMisc::Weather::IWeatherGridProvider::requestWeatherGrid virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CSlot &callback) override; + + signals: + //! The weather grid, requested from identified, is available + void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); + private: struct WeatherRequest { + BlackMisc::CIdentifier identifier; BlackMisc::Weather::CWeatherGrid weatherGrid; BlackMisc::CSlot callback; };