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:
Klaus Basan
2015-05-28 20:13:03 +02:00
parent eb8b6e6f1f
commit 94eb33d228
7 changed files with 45 additions and 26 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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.