mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
refs #502, move the thread checks into own class in blackmisc
* we want to clean up the freefunctions anyway * allows to use check in blackmisc namespace
This commit is contained in:
committed by
Mathew Sutcliffe
parent
e11e8e5716
commit
98b86b6f27
@@ -10,6 +10,7 @@
|
||||
#include "blackcore/airspace_analyzer.h"
|
||||
#include "blackcore/blackcorefreefunctions.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/threadutilities.h"
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -173,8 +174,8 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceAnalyzer::analyzeAirspace()
|
||||
{
|
||||
Q_ASSERT_X(!isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background thread");
|
||||
Q_ASSERT_X(!isApplicationThreadObjectThread(this), Q_FUNC_INFO, "Expect to run in background thread affinity");
|
||||
Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background thread");
|
||||
Q_ASSERT_X(!CThreadUtils::isApplicationThreadObjectThread(this), Q_FUNC_INFO, "Expect to run in background thread affinity");
|
||||
|
||||
bool restricted, enabled;
|
||||
int maxAircraft;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/propertyindexallclasses.h"
|
||||
#include "blackmisc/threadutilities.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -569,7 +570,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_receivedBookings(const CAtcStationList &bookedStations)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (bookedStations.isEmpty())
|
||||
{
|
||||
this->m_atcStationsBooked.clear();
|
||||
@@ -589,7 +590,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_receivedDataFile()
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
for (auto client = this->m_otherClients.begin(); client != this->m_otherClients.end(); ++client)
|
||||
{
|
||||
if (client->hasSpecifiedVoiceCapabilities()) { continue; } // we already have voice caps
|
||||
@@ -632,7 +633,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_atcPositionUpdate(const CCallsign &callsign, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const CCoordinateGeodetic &position, const BlackMisc::PhysicalQuantities::CLength &range)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (!this->m_connected) { return; }
|
||||
CAtcStationList stationsWithCallsign = this->m_atcStationsOnline.findByCallsign(callsign);
|
||||
if (stationsWithCallsign.isEmpty())
|
||||
@@ -682,7 +683,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_atcControllerDisconnected(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
|
||||
this->m_otherClients.removeByCallsign(callsign);
|
||||
if (this->m_atcStationsOnline.containsCallsign(callsign))
|
||||
@@ -699,7 +700,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_atisReceived(const CCallsign &callsign, const CInformationMessage &atisMessage)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (!this->m_connected || callsign.isEmpty()) return;
|
||||
CPropertyIndexVariantMap vm(CAtcStation::IndexAtis, CVariant::from(atisMessage));
|
||||
int changedOnline = this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm);
|
||||
@@ -713,7 +714,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_atisVoiceRoomReceived(const CCallsign &callsign, const QString &url)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (!this->m_connected) { return; }
|
||||
QString trimmedUrl = url.trimmed();
|
||||
CPropertyIndexVariantMap vm({ CAtcStation::IndexVoiceRoom, CVoiceRoom::IndexUrl }, trimmedUrl);
|
||||
@@ -740,7 +741,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_atisLogoffTimeReceived(const CCallsign &callsign, const QString &zuluTime)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (!this->m_connected) { return; }
|
||||
if (zuluTime.length() == 4)
|
||||
{
|
||||
@@ -764,7 +765,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_icaoCodesReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &aircraftIcaoDesignator, const QString &airlineIcaoDesignator, const QString &livery)
|
||||
{
|
||||
Q_ASSERT_X(BlackCore::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "not in main thread");
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "not in main thread");
|
||||
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "no callsign");
|
||||
if (!this->m_connected) { return; }
|
||||
|
||||
@@ -844,7 +845,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_aircraftUpdateReceived(const CAircraftSituation &situation, const CTransponder &transponder)
|
||||
{
|
||||
Q_ASSERT_X(BlackCore::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread");
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread");
|
||||
if (!this->m_connected) { return; }
|
||||
|
||||
CCallsign callsign(situation.getCallsign());
|
||||
@@ -934,7 +935,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_aircraftInterimUpdateReceived(const CAircraftSituation &situation)
|
||||
{
|
||||
Q_ASSERT_X(BlackCore::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread");
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Called in different thread");
|
||||
if (!this->m_connected) { return; }
|
||||
|
||||
CCallsign callsign(situation.getCallsign());
|
||||
@@ -975,7 +976,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_pilotDisconnected(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
|
||||
// in case of inconsistencies I always remove here
|
||||
this->m_otherClients.removeByCallsign(callsign);
|
||||
@@ -1001,7 +1002,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_frequencyReceived(const CCallsign &callsign, const CFrequency &frequency)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
|
||||
// update
|
||||
int changed;
|
||||
@@ -1015,7 +1016,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_aircraftConfigReceived(const BlackMisc::Aviation::CCallsign &callsign, const QJsonObject &jsonObject, bool isFull)
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
|
||||
CSimulatedAircraft simAircraft(getAircraftInRangeForCallsign(callsign));
|
||||
|
||||
@@ -1050,7 +1051,7 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::ps_sendInterimPositions()
|
||||
{
|
||||
Q_ASSERT(BlackCore::isCurrentThreadObjectThread(this));
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadObjectThread(this));
|
||||
if (!this->m_connected || !m_sendInterimPositions) { return; }
|
||||
CSimulatedAircraftList aircrafts = m_aircraftInRange.findBy(&CSimulatedAircraft::fastPositionUpdates, true);
|
||||
m_network->sendInterimPositions(aircrafts.getCallsigns());
|
||||
|
||||
@@ -27,26 +27,4 @@ namespace BlackCore
|
||||
|
||||
BlackCore::Data::CGlobalSetup::registerMetadata();
|
||||
}
|
||||
|
||||
bool isCurrentThreadObjectThread(QObject *toBeTested)
|
||||
{
|
||||
Q_ASSERT_X(toBeTested, Q_FUNC_INFO, "missing QObject");
|
||||
if (!toBeTested) { return false; }
|
||||
if (!toBeTested->thread()) { return false; }
|
||||
return (QThread::currentThread() == toBeTested->thread());
|
||||
}
|
||||
|
||||
bool isApplicationThreadObjectThread(QObject *toBeTested)
|
||||
{
|
||||
Q_ASSERT_X(toBeTested, Q_FUNC_INFO, "missing QObject");
|
||||
if (!toBeTested) { return false; }
|
||||
if (!toBeTested->thread()) { return false; }
|
||||
return (QCoreApplication::instance()->thread() == toBeTested->thread());
|
||||
}
|
||||
|
||||
bool isCurrentThreadApplicationThread()
|
||||
{
|
||||
return (QCoreApplication::instance()->thread() == QThread::currentThread());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -14,18 +14,6 @@ namespace BlackCore
|
||||
//! Register all relevant metadata in BlackCore
|
||||
BLACKCORE_EXPORT void registerMetadata();
|
||||
|
||||
//! Is the current thread the QObject's thread?
|
||||
//! \remarks can be used as ASSERT check for threaded objects
|
||||
BLACKCORE_EXPORT bool isCurrentThreadObjectThread(QObject *toBeTested);
|
||||
|
||||
//! Is the application thread the QObject's thread?
|
||||
//! \remarks can be used as ASSERT check for threaded objects
|
||||
BLACKCORE_EXPORT bool isApplicationThreadObjectThread(QObject *toBeTested);
|
||||
|
||||
//! Is the current thread the Application thread?
|
||||
//! \remarks can be used as ASSERT check for threaded objects
|
||||
BLACKCORE_EXPORT bool isCurrentThreadApplicationThread();
|
||||
|
||||
} // BlackCore
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "blackmisc/propertyindexvariantmap.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/threadutilities.h"
|
||||
#include <QPluginLoader>
|
||||
#include <QLibrary>
|
||||
|
||||
@@ -278,7 +279,7 @@ namespace BlackCore
|
||||
Q_ASSERT(getIContextApplication());
|
||||
Q_ASSERT(getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
Q_ASSERT(BlackCore::isCurrentThreadApplicationThread()); // only run in main thread
|
||||
Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread
|
||||
|
||||
// Is the plugin already loaded?
|
||||
if (!m_simulatorPlugin.first.isUnspecified() &&
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/threadutilities.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -305,7 +306,7 @@ namespace BlackCore
|
||||
// when changing back from restricted->unrestricted an one time update is required
|
||||
if (!snapshot.isRestricted() && !snapshot.isRestrictionChanged()) { return; }
|
||||
|
||||
Q_ASSERT_X(BlackCore::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Needs to run in object thread");
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "Needs to run in object thread");
|
||||
Q_ASSERT_X(snapshot.generatingThreadName() != QThread::currentThread()->objectName(), Q_FUNC_INFO, "Expect snapshot from background thread");
|
||||
|
||||
// restricted snapshot values?
|
||||
|
||||
Reference in New Issue
Block a user