Ref T111, some fixes in the vicinity of plugin / drivers

* mostly style / doxygen / formatting
* assert/verify
This commit is contained in:
Klaus Basan
2017-07-26 13:53:38 +02:00
committed by Mathew Sutcliffe
parent e72546d282
commit 29e1d54e05
16 changed files with 79 additions and 78 deletions

View File

@@ -302,18 +302,23 @@ namespace BlackCore
// Once the simulator signaled it is ready to simulate, add all known aircraft
m_initallyAddAircrafts = true;
m_matchingMessages.clear();
// try to connect to simulator
simulator->connectTo();
const bool connected = simulator->connectTo();
simulator->setWeatherActivated(m_isWeatherActivated);
// when everything is set up connected, update the current plugin info
m_simulatorPlugin.first = simulatorPluginInfo;
m_simulatorPlugin.second = simulator;
//! \fixme KB 7/2017 wonder if it was better to force an Qt::QueuedConnection emit by calling CTimer::singleShot
//! Replace this comment by an info comment after review, or change
emit simulatorPluginChanged(simulatorPluginInfo);
CLogMessage(this).info("Simulator plugin loaded: %1") << simulatorPluginInfo.toQString(true);
CLogMessage(this).info("Simulator plugin loaded: '%1' connected: %2")
<< simulatorPluginInfo.toQString(true)
<< boolToYesNo(connected);
simulator->setWeatherActivated(m_isWeatherActivated);
m_matchingMessages.clear();
return true;
}
@@ -326,7 +331,7 @@ namespace BlackCore
if (!m_listenersThread.isRunning())
{
m_listenersThread.setObjectName("CContextSimulator:Thread for listeners");
m_listenersThread.setObjectName("CContextSimulator: Thread for listener " + simulatorInfo.getIdentifier());
m_listenersThread.start(QThread::LowPriority);
}
@@ -335,14 +340,14 @@ namespace BlackCore
if (listener->thread() != &m_listenersThread)
{
bool c = connect(listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread");
const bool c = connect(listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
if (!c)
{
CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString();
return false;
}
Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread");
listener->setProperty("isInitialized", true);
listener->moveToThread(&m_listenersThread);
}
@@ -549,8 +554,8 @@ namespace BlackCore
if (!m_simulatorPlugin.first.isUnspecified()) { return; }
stopSimulatorListeners();
const auto enabledSimulators = m_enabledSimulators.getThreadLocal();
const auto allSimulators = m_plugins->getAvailableSimulatorPlugins();
const QStringList enabledSimulators = m_enabledSimulators.getThreadLocal();
const CSimulatorPluginInfoList allSimulators = m_plugins->getAvailableSimulatorPlugins();
for (const CSimulatorPluginInfo &s : allSimulators)
{
if (enabledSimulators.contains(s.getIdentifier()))
@@ -664,7 +669,12 @@ namespace BlackCore
for (const auto &info : getAvailableSimulatorPlugins())
{
ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier());
if (listener) { QMetaObject::invokeMethod(listener, "stop"); }
if (listener)
{
const bool s = QMetaObject::invokeMethod(listener, "stop");
Q_ASSERT_X(s, Q_FUNC_INFO, "Cannot invoke stop");
Q_UNUSED(s);
}
}
}

View File

@@ -93,12 +93,9 @@ namespace BlackCore
bool IPluginManager::tryLoad(const QString &path)
{
if (!QLibrary::isLibrary(path))
{
return false;
}
if (!QLibrary::isLibrary(path)) { return false; }
CLogMessage(this).debug() << "Loading plugin: " << path;
CLogMessage(this).debug() << "Try loading plugin:" << path;
QPluginLoader loader(path);
const QJsonObject json = loader.metaData();
if (!isValid(json))

View File

@@ -34,11 +34,7 @@ namespace BlackCore
ISimulatorListener *CPluginManagerSimulator::createListener(const QString &pluginId)
{
if (!m_plugins.contains(pluginId))
{
return nullptr;
}
if (!m_plugins.contains(pluginId)) { return nullptr; }
PluginExtended &plugin = m_plugins[pluginId];
if (!plugin.listener)
{
@@ -60,11 +56,7 @@ namespace BlackCore
ISimulatorListener *CPluginManagerSimulator::getListener(const QString &pluginId)
{
if (!m_plugins.contains(pluginId))
{
return nullptr;
}
if (!m_plugins.contains(pluginId)) { return nullptr; }
PluginExtended &plugin = m_plugins[pluginId];
return plugin.listener;
}

View File

@@ -59,12 +59,17 @@ namespace BlackCore
ISimulator::registerHelp();
}
void ISimulator::emitSimulatorCombinedStatus(int oldStatus)
void ISimulator::emitSimulatorCombinedStatus(SimulatorStatus oldStatus)
{
int newStatus = getSimulatorStatus();
const SimulatorStatus newStatus = getSimulatorStatus();
if (oldStatus != newStatus)
{
emit simulatorStatusChanged(newStatus);
// decouple, follow up of signal can include unloading
// simulator so this should happen asyncronously (which is like forcing Qt::QueuedConnection)
QTimer::singleShot(0, this, [ = ]
{
emit this->simulatorStatusChanged(newStatus);
});
}
}

View File

@@ -248,7 +248,7 @@ namespace BlackCore
CAirportList CSimulatorCommon::getAirportsInRange() const
{
// default implementation
if (!sApp->hasWebDataServices()) { return CAirportList(); }
if (!sApp || !sApp->hasWebDataServices()) { return CAirportList(); }
const CAirportList airports = sApp->getWebDataServices()->getAirports();
if (airports.isEmpty()) { return airports; }