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 // Once the simulator signaled it is ready to simulate, add all known aircraft
m_initallyAddAircrafts = true; m_initallyAddAircrafts = true;
m_matchingMessages.clear();
// try to connect to simulator // 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 // when everything is set up connected, update the current plugin info
m_simulatorPlugin.first = simulatorPluginInfo; m_simulatorPlugin.first = simulatorPluginInfo;
m_simulatorPlugin.second = simulator; 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); 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; return true;
} }
@@ -326,7 +331,7 @@ namespace BlackCore
if (!m_listenersThread.isRunning()) 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); m_listenersThread.start(QThread::LowPriority);
} }
@@ -335,14 +340,14 @@ namespace BlackCore
if (listener->thread() != &m_listenersThread) 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) if (!c)
{ {
CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString(); CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString();
return false; return false;
} }
Q_ASSERT_X(!listener->parent(), Q_FUNC_INFO, "Objects with parent cannot be moved to thread");
listener->setProperty("isInitialized", true); listener->setProperty("isInitialized", true);
listener->moveToThread(&m_listenersThread); listener->moveToThread(&m_listenersThread);
} }
@@ -549,8 +554,8 @@ namespace BlackCore
if (!m_simulatorPlugin.first.isUnspecified()) { return; } if (!m_simulatorPlugin.first.isUnspecified()) { return; }
stopSimulatorListeners(); stopSimulatorListeners();
const auto enabledSimulators = m_enabledSimulators.getThreadLocal(); const QStringList enabledSimulators = m_enabledSimulators.getThreadLocal();
const auto allSimulators = m_plugins->getAvailableSimulatorPlugins(); const CSimulatorPluginInfoList allSimulators = m_plugins->getAvailableSimulatorPlugins();
for (const CSimulatorPluginInfo &s : allSimulators) for (const CSimulatorPluginInfo &s : allSimulators)
{ {
if (enabledSimulators.contains(s.getIdentifier())) if (enabledSimulators.contains(s.getIdentifier()))
@@ -664,7 +669,12 @@ namespace BlackCore
for (const auto &info : getAvailableSimulatorPlugins()) for (const auto &info : getAvailableSimulatorPlugins())
{ {
ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); 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) bool IPluginManager::tryLoad(const QString &path)
{ {
if (!QLibrary::isLibrary(path)) if (!QLibrary::isLibrary(path)) { return false; }
{
return false;
}
CLogMessage(this).debug() << "Loading plugin: " << path; CLogMessage(this).debug() << "Try loading plugin:" << path;
QPluginLoader loader(path); QPluginLoader loader(path);
const QJsonObject json = loader.metaData(); const QJsonObject json = loader.metaData();
if (!isValid(json)) if (!isValid(json))

View File

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

View File

@@ -59,12 +59,17 @@ namespace BlackCore
ISimulator::registerHelp(); ISimulator::registerHelp();
} }
void ISimulator::emitSimulatorCombinedStatus(int oldStatus) void ISimulator::emitSimulatorCombinedStatus(SimulatorStatus oldStatus)
{ {
int newStatus = getSimulatorStatus(); const SimulatorStatus newStatus = getSimulatorStatus();
if (oldStatus != newStatus) 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 CAirportList CSimulatorCommon::getAirportsInRange() const
{ {
// default implementation // default implementation
if (!sApp->hasWebDataServices()) { return CAirportList(); } if (!sApp || !sApp->hasWebDataServices()) { return CAirportList(); }
const CAirportList airports = sApp->getWebDataServices()->getAirports(); const CAirportList airports = sApp->getWebDataServices()->getAirports();
if (airports.isEmpty()) { return airports; } if (airports.isEmpty()) { return airports; }

View File

@@ -2,6 +2,14 @@
<ui version="4.0"> <ui version="4.0">
<class>CLogComponent</class> <class>CLogComponent</class>
<widget class="QFrame" name="CLogComponent"> <widget class="QFrame" name="CLogComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>264</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Log component</string> <string>Log component</string>
</property> </property>

View File

@@ -29,7 +29,6 @@ class QPoint;
class QWidget; class QWidget;
namespace Ui { class CNavigatorDialog; } namespace Ui { class CNavigatorDialog; }
namespace BlackGui namespace BlackGui
{ {
namespace Components namespace Components

View File

@@ -25,6 +25,7 @@
#include "blackmisc/pq/time.h" #include "blackmisc/pq/time.h"
#include "blackmisc/pq/units.h" #include "blackmisc/pq/units.h"
#include "blackmisc/statusmessage.h" #include "blackmisc/statusmessage.h"
#include "blackmisc/verify.h"
#include "ui_settingssimulatorcomponent.h" #include "ui_settingssimulatorcomponent.h"
#include <QApplication> #include <QApplication>
@@ -146,7 +147,7 @@ namespace BlackGui
void CSettingsSimulatorComponent::ps_pluginStateChanged(const QString &identifier, bool enabled) void CSettingsSimulatorComponent::ps_pluginStateChanged(const QString &identifier, bool enabled)
{ {
Q_ASSERT(sGui->getIContextSimulator()); Q_ASSERT(sGui && sGui->getIContextSimulator());
const CSimulatorPluginInfoList simDrivers(getAvailablePlugins()); const CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier); const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier);
@@ -156,18 +157,22 @@ namespace BlackGui
return; return;
} }
QStringList e = m_enabledSimulators.getThreadLocal(); QStringList e = m_enabledSimulators.getThreadLocal(); // from setting
if (enabled != e.contains(selected.getIdentifier())) if (enabled != e.contains(selected.getIdentifier()))
{ {
if (enabled) if (enabled)
{ {
e << selected.getIdentifier(); e << selected.getIdentifier(); // add enabled plugin
} }
else else
{ {
e.removeAll(selected.getIdentifier()); e.removeAll(selected.getIdentifier());
} }
m_enabledSimulators.set(e); const CStatusMessage msg = m_enabledSimulators.set(e); // change setting
if (msg.isWarningOrAbove())
{
CLogMessage::preformatted(msg);
}
} }
// changing of GUI state will be done via received signal // changing of GUI state will be done via received signal
@@ -234,7 +239,7 @@ namespace BlackGui
void CSettingsSimulatorComponent::ps_onApplyTimeSync() void CSettingsSimulatorComponent::ps_onApplyTimeSync()
{ {
bool timeSync = ui->cb_TimeSync->isChecked(); const bool timeSync = ui->cb_TimeSync->isChecked();
const QString os = ui->le_TimeSyncOffset->text(); const QString os = ui->le_TimeSyncOffset->text();
CTime ost(0, CTimeUnit::hrmin()); CTime ost(0, CTimeUnit::hrmin());
if (!os.isEmpty()) if (!os.isEmpty())
@@ -284,8 +289,12 @@ namespace BlackGui
const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier); const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier);
QWidget *aw = qApp->activeWindow(); QWidget *aw = qApp->activeWindow();
Q_ASSERT_X(aw, Q_FUNC_INFO, "Missing active window");
CPluginDetailsWindow *w = new CPluginDetailsWindow(aw); CPluginDetailsWindow *w = new CPluginDetailsWindow(aw);
BLACK_VERIFY_X(w, Q_FUNC_INFO, "Missing window");
if (!w) { return; }
w->setAttribute(Qt::WA_DeleteOnClose); w->setAttribute(Qt::WA_DeleteOnClose);
w->setPluginIdentifier(selected.getIdentifier()); w->setPluginIdentifier(selected.getIdentifier());
w->setPluginName(selected.getName()); w->setPluginName(selected.getName());
@@ -301,12 +310,13 @@ namespace BlackGui
const QString configId = m_plugins->getPluginConfigId(selected.getIdentifier()); const QString configId = m_plugins->getPluginConfigId(selected.getIdentifier());
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId); IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
if (!config) BLACK_VERIFY_X(config, Q_FUNC_INFO, "Missing config");
{ if (!config) { return; }
return;
}
CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow()); CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow());
BLACK_VERIFY_X(window, Q_FUNC_INFO, "Missing window");
if (!window) { return; }
window->setAttribute(Qt::WA_DeleteOnClose); window->setAttribute(Qt::WA_DeleteOnClose);
window->show(); window->show();
} }

View File

@@ -9,8 +9,8 @@
//! \file //! \file
#ifndef BLACKGUI_SETTINGSSIMULATORCOMPONENT_H #ifndef BLACKGUI_COMPONENTS_SETTINGSSIMULATORCOMPONENT_H
#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H #define BLACKGUI_COMPONENTS_SETTINGSSIMULATORCOMPONENT_H
#include "blackcore/application/applicationsettings.h" #include "blackcore/application/applicationsettings.h"
#include "blackgui/blackguiexport.h" #include "blackgui/blackguiexport.h"
@@ -27,7 +27,6 @@ class QWidget;
namespace BlackCore { class CPluginManagerSimulator; } namespace BlackCore { class CPluginManagerSimulator; }
namespace BlackMisc { namespace Simulation { class CSimulatorPluginInfo; } } namespace BlackMisc { namespace Simulation { class CSimulatorPluginInfo; } }
namespace Ui { class CSettingsSimulatorComponent; } namespace Ui { class CSettingsSimulatorComponent; }
namespace BlackGui namespace BlackGui
{ {
namespace Components namespace Components
@@ -89,4 +88,5 @@ namespace BlackGui
}; };
} }
} // namespace } // namespace
#endif // guard #endif // guard

