mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #431, infinite recursion in driver unload
* Trivial changes to avoid changedStatus signal when nothing changed * Do not reload plugin when already loaded
This commit is contained in:
@@ -35,6 +35,7 @@ namespace BlackCore
|
||||
IContextSimulator(mode, runtime),
|
||||
m_mapper(new QSignalMapper(this))
|
||||
{
|
||||
this->setObjectName("CContextSimulator");
|
||||
findSimulatorPlugins();
|
||||
// Maps listener instance
|
||||
connect(m_mapper, static_cast<void (QSignalMapper::*)(QObject *)>(&QSignalMapper::mapped), this, &CContextSimulator::ps_simulatorStarted);
|
||||
@@ -363,6 +364,12 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the plugin already loaded?
|
||||
if (m_simulatorPlugin && m_simulatorPlugin->info == simulatorInfo)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
|
||||
@@ -416,6 +423,7 @@ namespace BlackCore
|
||||
settingsChanged(static_cast<uint>(IContextSettings::SettingsSimulator));
|
||||
|
||||
// try to connect
|
||||
//! \todo #417: we want to change this to connectTo, as the listener already checks the avialability of the simulator
|
||||
m_simulatorPlugin->simulator->asyncConnectTo();
|
||||
|
||||
if (m_simulatorPlugin) // can be already nullptr if connectTo() is synchronous and fails
|
||||
@@ -541,25 +549,24 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::unloadSimulatorPlugin()
|
||||
{
|
||||
if (m_simulatorPlugin)
|
||||
{
|
||||
// depending on shutdown order, network might already have been deleted
|
||||
emit simulatorPluginChanged(CSimulatorPluginInfo());
|
||||
if (!m_simulatorPlugin) { return; }
|
||||
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
Q_ASSERT(this->getIContextNetwork()->isLocalObject());
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
// depending on shutdown order, network might already have been deleted
|
||||
emit simulatorPluginChanged(CSimulatorPluginInfo());
|
||||
|
||||
// unload and disconnect
|
||||
m_simulatorPlugin->simulator->unload();
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
Q_ASSERT(this->getIContextNetwork()->isLocalObject());
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
|
||||
// disconnect signals
|
||||
this->disconnect(m_simulatorPlugin->simulator);
|
||||
// unload and disconnect
|
||||
m_simulatorPlugin->simulator->unload();
|
||||
|
||||
m_simulatorPlugin->simulator->deleteLater();
|
||||
m_simulatorPlugin->simulator = nullptr;
|
||||
m_simulatorPlugin = nullptr;
|
||||
}
|
||||
// disconnect signals
|
||||
this->disconnect(m_simulatorPlugin->simulator);
|
||||
|
||||
m_simulatorPlugin->simulator->deleteLater();
|
||||
m_simulatorPlugin->simulator = nullptr;
|
||||
m_simulatorPlugin = nullptr;
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
|
||||
@@ -45,9 +45,13 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void ISimulator::emitSimulatorCombinedStatus()
|
||||
void ISimulator::emitSimulatorCombinedStatus(int oldStatus)
|
||||
{
|
||||
emit simulatorStatusChanged(getSimulatorStatus());
|
||||
int newStatus = getSimulatorStatus();
|
||||
if (oldStatus != newStatus)
|
||||
{
|
||||
emit simulatorStatusChanged(newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace BlackCore
|
||||
|
||||
//! Interface to a simulator.
|
||||
class BLACKCORE_EXPORT ISimulator :
|
||||
public QObject,
|
||||
public BlackMisc::COriginatorAware
|
||||
public QObject,
|
||||
public BlackMisc::COriginatorAware
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace BlackCore
|
||||
virtual bool connectTo() = 0;
|
||||
|
||||
//! Connect asynchronously to simulator
|
||||
//! \deprecated #417
|
||||
virtual void asyncConnectTo() = 0;
|
||||
|
||||
//! Disconnect from simulator
|
||||
@@ -226,8 +227,9 @@ namespace BlackCore
|
||||
virtual int physicallyRemoveAllRemoteAircraft() = 0;
|
||||
|
||||
//! Emit the combined status
|
||||
//! \param oldStatus optionally one can capture and provide the old status for comparison. In case of equal status values no signal will be sent
|
||||
//! \sa simulatorStatusChanged;
|
||||
void emitSimulatorCombinedStatus();
|
||||
void emitSimulatorCombinedStatus(int oldStatus = -1);
|
||||
};
|
||||
|
||||
//! Interface to a simulator listener.
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorFs9::disconnectFrom()
|
||||
{
|
||||
if (!m_simConnected) return true;
|
||||
if (!m_simConnected) { return true; }
|
||||
|
||||
// Don't forward messages when disconnected
|
||||
disconnect(m_connectionHostMessages);
|
||||
|
||||
@@ -80,12 +80,13 @@ namespace BlackSimPlugin
|
||||
bool CSimulatorFsx::connectTo()
|
||||
{
|
||||
if (m_simConnected) { return true; }
|
||||
int oldStatus = getSimulatorStatus();
|
||||
if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0)))
|
||||
{
|
||||
m_simConnected = false;
|
||||
m_simPaused = false;
|
||||
m_simSimulating = false;
|
||||
emitSimulatorCombinedStatus();
|
||||
emitSimulatorCombinedStatus(oldStatus);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -96,7 +97,7 @@ namespace BlackSimPlugin
|
||||
initWhenConnected();
|
||||
m_simconnectTimerId = startTimer(10);
|
||||
m_simConnected = true;
|
||||
emitSimulatorCombinedStatus();
|
||||
emitSimulatorCombinedStatus(oldStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -352,8 +353,9 @@ namespace BlackSimPlugin
|
||||
|
||||
void CSimulatorFsx::onSimStopped()
|
||||
{
|
||||
int oldStatus = getSimulatorStatus();
|
||||
m_simSimulating = false;
|
||||
emitSimulatorCombinedStatus();
|
||||
emitSimulatorCombinedStatus(oldStatus);
|
||||
}
|
||||
|
||||
void CSimulatorFsx::onSimFrame()
|
||||
|
||||
@@ -84,8 +84,11 @@ namespace BlackSimPlugin
|
||||
case SystemEventPause:
|
||||
{
|
||||
bool p = event->dwData ? true : false;
|
||||
simulatorFsx->m_simPaused = p;
|
||||
simulatorFsx->emitSimulatorCombinedStatus();
|
||||
if (simulatorFsx->m_simPaused != p)
|
||||
{
|
||||
simulatorFsx->m_simPaused = p;
|
||||
simulatorFsx->emitSimulatorCombinedStatus();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -193,6 +193,7 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorXPlane::disconnectFrom()
|
||||
{
|
||||
if (!this->isConnected()) { return true; } // avoid emit if already disconnected
|
||||
if (m_traffic)
|
||||
{
|
||||
m_traffic->cleanup();
|
||||
|
||||
Reference in New Issue
Block a user