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