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; }

View File

@@ -2,6 +2,14 @@
<ui version="4.0">
<class>CLogComponent</class>
<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">
<string>Log component</string>
</property>

View File

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

View File

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

View File

@@ -9,8 +9,8 @@
//! \file
#ifndef BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#ifndef BLACKGUI_COMPONENTS_SETTINGSSIMULATORCOMPONENT_H
#define BLACKGUI_COMPONENTS_SETTINGSSIMULATORCOMPONENT_H
#include "blackcore/application/applicationsettings.h"
#include "blackgui/blackguiexport.h"
@@ -27,7 +27,6 @@ class QWidget;
namespace BlackCore { class CPluginManagerSimulator; }
namespace BlackMisc { namespace Simulation { class CSimulatorPluginInfo; } }
namespace Ui { class CSettingsSimulatorComponent; }
namespace BlackGui
{
namespace Components
@@ -89,4 +88,5 @@ namespace BlackGui
};
}
} // namespace
#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 hr;
@@ -337,8 +332,7 @@ namespace BlackSimPlugin
break;
}
}
return S_OK;
}
}
}
} // ns
} // ns

View File

@@ -18,12 +18,11 @@ namespace BlackSimPlugin
void disconnected();
public:
//! Constructor
CLobbyClient(QObject *parent = nullptr);
//! Destructor
~CLobbyClient();
virtual ~CLobbyClient();
//! Initialize DirectPlay
HRESULT initDirectPlay();
@@ -34,11 +33,7 @@ namespace BlackSimPlugin
//! Connect FS9 simulator to our host
HRESULT connectFs9ToHost(const QString address);
//! Cleanup & be ready to another connection
void cleanup();
private:
//! 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 );
@@ -67,6 +62,5 @@ namespace BlackSimPlugin
static const size_t m_maxSizePlayerName = 14;
};
}
}
} // ns
} // ns

View File

@@ -38,7 +38,7 @@ namespace BlackSimPlugin
{
namespace Fs9
{
CAircraftSituation aircraftSituationfromFS9(const MPPositionVelocity &positionVelocity)
CAircraftSituation aircraftSituationFromFS9(const MPPositionVelocity &positionVelocity)
{
CAircraftSituation situation;
@@ -259,6 +259,7 @@ namespace BlackSimPlugin
if (newTransponder.getTransponderMode() != this->m_simTransponder.getTransponderMode())
{
// void
}
// avoid changes of cockpit back to old values due to an outdated read back value
@@ -343,7 +344,7 @@ namespace BlackSimPlugin
{
MPPositionVelocity mpPositionVelocity;
MultiPlayerPacketParser::readMessage(message, mpPositionVelocity);
auto aircraftSituation = aircraftSituationfromFS9(mpPositionVelocity);
auto aircraftSituation = aircraftSituationFromFS9(mpPositionVelocity);
updateOwnSituation(aircraftSituation);
if (m_isWeatherActivated)
@@ -435,7 +436,7 @@ namespace BlackSimPlugin
if (m_isConnecting || m_lobbyClient->connectFs9ToHost(m_fs9Host->getHostAddress()) == S_OK)
{
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<CLobbyClient> m_lobbyClient;
};
} // namespace Fs9
} // namespace BlackCore
} // ns
} // ns
#endif // guard

View File

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

View File

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

View File

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