[FSD] Start FSD client in own thread (CContinuousWorker)

This commit is contained in:
Klaus Basan
2019-11-19 19:14:11 +01:00
committed by Mat Sutcliffe
parent 4ef17fed6a
commit 34f9fb89d6
3 changed files with 21 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ namespace BlackCore
this->setObjectName("CAirspaceMonitor"); this->setObjectName("CAirspaceMonitor");
this->enableReverseLookupMessages(sApp->isDeveloperFlagSet() || CBuildConfig::isLocalDeveloperDebugBuild() ? RevLogEnabled : RevLogEnabledSimplified); this->enableReverseLookupMessages(sApp->isDeveloperFlagSet() || CBuildConfig::isLocalDeveloperDebugBuild() ? RevLogEnabled : RevLogEnabledSimplified);
// FSD TODO // FSD runs in its own thread!
connect(m_fsdClient, &CFSDClient::atcDataUpdateReceived, this, &CAirspaceMonitor::onAtcPositionUpdate); connect(m_fsdClient, &CFSDClient::atcDataUpdateReceived, this, &CAirspaceMonitor::onAtcPositionUpdate);
connect(m_fsdClient, &CFSDClient::atisReplyReceived, this, &CAirspaceMonitor::onAtisReceived); connect(m_fsdClient, &CFSDClient::atisReplyReceived, this, &CAirspaceMonitor::onAtisReceived);
connect(m_fsdClient, &CFSDClient::atisLogoffTimeReplyReceived, this, &CAirspaceMonitor::onAtisLogoffTimeReceived); connect(m_fsdClient, &CFSDClient::atisLogoffTimeReplyReceived, this, &CAirspaceMonitor::onAtisLogoffTimeReceived);

View File

@@ -78,7 +78,7 @@ namespace BlackCore
CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, CAirspaceMonitor(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft,
BlackMisc::Simulation::IAircraftModelSetProvider *modelSetProvider, BlackMisc::Simulation::IAircraftModelSetProvider *modelSetProvider,
Fsd::CFSDClient *fsdClient, Fsd::CFSDClient *fsdClient,
QObject *parent); QObject *parent);
//! Members not implenented or fully implenented by CRemoteAircraftProvider //! Members not implenented or fully implenented by CRemoteAircraftProvider
//! \ingroup remoteaircraftprovider //! \ingroup remoteaircraftprovider

View File

@@ -69,12 +69,17 @@ namespace BlackCore
CContextNetwork::registerHelp(); CContextNetwork::registerHelp();
// 1. Init by "network driver" // 1. Init by "network driver"
m_fsdClient = new CFSDClient(this, this->getRuntime()->getCContextOwnAircraft(), this, this); m_fsdClient = new CFSDClient(
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged); this, // client provider
connect(m_fsdClient, &CFSDClient::killRequestReceived, this, &CContextNetwork::kicked); this->getRuntime()->getCContextOwnAircraft(), // own aircraft provider
connect(m_fsdClient, &CFSDClient::textMessagesReceived, this, &CContextNetwork::textMessagesReceived); this, // remote aircraft provider
connect(m_fsdClient, &CFSDClient::textMessageSent, this, &CContextNetwork::textMessageSent); this); // thread owner
connect(m_fsdClient, &CFSDClient::severeNetworkError, this, &CContextNetwork::severeNetworkError); m_fsdClient->start(); // FSD thread
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::killRequestReceived, this, &CContextNetwork::kicked, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessagesReceived, this, &CContextNetwork::textMessagesReceived, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessageSent, this, &CContextNetwork::textMessageSent, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::severeNetworkError, this, &CContextNetwork::severeNetworkError, Qt::QueuedConnection);
// 2. Update timer for data (network data such as frequency) // 2. Update timer for data (network data such as frequency)
// we use 2 timers so we can query at different times (not too many queirs at once) // we use 2 timers so we can query at different times (not too many queirs at once)
@@ -107,7 +112,7 @@ namespace BlackCore
connect(m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked, Qt::QueuedConnection); connect(m_airspace, &CAirspaceMonitor::changedAtcStationsBooked, this, &CContextNetwork::changedAtcStationsBooked, Qt::QueuedConnection);
connect(m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange, Qt::QueuedConnection); connect(m_airspace, &CAirspaceMonitor::changedAircraftInRange, this, &CContextNetwork::changedAircraftInRange, Qt::QueuedConnection);
connect(m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft, Qt::QueuedConnection); // DBus connect(m_airspace, &CAirspaceMonitor::removedAircraft, this, &IContextNetwork::removedAircraft, Qt::QueuedConnection); // DBus
connect(m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::onReadyForModelMatching); connect(m_airspace, &CAirspaceMonitor::readyForModelMatching, this, &CContextNetwork::onReadyForModelMatching); // intentionally NOT QueuedConnection
connect(m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft, Qt::QueuedConnection); connect(m_airspace, &CAirspaceMonitor::addedAircraft, this, &CContextNetwork::addedAircraft, Qt::QueuedConnection);
connect(m_airspace, &CAirspaceMonitor::changedAtisReceived, this, &CContextNetwork::onChangedAtisReceived, Qt::QueuedConnection); connect(m_airspace, &CAirspaceMonitor::changedAtisReceived, this, &CContextNetwork::onChangedAtisReceived, Qt::QueuedConnection);
} }
@@ -121,7 +126,7 @@ namespace BlackCore
void CContextNetwork::setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider) void CContextNetwork::setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider)
{ {
if (m_airspace) { m_airspace->setSimulationEnvironmentProvider(provider); } if (m_airspace) { m_airspace->setSimulationEnvironmentProvider(provider); }
if (m_fsdClient) { m_fsdClient->setSimulationEnvironmentProvider(provider); } if (m_fsdClient) { m_fsdClient->setSimulationEnvironmentProvider(provider); }
} }
@@ -217,8 +222,12 @@ namespace BlackCore
{ {
this->disconnect(); // all signals this->disconnect(); // all signals
if (this->isConnected()) { this->disconnectFromNetwork(); } if (this->isConnected()) { this->disconnectFromNetwork(); }
if (m_fsdClient) { m_fsdClient->setClientProvider(nullptr); } if (m_airspace) { m_airspace->gracefulShutdown(); }
if (m_airspace) { m_airspace->gracefulShutdown(); } if (m_fsdClient)
{
m_fsdClient->gracefulShutdown();
m_fsdClient->setClientProvider(nullptr);
}
} }
CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const CCallsign &partnerCallsign, CLoginMode mode) CStatusMessage CContextNetwork::connectToNetwork(const CServer &server, const QString &extraLiveryString, bool sendLivery, const QString &extraModelString, bool sendModelString, const CCallsign &partnerCallsign, CLoginMode mode)