mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
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
This commit is contained in:
@@ -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 <QObject>
|
||||
#include <QString>
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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<void(const BlackMisc::Weather::CWeatherGrid &)> &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
|
||||
|
||||
@@ -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<void(const BlackMisc::Weather::CWeatherGrid &)> &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<void(const BlackMisc::Weather::CWeatherGrid &)> callback;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user