mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
Ref T786, make sure callbacks are called in correct thread
* callback.singleShot * shutdown guards, "myself" * BLACK_VERIFY * Qt::QueuedConnection
This commit is contained in:
committed by
Mat Sutcliffe
parent
fbf63457c1
commit
3be498a347
@@ -77,7 +77,7 @@ namespace BlackCore
|
|||||||
m_plugins->collectPlugins();
|
m_plugins->collectPlugins();
|
||||||
this->restoreSimulatorPlugins();
|
this->restoreSimulatorPlugins();
|
||||||
|
|
||||||
connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived);
|
connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived, Qt::QueuedConnection);
|
||||||
connect(&m_aircraftMatcher, &CAircraftMatcher::setupChanged, this, &CContextSimulator::matchingSetupChanged);
|
connect(&m_aircraftMatcher, &CAircraftMatcher::setupChanged, this, &CContextSimulator::matchingSetupChanged);
|
||||||
connect(&CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance(), &CCentralMultiSimulatorModelSetCachesProvider::cacheChanged, this, &CContextSimulator::modelSetChanged);
|
connect(&CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance(), &CCentralMultiSimulatorModelSetCachesProvider::cacheChanged, this, &CContextSimulator::modelSetChanged);
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,16 @@
|
|||||||
|
|
||||||
#include "blackcore/weatherdata.h"
|
#include "blackcore/weatherdata.h"
|
||||||
#include "blackcore/weathermanager.h"
|
#include "blackcore/weathermanager.h"
|
||||||
#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/gridpoint.h"
|
||||||
#include "blackmisc/weather/weatherdataplugininfo.h"
|
#include "blackmisc/weather/weatherdataplugininfo.h"
|
||||||
#include "blackmisc/weather/weatherdataplugininfolist.h"
|
#include "blackmisc/weather/weatherdataplugininfolist.h"
|
||||||
|
#include "blackmisc/pq/length.h"
|
||||||
|
#include "blackmisc/pq/units.h"
|
||||||
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackmisc/range.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
#include "blackmisc/statusmessage.h"
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
@@ -42,6 +44,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
WeatherRequest request { {}, identifier, weatherGrid, {} };
|
WeatherRequest request { {}, identifier, weatherGrid, {} };
|
||||||
m_pendingRequests.append(request);
|
m_pendingRequests.append(request);
|
||||||
|
|
||||||
// Serialize the requests, since plugins can handle only one at a time
|
// Serialize the requests, since plugins can handle only one at a time
|
||||||
if (m_pendingRequests.size() == 1) { fetchNextWeatherData(); }
|
if (m_pendingRequests.size() == 1) { fetchNextWeatherData(); }
|
||||||
}
|
}
|
||||||
@@ -49,9 +52,12 @@ namespace BlackCore
|
|||||||
void CWeatherManager::requestWeatherGrid(const CWeatherGrid &weatherGrid,
|
void CWeatherManager::requestWeatherGrid(const CWeatherGrid &weatherGrid,
|
||||||
const CSlot<void(const CWeatherGrid &)> &callback)
|
const CSlot<void(const CWeatherGrid &)> &callback)
|
||||||
{
|
{
|
||||||
|
BLACK_VERIFY_X(callback, Q_FUNC_INFO, "Missing callback");
|
||||||
|
if (!callback) { return; }
|
||||||
|
|
||||||
if (m_isWeatherClear)
|
if (m_isWeatherClear)
|
||||||
{
|
{
|
||||||
callback(CWeatherGrid::getClearWeatherGrid());
|
callback.singleShot(CWeatherGrid::getClearWeatherGrid());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,9 +71,9 @@ namespace BlackCore
|
|||||||
void CWeatherManager::requestWeatherGridFromFile(const QString &filePath, const CWeatherGrid &weatherGrid,
|
void CWeatherManager::requestWeatherGridFromFile(const QString &filePath, const CWeatherGrid &weatherGrid,
|
||||||
const CSlot<void(const CWeatherGrid &)> &callback)
|
const CSlot<void(const CWeatherGrid &)> &callback)
|
||||||
{
|
{
|
||||||
if (m_isWeatherClear)
|
if (m_isWeatherClear && callback)
|
||||||
{
|
{
|
||||||
callback(CWeatherGrid::getClearWeatherGrid());
|
callback.singleShot(CWeatherGrid::getClearWeatherGrid());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +109,7 @@ namespace BlackCore
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(weatherData, &IWeatherData::fetchingFinished, this, &CWeatherManager::handleNextRequest);
|
connect(weatherData, &IWeatherData::fetchingFinished, this, &CWeatherManager::handleNextRequest, Qt::QueuedConnection);
|
||||||
m_weatherDataPlugins.append(weatherData);
|
m_weatherDataPlugins.append(weatherData);
|
||||||
delete factory;
|
delete factory;
|
||||||
}
|
}
|
||||||
@@ -131,7 +137,7 @@ namespace BlackCore
|
|||||||
const auto fetchedWeatherGrid = weatherDataPlugin->getWeatherData();
|
const auto fetchedWeatherGrid = weatherDataPlugin->getWeatherData();
|
||||||
|
|
||||||
const WeatherRequest weatherRequest = m_pendingRequests.constFirst();
|
const WeatherRequest weatherRequest = m_pendingRequests.constFirst();
|
||||||
CWeatherGrid requestedWeatherGrid = weatherRequest.weatherGrid;
|
CWeatherGrid requestedWeatherGrid = weatherRequest.weatherGrid;
|
||||||
|
|
||||||
// Interpolation. So far it just picks the closest point without interpolation.
|
// Interpolation. So far it just picks the closest point without interpolation.
|
||||||
for (CGridPoint &gridPoint : requestedWeatherGrid)
|
for (CGridPoint &gridPoint : requestedWeatherGrid)
|
||||||
@@ -141,7 +147,7 @@ namespace BlackCore
|
|||||||
gridPoint.setPosition(nearestGridPoint.getPosition());
|
gridPoint.setPosition(nearestGridPoint.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weatherRequest.callback) { weatherRequest.callback(requestedWeatherGrid); }
|
if (weatherRequest.callback) { weatherRequest.callback.singleShot(requestedWeatherGrid); }
|
||||||
if (!weatherRequest.identifier.isAnonymous()) { emit weatherGridReceived(requestedWeatherGrid, weatherRequest.identifier); }
|
if (!weatherRequest.identifier.isAnonymous()) { emit weatherGridReceived(requestedWeatherGrid, weatherRequest.identifier); }
|
||||||
m_pendingRequests.pop_front();
|
m_pendingRequests.pop_front();
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ namespace BlackCore
|
|||||||
void handleNextRequest();
|
void handleNextRequest();
|
||||||
|
|
||||||
CPluginManagerWeatherData m_pluginManagerWeatherData { this };
|
CPluginManagerWeatherData m_pluginManagerWeatherData { this };
|
||||||
QVector<IWeatherData *> m_weatherDataPlugins;
|
QVector<IWeatherData *> m_weatherDataPlugins;
|
||||||
QVector<WeatherRequest> m_pendingRequests;
|
QVector<WeatherRequest> m_pendingRequests;
|
||||||
BlackMisc::Weather::CWeatherGrid m_weatherGrid;
|
BlackMisc::Weather::CWeatherGrid m_weatherGrid;
|
||||||
bool m_isWeatherClear = false;
|
bool m_isWeatherClear = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
// here I know I am the selected widget, update, but keep GUI responsive (-> timer)
|
// here I know I am the selected widget, update, but keep GUI responsive (-> timer)
|
||||||
//QTimer::singleShot(1000, this, &CWeatherComponent::update);
|
//QTimer::singleShot(1000, this, &CWeatherComponent::update);
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWeatherComponent::toggleUseOwnAircraftPosition(bool useOwnAircraftPosition)
|
void CWeatherComponent::toggleUseOwnAircraftPosition(bool useOwnAircraftPosition)
|
||||||
@@ -243,7 +243,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
// Context connections
|
// Context connections
|
||||||
Q_ASSERT(sGui->getIContextSimulator());
|
Q_ASSERT(sGui->getIContextSimulator());
|
||||||
connect(sGui->getIContextSimulator(), &IContextSimulator::weatherGridReceived, this, &CWeatherComponent::weatherGridReceived);
|
connect(sGui->getIContextSimulator(), &IContextSimulator::weatherGridReceived, this, &CWeatherComponent::weatherGridReceived, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWeatherComponent::setWeatherGrid(const CWeatherGrid &weatherGrid)
|
void CWeatherComponent::setWeatherGrid(const CWeatherGrid &weatherGrid)
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ namespace BlackWxPlugin
|
|||||||
|
|
||||||
void CWeatherDataGfs::fetchWeatherData(const CWeatherGrid &grid, const CLength &range)
|
void CWeatherDataGfs::fetchWeatherData(const CWeatherGrid &grid, const CLength &range)
|
||||||
{
|
{
|
||||||
|
if (!sApp || sApp->isShuttingDown()) { return; }
|
||||||
m_grid = grid;
|
m_grid = grid;
|
||||||
m_maxRange = range;
|
m_maxRange = range;
|
||||||
if (m_gribData.isEmpty())
|
if (m_gribData.isEmpty())
|
||||||
@@ -202,8 +203,20 @@ namespace BlackWxPlugin
|
|||||||
void CWeatherDataGfs::fetchingWeatherDataFinished()
|
void CWeatherDataGfs::fetchingWeatherDataFinished()
|
||||||
{
|
{
|
||||||
// If the worker is not destroyed yet, try again in 10 ms.
|
// If the worker is not destroyed yet, try again in 10 ms.
|
||||||
if (m_parseGribFileWorker) { QTimer::singleShot(10, this, &CWeatherDataGfs::fetchingWeatherDataFinished); }
|
if (m_parseGribFileWorker)
|
||||||
else { emit fetchingFinished(); }
|
{
|
||||||
|
QPointer<CWeatherDataGfs> myself(this);
|
||||||
|
QTimer::singleShot(25, this, [ = ]
|
||||||
|
{
|
||||||
|
// try again until finished
|
||||||
|
if (!myself) { return; }
|
||||||
|
myself->fetchingWeatherDataFinished();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emit fetchingFinished();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWeatherDataGfs::parseGfsFile(QNetworkReply *nwReplyPtr)
|
void CWeatherDataGfs::parseGfsFile(QNetworkReply *nwReplyPtr)
|
||||||
|
|||||||
Reference in New Issue
Block a user