View File

@@ -153,11 +153,6 @@ namespace BlackSimPlugin
} }
} }
void CLobbyClient::cleanup()
{
}
HRESULT CLobbyClient::allocAndInitConnectSettings(const QString &address, GUID *pAppGuid, DPL_CONNECTION_SETTINGS **ppdplConnectSettings) HRESULT CLobbyClient::allocAndInitConnectSettings(const QString &address, GUID *pAppGuid, DPL_CONNECTION_SETTINGS **ppdplConnectSettings)
{ {
HRESULT hr; HRESULT hr;
@@ -337,8 +332,7 @@ namespace BlackSimPlugin
break; break;
} }
} }
return S_OK; return S_OK;
} }
} } // ns
} } // ns

View File

@@ -18,12 +18,11 @@ namespace BlackSimPlugin
void disconnected(); void disconnected();
public: public:
//! Constructor //! Constructor
CLobbyClient(QObject *parent = nullptr); CLobbyClient(QObject *parent = nullptr);
//! Destructor //! Destructor
~CLobbyClient(); virtual ~CLobbyClient();
//! Initialize DirectPlay //! Initialize DirectPlay
HRESULT initDirectPlay(); HRESULT initDirectPlay();
@@ -34,11 +33,7 @@ namespace BlackSimPlugin
//! Connect FS9 simulator to our host //! Connect FS9 simulator to our host
HRESULT connectFs9ToHost(const QString address); HRESULT connectFs9ToHost(const QString address);
//! Cleanup & be ready to another connection
void cleanup();
private: private:
//! Alloc and fill up a DPL_CONNECTION_SETTINGS. Call FreeConnectSettings later to free it. //! Alloc and fill up a DPL_CONNECTION_SETTINGS. Call FreeConnectSettings later to free it.
HRESULT allocAndInitConnectSettings(const QString &address, GUID* pAppGuid, DPL_CONNECTION_SETTINGS** ppdplConnectSettings ); HRESULT allocAndInitConnectSettings(const QString &address, GUID* pAppGuid, DPL_CONNECTION_SETTINGS** ppdplConnectSettings );
@@ -67,6 +62,5 @@ namespace BlackSimPlugin
static const size_t m_maxSizePlayerName = 14; static const size_t m_maxSizePlayerName = 14;
}; };
} // ns
} } // ns
}

