mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Issue #77 Refactor to inline functions
This commit is contained in:
@@ -220,7 +220,7 @@ namespace BlackCore
|
||||
void CAirspaceAnalyzer::analyzeAirspace()
|
||||
{
|
||||
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");
|
||||
Q_ASSERT_X(thread() != qApp->thread(), Q_FUNC_INFO, "Expect to run in background thread affinity");
|
||||
|
||||
bool restricted, enabled;
|
||||
int maxAircraft;
|
||||
|
||||
@@ -1809,7 +1809,7 @@ namespace BlackCore
|
||||
if (!this->isNetworkAccessible()) { return nullptr; }
|
||||
|
||||
QWriteLocker locker(&m_accessManagerLock);
|
||||
Q_ASSERT_X(CThreadUtils::isApplicationThreadObjectThread(m_accessManager), Q_FUNC_INFO, "Network manager supposed to be in main thread");
|
||||
Q_ASSERT_X(m_accessManager->thread() == qApp->thread(), Q_FUNC_INFO, "Network manager supposed to be in main thread");
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(m_accessManager))
|
||||
{
|
||||
this->httpRequestImplInQAMThread(request, logId, callback, progress, maxRedirects, getPostOrDeleteRequest);
|
||||
|
||||
@@ -195,10 +195,10 @@ namespace BlackCore
|
||||
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
|
||||
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
|
||||
|
||||
Q_ASSERT_X(CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Should be in main thread");
|
||||
Q_ASSERT_X(m_voiceClient->thread() == qApp->thread(), Q_FUNC_INFO, "Should be in main thread");
|
||||
m_voiceClient->start(); // thread
|
||||
Q_ASSERT_X(m_voiceClient->owner() == this, Q_FUNC_INFO, "Wrong owner");
|
||||
Q_ASSERT_X(!CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Must NOT be in main thread");
|
||||
Q_ASSERT_X(m_voiceClient->thread() != qApp->thread(), Q_FUNC_INFO, "Must NOT be in main thread");
|
||||
|
||||
// connect(m_voiceClient, &CAfvClient::outputVolumePeakVU, this, &CContextAudioBase::outputVolumePeakVU, Qt::QueuedConnection);
|
||||
// connect(m_voiceClient, &CAfvClient::inputVolumePeakVU, this, &CContextAudioBase::inputVolumePeakVU, Qt::QueuedConnection);
|
||||
|
||||
@@ -225,7 +225,15 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::connectToServer()
|
||||
{
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->connectToServer(); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { connectToServer(); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_socket.isOpen()) { return; }
|
||||
Q_ASSERT(!m_clientName.isEmpty());
|
||||
Q_ASSERT((m_versionMajor + m_versionMinor) > 0);
|
||||
@@ -257,8 +265,15 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::disconnectFromServer()
|
||||
{
|
||||
if (this->isDisconnected()) { return; }
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->disconnectFromServer(); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { disconnectFromServer(); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this->stopPositionTimers();
|
||||
this->updateConnectionStatus(CConnectionStatus::Disconnecting);
|
||||
|
||||
@@ -426,7 +441,14 @@ namespace BlackCore
|
||||
void CFSDClient::sendClientQuery(ClientQueryType queryType, const CCallsign &receiver, const QStringList &queryData)
|
||||
{
|
||||
if (queryType == ClientQueryType::Unknown) { return; }
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendClientQuery(queryType, receiver, queryData); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendClientQuery(queryType, receiver, queryData); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const QString reveiverCallsign = receiver.getFsdCallsignString();
|
||||
if (queryType == ClientQueryType::IsValidATC)
|
||||
@@ -492,7 +514,14 @@ namespace BlackCore
|
||||
void CFSDClient::sendTextMessages(const CTextMessageList &messages)
|
||||
{
|
||||
if (messages.isEmpty()) { return; }
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendTextMessages(messages); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendTextMessages(messages); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const CTextMessageList privateMessages = messages.getPrivateMessages().markedAsSent();
|
||||
const QString ownCallsign = getOwnCallsignAsString();
|
||||
@@ -536,7 +565,14 @@ namespace BlackCore
|
||||
void CFSDClient::sendTextMessage(TextMessageGroups receiverGroup, const QString &message)
|
||||
{
|
||||
if (message.isEmpty()) { return; }
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendTextMessage(receiverGroup, message); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendTextMessage(receiverGroup, message); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
QString receiver;
|
||||
if (receiverGroup == TextMessageGroups::AllClients) { receiver = '*'; }
|
||||
@@ -578,7 +614,14 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::sendFlightPlan(const CFlightPlan &flightPlan)
|
||||
{
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendFlightPlan(flightPlan); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendFlightPlan(flightPlan); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Removed with T353 although it is standard
|
||||
// const QString route = QString(flightPlan.getRoute()).replace(" ", ".");
|
||||
@@ -628,7 +671,15 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::sendPlaneInfoRequest(const CCallsign &receiver)
|
||||
{
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendPlaneInfoRequest(receiver); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendPlaneInfoRequest(receiver); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const PlaneInfoRequest planeInfoRequest(getOwnCallsignAsString(), receiver.toQString());
|
||||
sendQueudedMessage(planeInfoRequest);
|
||||
increaseStatisticsValue(QStringLiteral("sendPlaneInfoRequest"));
|
||||
@@ -636,7 +687,15 @@ namespace BlackCore
|
||||
|
||||
void CFSDClient::sendPlaneInfoRequestFsinn(const CCallsign &callsign)
|
||||
{
|
||||
if (CThreadUtils::callInObjectThread(this, [ = ] { if (sApp && !sApp->isShuttingDown()) { this->sendPlaneInfoRequestFsinn(callsign); }})) { return; }
|
||||
if (!CThreadUtils::isCurrentThreadObjectThread(this))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [ = ]
|
||||
{
|
||||
if (sApp && !sApp->isShuttingDown()) { sendPlaneInfoRequestFsinn(callsign); }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const bool connected = isConnected();
|
||||
BLACK_VERIFY_X(connected, Q_FUNC_INFO, "Can't send to server when disconnected");
|
||||
if (!connected) { return; }
|
||||
|
||||
Reference in New Issue
Block a user