View File

@@ -38,7 +38,7 @@ namespace BlackSimPlugin
{ {
namespace Fs9 namespace Fs9
{ {
CAircraftSituation aircraftSituationfromFS9(const MPPositionVelocity &positionVelocity) CAircraftSituation aircraftSituationFromFS9(const MPPositionVelocity &positionVelocity)
{ {
CAircraftSituation situation; CAircraftSituation situation;
@@ -259,6 +259,7 @@ namespace BlackSimPlugin
if (newTransponder.getTransponderMode() != this->m_simTransponder.getTransponderMode()) if (newTransponder.getTransponderMode() != this->m_simTransponder.getTransponderMode())
{ {
// void
} }
// avoid changes of cockpit back to old values due to an outdated read back value // avoid changes of cockpit back to old values due to an outdated read back value
@@ -343,7 +344,7 @@ namespace BlackSimPlugin
{ {
MPPositionVelocity mpPositionVelocity; MPPositionVelocity mpPositionVelocity;
MultiPlayerPacketParser::readMessage(message, mpPositionVelocity); MultiPlayerPacketParser::readMessage(message, mpPositionVelocity);
auto aircraftSituation = aircraftSituationfromFS9(mpPositionVelocity); auto aircraftSituation = aircraftSituationFromFS9(mpPositionVelocity);
updateOwnSituation(aircraftSituation); updateOwnSituation(aircraftSituation);
if (m_isWeatherActivated) if (m_isWeatherActivated)
@@ -435,7 +436,7 @@ namespace BlackSimPlugin
if (m_isConnecting || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK) if (m_isConnecting || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK)
{ {
m_isConnecting = true; m_isConnecting = true;
CLogMessage(this).info("Swift is joining FS9 to the multiplayer session..."); CLogMessage(this).info("swift is joining FS9 to the multiplayer session...");
} }
} }

View File

@@ -160,7 +160,7 @@ namespace BlackSimPlugin
QSharedPointer<CFs9Host> m_fs9Host; QSharedPointer<CFs9Host> m_fs9Host;
QSharedPointer<CLobbyClient> m_lobbyClient; QSharedPointer<CLobbyClient> m_lobbyClient;
}; };
} // namespace Fs9 } // ns
} // namespace BlackCore } // ns
#endif // guard #endif // guard

View File

@@ -10,7 +10,6 @@
#include "simulatorfsxfactory.h" #include "simulatorfsxfactory.h"
#include "simulatorfsx.h" #include "simulatorfsx.h"
#include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfo.h"
#include <QTimer>
namespace BlackSimPlugin namespace BlackSimPlugin
{ {

View File

@@ -10,16 +10,15 @@
#include "simulatorp3dfactory.h" #include "simulatorp3dfactory.h"
#include "simulatorp3d.h" #include "simulatorp3d.h"
#include "blackmisc/simulation/simulatorplugininfo.h" #include "blackmisc/simulation/simulatorplugininfo.h"
#include <QTimer>
namespace BlackSimPlugin namespace BlackSimPlugin
{ {
namespace P3D namespace P3D
{ {
BlackCore::ISimulator *CSimulatorP3DFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackCore::ISimulator *CSimulatorP3DFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider) BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider)
{ {
Q_ASSERT(ownAircraftProvider); Q_ASSERT(ownAircraftProvider);
return new CSimulatorP3D(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, this); return new CSimulatorP3D(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, this);
@@ -29,6 +28,5 @@ namespace BlackSimPlugin
{ {
return new CSimulatorP3DListener(info); return new CSimulatorP3DListener(info);
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -32,9 +32,6 @@ using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo; using namespace BlackMisc::Geo;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
/*
* Load own aircraft
*/
bool SwiftGuiStd::ps_reloadOwnAircraft() bool SwiftGuiStd::ps_reloadOwnAircraft()
{ {
if (!this->isContextNetworkAvailableCheck()) { return false; } if (!this->isContextNetworkAvailableCheck()) { return false; }
@@ -50,9 +47,6 @@ bool SwiftGuiStd::ps_reloadOwnAircraft()
return changed; return changed;
} }
/*
* Position
*/
void SwiftGuiStd::setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const CAltitude &altitude) void SwiftGuiStd::setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const CAltitude &altitude)
{ {
CCoordinateGeodetic coordinate( CCoordinateGeodetic coordinate(