mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Remove ISimulator::getSimulatorInfo()
To provide maximum flexibility, the simulator info is specified by each plugin in the JSON metadata file. * Renamed SCimulatorInfo to CSimulatorPluginInfo * Removed pre-defined simulator infos (UnspecifiedSim, FSX, etc) * CContextSimulator keeps track of which plugin is loaded and its info * QSignalMapper keeps track of which listener emitted the simulatorStared() signal * CSimulatorPluginInfo contains name, simulator name and description * TODO: GUI part * TODO: CTestFsCommon
This commit is contained in:
committed by
Roland Winklmeier
parent
3897fb2d1a
commit
63e48ae332
@@ -185,7 +185,7 @@ namespace BlackCore
|
||||
}
|
||||
else
|
||||
{
|
||||
this->m_network->presetSimulatorInfo(CSimulatorInfo::UnspecifiedSim());
|
||||
this->m_network->presetSimulatorInfo(CSimulatorPluginInfo());
|
||||
}
|
||||
this->m_network->initiateConnection();
|
||||
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort()));
|
||||
|
||||
@@ -178,6 +178,21 @@ namespace BlackCore
|
||||
c = connect(this->m_contextNetwork, &IContextNetwork::textMessagesReceived,
|
||||
this->getCContextSimulator(), &CContextSimulator::ps_textMessagesReceived);
|
||||
Q_ASSERT(c);
|
||||
|
||||
// use readyForModelMatching instead of CAirspaceMonitor::addedAircraft, as it contains client information
|
||||
// ready for model matching is sent delayed when all information are available
|
||||
c = connect(this->m_contextNetwork, &IContextNetwork::readyForModelMatching,
|
||||
this->getCContextSimulator(), &CContextSimulator::ps_addRemoteAircraft);
|
||||
Q_ASSERT(c);
|
||||
c = connect(this->m_contextNetwork, &IContextNetwork::removedAircraft,
|
||||
this->getCContextSimulator(), &CContextSimulator::ps_removedRemoteAircraft);
|
||||
Q_ASSERT(c);
|
||||
c = connect(this->m_contextNetwork, &IContextNetwork::changedRemoteAircraftModel,
|
||||
this->getCContextSimulator(), &CContextSimulator::ps_changedRemoteAircraftModel);
|
||||
Q_ASSERT(c);
|
||||
c = connect(this->m_contextNetwork, &IContextNetwork::changedRemoteAircraftEnabled,
|
||||
this->getCContextSimulator(), &CContextSimulator::ps_changedRemoteAircraftEnabled);
|
||||
Q_ASSERT(c);
|
||||
}
|
||||
|
||||
// only if own aircraft runs locally
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "blackcore/dbus_server.h"
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blacksim/simulatorplugininfo.h"
|
||||
#include "blacksim/simulatorinfolist.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
@@ -86,7 +86,7 @@ namespace BlackCore
|
||||
public slots:
|
||||
|
||||
//! Return list of available simulator plugins
|
||||
virtual BlackSim::CSimulatorInfoList getAvailableSimulatorPlugins() const = 0;
|
||||
virtual BlackSim::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const = 0;
|
||||
|
||||
//! Returns true when simulator is connected
|
||||
//! \sa isSimulating
|
||||
@@ -108,7 +108,7 @@ namespace BlackCore
|
||||
virtual bool isSimulating() const = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
virtual BlackSim::CSimulatorPluginInfo getSimulatorInfo() const = 0;
|
||||
|
||||
//! Airports in range
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const = 0;
|
||||
@@ -163,13 +163,13 @@ namespace BlackCore
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0;
|
||||
|
||||
//! Load specific simulator plugin
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) = 0;
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Load specific simulator plugin as set in settings
|
||||
virtual bool loadSimulatorPluginFromSettings() = 0;
|
||||
|
||||
//! Listen for the specific simulator to start, load plugin automatically
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) = 0;
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Listen for all available simulators
|
||||
virtual void listenForAllSimulators() = 0;
|
||||
|
||||
@@ -31,10 +31,12 @@ using namespace BlackSim::Settings;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CContextSimulator::CContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : IContextSimulator(mode, runtime)
|
||||
CContextSimulator::CContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
IContextSimulator(mode, runtime),
|
||||
m_mapper(new QSignalMapper(this))
|
||||
{
|
||||
findSimulatorPlugins();
|
||||
|
||||
connect(m_mapper, static_cast<void (QSignalMapper::*)(QObject *)>(&QSignalMapper::mapped), this, &CContextSimulator::ps_simulatorStarted);
|
||||
// do not load plugin here, as it depends on settings
|
||||
// it has to be guaranteed the settings are alredy loaded
|
||||
}
|
||||
@@ -45,21 +47,22 @@ namespace BlackCore
|
||||
unloadSimulatorPlugin();
|
||||
}
|
||||
|
||||
ISimulatorFactory *CContextSimulator::getSimulatorFactory(const CSimulatorInfo &simulator)
|
||||
ISimulatorFactory *CContextSimulator::getSimulatorFactory(const CSimulatorPluginInfo &simulator)
|
||||
{
|
||||
if (!m_simulatorDrivers.contains(simulator))
|
||||
PluginData *plugin = findPlugin(simulator);
|
||||
if (!plugin)
|
||||
return nullptr;
|
||||
|
||||
DriverInfo& driver = m_simulatorDrivers[simulator];
|
||||
if (!driver.factory) {
|
||||
QPluginLoader loader(driver.fileName);
|
||||
QObject *plugin = loader.instance();
|
||||
if (plugin)
|
||||
if (!plugin->factory)
|
||||
{
|
||||
QPluginLoader loader(plugin->fileName);
|
||||
QObject *instance = loader.instance();
|
||||
if (instance)
|
||||
{
|
||||
ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(plugin);
|
||||
ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(instance);
|
||||
if (factory)
|
||||
{
|
||||
driver.factory = factory;
|
||||
plugin->factory = factory;
|
||||
CLogMessage(this).debug() << "Loaded plugin: " << plugin->info.toQString();
|
||||
}
|
||||
} else {
|
||||
@@ -68,16 +71,16 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
return driver.factory;
|
||||
return plugin->factory;
|
||||
}
|
||||
|
||||
CSimulatorInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
||||
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
||||
{
|
||||
CSimulatorInfoList list;
|
||||
auto keys = m_simulatorDrivers.keys();
|
||||
|
||||
std::for_each(keys.begin(), keys.end(), [&list](const CSimulatorInfo& driver) {
|
||||
list.push_back(driver);
|
||||
CSimulatorPluginInfoList list;
|
||||
|
||||
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&list](const PluginData &driver)
|
||||
{
|
||||
list.push_back(driver.info);
|
||||
});
|
||||
|
||||
return list;
|
||||
@@ -85,62 +88,97 @@ namespace BlackCore
|
||||
|
||||
bool CContextSimulator::isConnected() const
|
||||
{
|
||||
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return false;
|
||||
return m_simulator->isConnected();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->isConnected();
|
||||
}
|
||||
|
||||
bool CContextSimulator::canConnect() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return false;
|
||||
return m_simulator->canConnect();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->canConnect();
|
||||
}
|
||||
|
||||
bool CContextSimulator::connectToSimulator()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return false;
|
||||
return m_simulator->connectTo();
|
||||
if (!m_simulator)
|
||||
return false;
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->connectTo();
|
||||
}
|
||||
|
||||
void CContextSimulator::asyncConnectToSimulator()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator || m_canConnectResult.isRunning()) return; // already checking
|
||||
m_simulator->asyncConnectTo();
|
||||
if (!m_simulator || m_canConnectResult.isRunning())
|
||||
return; // already checking
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
m_simulator->simulator->asyncConnectTo();
|
||||
}
|
||||
|
||||
bool CContextSimulator::disconnectFromSimulator()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return false;
|
||||
return m_simulator->disconnectFrom();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->disconnectFrom();
|
||||
}
|
||||
|
||||
BlackSim::CSimulatorInfo CContextSimulator::getSimulatorInfo() const
|
||||
BlackSim::CSimulatorPluginInfo CContextSimulator::getSimulatorInfo() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return BlackSim::CSimulatorInfo::UnspecifiedSim();
|
||||
return m_simulator->getSimulatorInfo();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return BlackSim::CSimulatorPluginInfo();
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->info;
|
||||
}
|
||||
|
||||
CAirportList CContextSimulator::getAirportsInRange() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAirportList(); }
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CAirportList();
|
||||
}
|
||||
|
||||
return this->m_simulator->getAirportsInRange();
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->getAirportsInRange();
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulator::getInstalledModels() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
// If no ISimulator object is available, return a dummy.
|
||||
if (!m_simulator) { return CAircraftModelList(); }
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CAircraftModelList();
|
||||
}
|
||||
|
||||
return this->m_simulator->getInstalledModels();
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->getInstalledModels();
|
||||
}
|
||||
|
||||
int CContextSimulator::getInstalledModelsCount() const
|
||||
@@ -148,87 +186,125 @@ namespace BlackCore
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) { return 0; }
|
||||
|
||||
return this->m_simulator->getInstalledModels().size();
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return this->m_simulator->simulator->getInstalledModels().size();
|
||||
}
|
||||
|
||||
CAircraftModelList CContextSimulator::getInstalledModelsStartingWith(const QString modelString) const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << modelString; }
|
||||
if (!m_simulator) { return CAircraftModelList(); }
|
||||
return this->m_simulator->getInstalledModels().findModelsStartingWith(modelString);
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CAircraftModelList();
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->getInstalledModels().findModelsStartingWith(modelString);
|
||||
}
|
||||
|
||||
void CContextSimulator::reloadInstalledModels()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) { return; }
|
||||
if (!m_simulator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
m_simulator->reloadInstalledModels();
|
||||
}
|
||||
|
||||
CAircraftIcao CContextSimulator::getIcaoForModelString(const QString &modelString) const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << modelString; }
|
||||
if (!m_simulator) { return CAircraftIcao(); }
|
||||
return this->m_simulator->getIcaoForModelString(modelString);
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CAircraftIcao();
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->getIcaoForModelString(modelString);
|
||||
}
|
||||
|
||||
bool CContextSimulator::setTimeSynchronization(bool enable, CTime offset)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) { return false; }
|
||||
bool c = this->m_simulator->setTimeSynchronization(enable, offset);
|
||||
if (!c) { return false; }
|
||||
if (enable)
|
||||
if (!m_simulator)
|
||||
{
|
||||
CLogMessage(this).info("Set time syncronization to %1") << offset.toQString();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
bool c = m_simulator->simulator->setTimeSynchronization(enable, offset);
|
||||
if (!c)
|
||||
{
|
||||
CLogMessage(this).info("Disabled time syncronization %1");
|
||||
return false;
|
||||
}
|
||||
|
||||
CLogMessage(this).info(enable ? QStringLiteral("Set time syncronization to %1").arg(offset.toQString()) : QStringLiteral("Disabled time syncrhonization"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CContextSimulator::isTimeSynchronized() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return false;
|
||||
return this->m_simulator->isTimeSynchronized();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->isTimeSynchronized();
|
||||
}
|
||||
|
||||
int CContextSimulator::getMaxRenderedAircraft() const
|
||||
{
|
||||
if (m_debugEnabled) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return 0;
|
||||
return m_simulator->getMaxRenderedAircraft();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->getMaxRenderedAircraft();
|
||||
}
|
||||
|
||||
void CContextSimulator::setMaxRenderedAircraft(int number)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << number; }
|
||||
if (m_simulator) { this->m_simulator->setMaxRenderedAircraft(number); }
|
||||
|
||||
if (m_simulator)
|
||||
{
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
m_simulator->simulator->setMaxRenderedAircraft(number);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::setMaxRenderedDistance(CLength &distance)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << distance; }
|
||||
if (m_simulator) { this->m_simulator->setMaxRenderedDistance(distance); }
|
||||
if (m_simulator)
|
||||
{
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
this->m_simulator->simulator->setMaxRenderedDistance(distance);
|
||||
}
|
||||
}
|
||||
|
||||
QString CContextSimulator::getRenderRestrictionText() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) { return ""; }
|
||||
if (!m_simulator->isRenderingRestricted()) { return "none"; }
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
if (!m_simulator->simulator->isRenderingRestricted()) { return "none"; }
|
||||
QString rt;
|
||||
if (m_simulator->isMaxAircraftRestricted())
|
||||
if (m_simulator->simulator->isMaxAircraftRestricted())
|
||||
{
|
||||
rt.append(QString::number(m_simulator->getMaxRenderedAircraft())).append(" A/C");
|
||||
rt.append(QString::number(m_simulator->simulator->getMaxRenderedAircraft())).append(" A/C");
|
||||
}
|
||||
if (m_simulator->isMaxDistanceRestricted())
|
||||
if (m_simulator->simulator->isMaxDistanceRestricted())
|
||||
{
|
||||
if (!rt.isEmpty()) { rt.append(" ");}
|
||||
rt.append(m_simulator->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0));
|
||||
rt.append(m_simulator->simulator->getMaxRenderedDistance().valueRoundedWithUnit(CLengthUnit::NM(), 0));
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
@@ -236,57 +312,70 @@ namespace BlackCore
|
||||
CLength CContextSimulator::getMaxRenderedDistance() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (m_simulator) { return this->m_simulator->getMaxRenderedDistance(); }
|
||||
return CLength(0, CLengthUnit::nullUnit());
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CLength(0, CLengthUnit::nullUnit());
|
||||
}
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return this->m_simulator->simulator->getMaxRenderedDistance();
|
||||
}
|
||||
|
||||
CLength CContextSimulator::getRenderedDistanceBoundary() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (m_simulator) { return this->m_simulator->getRenderedDistanceBoundary(); }
|
||||
return CLength(20.0, CLengthUnit::NM());
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CLength(20.0, CLengthUnit::NM());
|
||||
}
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return this->m_simulator->simulator->getRenderedDistanceBoundary();
|
||||
}
|
||||
|
||||
void CContextSimulator::deleteAllRenderingRestrictions()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (m_simulator) { this->m_simulator->deleteAllRenderingRestrictions(); }
|
||||
if (m_simulator)
|
||||
{
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
this->m_simulator->simulator->deleteAllRenderingRestrictions();
|
||||
}
|
||||
}
|
||||
|
||||
bool CContextSimulator::isRenderingRestricted() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (m_simulator) { return this->m_simulator->isRenderingRestricted(); }
|
||||
return false;
|
||||
if (!m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return this->m_simulator->simulator->isRenderingRestricted();
|
||||
}
|
||||
|
||||
CTime CContextSimulator::getTimeSynchronizationOffset() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulator) return CTime(0, CTimeUnit::hrmin());
|
||||
return this->m_simulator->getTimeSynchronizationOffset();
|
||||
if (!m_simulator)
|
||||
{
|
||||
return CTime(0, CTimeUnit::hrmin());
|
||||
}
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return this->m_simulator->simulator->getTimeSynchronizationOffset();
|
||||
}
|
||||
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
Q_ASSERT(this->getIContextApplication());
|
||||
Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject());
|
||||
|
||||
if (this->m_simulator && this->m_simulator->getSimulatorInfo() == simulatorInfo) {
|
||||
return true;
|
||||
} // already loaded
|
||||
|
||||
/* TODO Specify behaviour below (maybe assert?) */
|
||||
if (simulatorInfo.isUnspecified()) {
|
||||
return false;
|
||||
}
|
||||
Q_ASSERT(getIContextApplication());
|
||||
Q_ASSERT(getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
|
||||
// warning if we do not have any plugins
|
||||
if (m_simulatorDrivers.isEmpty()) {
|
||||
if (m_simulatorPlugins.isEmpty())
|
||||
{
|
||||
CLogMessage(this).error("No simulator plugins");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
|
||||
@@ -299,44 +388,35 @@ namespace BlackCore
|
||||
ISimulator *newSimulator = factory->create(ownAircraftProvider, renderedAircraftProvider, this);
|
||||
Q_ASSERT(newSimulator);
|
||||
|
||||
this->unloadSimulatorPlugin(); // old plugin unloaded
|
||||
m_simulator = newSimulator;
|
||||
unloadSimulatorPlugin(); // old plugin unloaded
|
||||
|
||||
connect(m_simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
|
||||
connect(m_simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||
connect(m_simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted);
|
||||
connect(m_simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged);
|
||||
connect(m_simulator, &ISimulator::restrictedRenderingChanged, this, &IContextSimulator::restrictedRenderingChanged);
|
||||
PluginData* plugin = findPlugin(simulatorInfo);
|
||||
plugin->simulator = newSimulator;
|
||||
m_simulator = plugin;
|
||||
|
||||
connect(m_simulator->simulator, &ISimulator::simulatorStatusChanged, this, &CContextSimulator::ps_onSimulatorStatusChanged);
|
||||
connect(m_simulator->simulator, &ISimulator::ownAircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||
connect(m_simulator->simulator, &ISimulator::modelMatchingCompleted, this, &IContextSimulator::modelMatchingCompleted);
|
||||
connect(m_simulator->simulator, &ISimulator::installedAircraftModelsChanged, this, &IContextSimulator::installedAircraftModelsChanged);
|
||||
connect(m_simulator->simulator, &ISimulator::restrictedRenderingChanged, this, &IContextSimulator::restrictedRenderingChanged);
|
||||
|
||||
// log from context to simulator
|
||||
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator, &ISimulator::displayStatusMessage);
|
||||
connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, m_simulator, &ISimulator::displayStatusMessage);
|
||||
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator->simulator, &ISimulator::displayStatusMessage);
|
||||
connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged,m_simulator->simulator, &ISimulator::displayStatusMessage);
|
||||
|
||||
// connect with network
|
||||
IContextNetwork *networkContext = this->getIContextNetwork();
|
||||
Q_ASSERT(networkContext);
|
||||
Q_ASSERT(networkContext->isLocalObject());
|
||||
|
||||
// use readyForModelMatching instead of CAirspaceMonitor::addedAircraft, as it contains client information
|
||||
// ready for model matching is sent delayed when all information are available
|
||||
bool c = connect(networkContext, &IContextNetwork::readyForModelMatching, this, &CContextSimulator::ps_addRemoteAircraft);
|
||||
Q_ASSERT(c);
|
||||
c = connect(networkContext, &IContextNetwork::removedAircraft, this, &CContextSimulator::ps_removedRemoteAircraft);
|
||||
Q_ASSERT(c);
|
||||
c = connect(networkContext, &IContextNetwork::changedRemoteAircraftModel, this, &CContextSimulator::ps_changedRemoteAircraftModel);
|
||||
Q_ASSERT(c);
|
||||
c = connect(networkContext, &IContextNetwork::changedRemoteAircraftEnabled, this, &CContextSimulator::ps_changedRemoteAircraftEnabled);
|
||||
Q_ASSERT(c);
|
||||
Q_UNUSED(c);
|
||||
|
||||
for (const CSimulatedAircraft &simAircraft : networkContext->getAircraftInRange())
|
||||
{
|
||||
Q_ASSERT(!simAircraft.getCallsign().isEmpty());
|
||||
m_simulator->addRemoteAircraft(simAircraft);
|
||||
m_simulator->simulator->addRemoteAircraft(simAircraft);
|
||||
}
|
||||
|
||||
// apply latest settings
|
||||
this->settingsChanged(static_cast<uint>(IContextSettings::SettingsSimulator));
|
||||
settingsChanged(static_cast<uint>(IContextSettings::SettingsSimulator));
|
||||
|
||||
// try to connect
|
||||
asyncConnectToSimulator();
|
||||
@@ -353,7 +433,7 @@ namespace BlackCore
|
||||
|
||||
// TODO warnings if we didn't load the plugin which the settings asked for
|
||||
|
||||
CSimulatorInfoList plugins = this->getAvailableSimulatorPlugins();
|
||||
CSimulatorPluginInfoList plugins = this->getAvailableSimulatorPlugins();
|
||||
if (plugins.size() == 1)
|
||||
{
|
||||
// load, independent from settings, we have only driver
|
||||
@@ -375,39 +455,44 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::listenForSimulator(const CSimulatorInfo &simulatorInfo)
|
||||
void CContextSimulator::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
Q_ASSERT(this->getIContextApplication());
|
||||
Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
|
||||
if (this->m_simulator) { // already loaded
|
||||
if (this->m_simulator)
|
||||
{ // already loaded
|
||||
qWarning("Cannot listen for simulator while the driver is still loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
// warning if we do not have any plugins
|
||||
if (m_simulatorDrivers.isEmpty()) {
|
||||
CLogMessage(this).error("No simulator drivers");
|
||||
if (m_simulatorPlugins.isEmpty())
|
||||
{
|
||||
CLogMessage(this).error("No simulator drivers available");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_simulatorDrivers.contains(simulatorInfo)) {
|
||||
CLogMessage(this).error("Driver not found for '%1'") << simulatorInfo.toQString(true);
|
||||
PluginData* plugin = findPlugin(simulatorInfo);
|
||||
if (!plugin)
|
||||
{
|
||||
CLogMessage(this).error("Driver not found for '%1'") << simulatorInfo.toQString();
|
||||
return;
|
||||
}
|
||||
|
||||
DriverInfo& driver = m_simulatorDrivers[simulatorInfo];
|
||||
if (!driver.listener) {
|
||||
|
||||
if (!plugin->listener)
|
||||
{
|
||||
ISimulatorFactory* factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
|
||||
driver.listener = factory->createListener();
|
||||
connect(driver.listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
|
||||
driver.listener->moveToThread(&m_listenersThread);
|
||||
|
||||
plugin->listener = factory->createListener();
|
||||
connect(plugin->listener, SIGNAL(simulatorStarted()), m_mapper, SLOT(map()));
|
||||
m_mapper->setMapping(plugin->listener, plugin->listener);
|
||||
plugin->listener->moveToThread(&m_listenersThread);
|
||||
}
|
||||
|
||||
ISimulatorListener *listener = m_simulatorDrivers[simulatorInfo].listener;
|
||||
|
||||
ISimulatorListener *listener = plugin->listener;
|
||||
Q_ASSERT(listener);
|
||||
|
||||
if (!m_listenersThread.isRunning())
|
||||
@@ -429,10 +514,12 @@ namespace BlackCore
|
||||
void CContextSimulator::listenForSimulatorFromSettings()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
|
||||
|
||||
auto plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin();
|
||||
if (plugin.isUnspecified())
|
||||
{
|
||||
listenForAllSimulators();
|
||||
}
|
||||
else
|
||||
{
|
||||
listenForSimulator(plugin);
|
||||
@@ -453,10 +540,10 @@ namespace BlackCore
|
||||
m_simulator->simulator->disconnect();
|
||||
CLogHandler::instance()->disconnect(m_simulator->simulator);
|
||||
this->disconnect(m_simulator->simulator);
|
||||
|
||||
|
||||
if (m_simulator->simulator->isConnected())
|
||||
m_simulator->simulator->disconnectFrom(); // disconnect from simulator
|
||||
|
||||
|
||||
m_simulator->simulator->deleteLater();
|
||||
m_simulator->simulator = nullptr;
|
||||
m_simulator = nullptr;
|
||||
@@ -465,95 +552,91 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
Q_ASSERT(m_simulator);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
Q_ASSERT(!remoteAircraft.getCallsign().isEmpty());
|
||||
if (!this->m_simulator) { return; }
|
||||
this->m_simulator->addRemoteAircraft(remoteAircraft);
|
||||
|
||||
m_simulator->simulator->addRemoteAircraft(remoteAircraft);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
if (!this->m_simulator) { return; }
|
||||
this->m_simulator->removeRemoteAircraft(callsign);
|
||||
Q_ASSERT(m_simulator);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
|
||||
m_simulator->simulator->removeRemoteAircraft(callsign);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_onConnectionStatusChanged(ISimulator::ConnectionStatus status)
|
||||
{
|
||||
bool connected;
|
||||
if (status == ISimulator::Connected)
|
||||
Q_ASSERT(m_simulator);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
|
||||
if (!(status & ISimulator::Connected))
|
||||
{
|
||||
connected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
connected = false;
|
||||
unloadSimulatorPlugin();
|
||||
listenForSimulatorFromSettings();
|
||||
}
|
||||
emit simulatorStatusChanged(status);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_textMessagesReceived(const Network::CTextMessageList &textMessages)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator); // TODO Assert or if?
|
||||
if (!this->m_simulator) { return; }
|
||||
foreach(CTextMessage tm, textMessages)
|
||||
Q_ASSERT(m_simulator);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
|
||||
for (auto &tm: textMessages)
|
||||
{
|
||||
this->m_simulator->displayTextMessage(tm);
|
||||
m_simulator->simulator->displayTextMessage(tm);
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_cockitChangedFromSim(const CSimulatedAircraft &ownAircraft)
|
||||
{
|
||||
Q_ASSERT(this->getIContextOwnAircraft());
|
||||
if (!this->getIContextOwnAircraft()) { return; }
|
||||
this->getIContextOwnAircraft()->changedAircraftCockpit(ownAircraft, IContextSimulator::InterfaceName());
|
||||
Q_ASSERT(getIContextOwnAircraft());
|
||||
|
||||
getIContextOwnAircraft()->changedAircraftCockpit(ownAircraft, IContextSimulator::InterfaceName());
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_changedRemoteAircraftModel(const CSimulatedAircraft &aircraft, const QString &originator)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
if (!this->m_simulator) { return; }
|
||||
|
||||
this->m_simulator->changeRemoteAircraftModel(aircraft, originator);
|
||||
this->m_simulator->simulator->changeRemoteAircraftModel(aircraft, originator);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_changedRemoteAircraftEnabled(const CSimulatedAircraft &aircraft, const QString &originator)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator);
|
||||
if (!this->m_simulator) { return; }
|
||||
|
||||
this->m_simulator->changeRemoteAircraftEnabled(aircraft, originator);
|
||||
this->m_simulator->simulator->changeRemoteAircraftEnabled(aircraft, originator);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_updateSimulatorCockpitFromContext(const CAircraft &ownAircraft, const QString &originator)
|
||||
{
|
||||
Q_ASSERT(this->m_simulator); // TODO Assert or if?
|
||||
if (!this->m_simulator) { return; }
|
||||
Q_ASSERT(m_simulator);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
|
||||
// avoid loops
|
||||
if (originator.isEmpty() || originator == IContextSimulator::InterfaceName()) { return; }
|
||||
|
||||
// update
|
||||
this->m_simulator->updateOwnSimulatorCockpit(ownAircraft, originator);
|
||||
this->m_simulator->simulator->updateOwnSimulatorCockpit(ownAircraft, originator);
|
||||
}
|
||||
|
||||
void CContextSimulator::settingsChanged(uint type)
|
||||
{
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
|
||||
auto settingsType = static_cast<IContextSettings::SettingsType>(type);
|
||||
if (settingsType != IContextSettings::SettingsSimulator)
|
||||
return;
|
||||
|
||||
// plugin
|
||||
CSettingsSimulator settingsSim = this->getIContextSettings()->getSimulatorSettings();
|
||||
CSimulatorInfo plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin();
|
||||
CSimulatorPluginInfo plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin();
|
||||
|
||||
// no simulator loaded yet, listen
|
||||
if (!m_simulator)
|
||||
{
|
||||
stopSimulatorListeners();
|
||||
if (plugin.isSameSimulator(CSimulatorInfo::UnspecifiedSim()))
|
||||
if (plugin.isUnspecified())
|
||||
{
|
||||
listenForAllSimulators();
|
||||
}
|
||||
@@ -567,45 +650,79 @@ namespace BlackCore
|
||||
// time sync
|
||||
bool timeSync = settingsSim.isTimeSyncEnabled();
|
||||
CTime syncOffset = settingsSim.getSyncTimeOffset();
|
||||
m_simulator->setTimeSynchronization(timeSync, syncOffset);
|
||||
m_simulator->simulator->setTimeSynchronization(timeSync, syncOffset);
|
||||
}
|
||||
}
|
||||
|
||||
CPixmap CContextSimulator::iconForModel(const QString &modelString) const
|
||||
{
|
||||
if (!this->m_simulator) { return CPixmap(); }
|
||||
return this->m_simulator->iconForModel(modelString);
|
||||
if (!this->m_simulator)
|
||||
{
|
||||
return CPixmap();
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->iconForModel(modelString);
|
||||
}
|
||||
|
||||
void CContextSimulator::enableDebugMessages(bool driver, bool interpolator)
|
||||
{
|
||||
if (!this->m_simulator) { return; }
|
||||
return this->m_simulator->enableDebugMessages(driver, interpolator);
|
||||
if (!this->m_simulator)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->enableDebugMessages(driver, interpolator);
|
||||
}
|
||||
|
||||
void CContextSimulator::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime)
|
||||
{
|
||||
if (!this->m_simulator) { return; }
|
||||
this->m_simulator->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime);
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
this->m_simulator->simulator->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime);
|
||||
}
|
||||
|
||||
bool CContextSimulator::isPaused() const
|
||||
{
|
||||
if (!this->m_simulator) return false;
|
||||
return this->m_simulator->isPaused();
|
||||
if (!this->m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->isPaused();
|
||||
}
|
||||
|
||||
bool CContextSimulator::isSimulating() const
|
||||
{
|
||||
if (!this->m_simulator) return false;
|
||||
return this->m_simulator->isSimulating();
|
||||
if (!this->m_simulator)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulator->simulator);
|
||||
return m_simulator->simulator->isSimulating();
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_simulatorStarted(CSimulatorInfo simulatorInfo)
|
||||
void CContextSimulator::ps_simulatorStarted(QObject *listener)
|
||||
{
|
||||
CLogMessage(this).debug() << simulatorInfo.toQString() << "started";
|
||||
Q_ASSERT(listener);
|
||||
Q_ASSERT(listener->inherits("BlackCore::ISimulatorListener"));
|
||||
|
||||
/* Find caller */
|
||||
PluginData *plugin = [this](QObject *listener)
|
||||
{
|
||||
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [listener](const PluginData &plugin)
|
||||
{
|
||||
return plugin.listener == listener;
|
||||
});
|
||||
return &(*it);
|
||||
}(listener);
|
||||
Q_ASSERT(plugin);
|
||||
|
||||
CLogMessage(this).debug() << plugin->info.toQString() << "started";
|
||||
stopSimulatorListeners();
|
||||
loadSimulatorPlugin(simulatorInfo);
|
||||
loadSimulatorPlugin(plugin->info);
|
||||
}
|
||||
|
||||
void CContextSimulator::findSimulatorPlugins()
|
||||
@@ -617,7 +734,7 @@ namespace BlackCore
|
||||
CLogMessage(this).error("No plugin directory: %1") << m_pluginsDir.currentPath();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QStringList fileNames = m_pluginsDir.entryList(QDir::Files);
|
||||
fileNames.sort(Qt::CaseInsensitive); // give a certain order, rather than random file order
|
||||
for (const auto& fileName: fileNames)
|
||||
@@ -626,16 +743,17 @@ namespace BlackCore
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
CLogMessage(this).debug() << "Try to load plugin: " << fileName;
|
||||
QString pluginPath = m_pluginsDir.absoluteFilePath(fileName);
|
||||
QPluginLoader loader(pluginPath);
|
||||
QJsonObject json = loader.metaData();
|
||||
CSimulatorInfo simulatorInfo(json);
|
||||
if (!simulatorInfo.isUnspecified())
|
||||
CSimulatorPluginInfo simulatorPluginInfo;
|
||||
simulatorPluginInfo.convertFromJson(json);
|
||||
if (simulatorPluginInfo.isValid())
|
||||
{
|
||||
m_simulatorDrivers.insert(simulatorInfo, { nullptr, nullptr, pluginPath} );
|
||||
CLogMessage(this).debug() << "Found simulator driver: " << simulatorInfo.toQString();
|
||||
m_simulatorPlugins << PluginData{ simulatorPluginInfo, nullptr, nullptr, nullptr, pluginPath};
|
||||
CLogMessage(this).debug() << "Found simulator driver: " << simulatorPluginInfo.toQString();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -646,10 +764,21 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::stopSimulatorListeners()
|
||||
{
|
||||
std::for_each(m_simulatorDrivers.begin(), m_simulatorDrivers.end(), [](DriverInfo& driver) {
|
||||
if (driver.listener)
|
||||
QMetaObject::invokeMethod(driver.listener, "stop");
|
||||
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [](PluginData& plugin)
|
||||
{
|
||||
if (plugin.listener)
|
||||
QMetaObject::invokeMethod(plugin.listener, "stop");
|
||||
});
|
||||
}
|
||||
|
||||
CContextSimulator::PluginData *CContextSimulator::findPlugin(const CSimulatorPluginInfo &info)
|
||||
{
|
||||
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&info](PluginData& plugin)
|
||||
{
|
||||
return plugin.info == info;
|
||||
});
|
||||
|
||||
return &(*it);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "blackcore/context_simulator.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blacksim/simulatorplugininfo.h"
|
||||
#include "blacksim/simulatorinfolist.h"
|
||||
#include "blackmisc/nwtextmessagelist.h"
|
||||
#include "blackmisc/pixmap.h"
|
||||
@@ -43,12 +43,12 @@ namespace BlackCore
|
||||
//! Lazy-loads the driver, instantiates the factory and returns it.
|
||||
//! \return nullptr if no corresponding driver was found or an error occured during loading it.
|
||||
//! \todo Consider moving to private scope.
|
||||
ISimulatorFactory* getSimulatorFactory(const BlackSim::CSimulatorInfo& simulator);
|
||||
ISimulatorFactory* getSimulatorFactory(const BlackSim::CSimulatorPluginInfo& simulator);
|
||||
|
||||
public slots:
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
virtual BlackSim::CSimulatorInfoList getAvailableSimulatorPlugins() const override;
|
||||
virtual BlackSim::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
@@ -72,7 +72,7 @@ namespace BlackCore
|
||||
virtual bool isSimulating() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo()
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
virtual BlackSim::CSimulatorPluginInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getAirportsInRange
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
@@ -126,13 +126,13 @@ namespace BlackCore
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||
virtual bool loadSimulatorPluginFromSettings() override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulator()
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForAllSimulators()
|
||||
virtual void listenForAllSimulators() override;
|
||||
@@ -181,7 +181,7 @@ namespace BlackCore
|
||||
void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);
|
||||
|
||||
//! Listener reports the simulator has started
|
||||
void ps_simulatorStarted(BlackSim::CSimulatorInfo simulatorInfo);
|
||||
void ps_simulatorStarted(QObject *listener);
|
||||
|
||||
//! Simulator has changed cockpit
|
||||
void ps_cockitChangedFromSim(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
|
||||
@@ -203,21 +203,28 @@ namespace BlackCore
|
||||
//! \brief call stop() on all loaded listeners
|
||||
void stopSimulatorListeners();
|
||||
|
||||
struct PluginData;
|
||||
|
||||
//! \brief Locate PluginData (linear search)
|
||||
PluginData* findPlugin(const BlackSim::CSimulatorPluginInfo &info);
|
||||
|
||||
/*!
|
||||
* A simple struct containing all info about the driver we need.
|
||||
* A simple struct containing all info about the plugin.
|
||||
*/
|
||||
struct DriverInfo {
|
||||
ISimulatorFactory* factory; //!< Lazy-loaded, nullptr by default
|
||||
ISimulatorListener* listener; //!< Listener instance, nullptr by default
|
||||
struct PluginData {
|
||||
BlackSim::CSimulatorPluginInfo info;
|
||||
ISimulatorFactory *factory; //!< Lazy-loaded, nullptr by default
|
||||
ISimulatorListener *listener; //!< Listener instance, nullptr by default
|
||||
ISimulator *simulator; //!< The simulator itself (always nullptr unless it is the currently working one)
|
||||
QString fileName; //!< Plugin file name (relative to plugins/simulator)
|
||||
};
|
||||
|
||||
BlackCore::ISimulator *m_simulator = nullptr; //!< Actually loaded simulator driver
|
||||
QTimer *m_updateTimer = nullptr;
|
||||
QDir m_pluginsDir;
|
||||
QMap<BlackSim::CSimulatorInfo, DriverInfo> m_simulatorDrivers;
|
||||
QList<PluginData> m_simulatorPlugins;
|
||||
PluginData *m_simulator = nullptr; //!< Currently loaded simulator plugin
|
||||
QFuture<bool> m_canConnectResult;
|
||||
BlackMisc::CRegularThread m_listenersThread;
|
||||
QSignalMapper* m_mapper;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace BlackCore
|
||||
Q_UNUSED(s);
|
||||
}
|
||||
|
||||
CSimulatorInfoList CContextSimulatorProxy::getAvailableSimulatorPlugins() const
|
||||
CSimulatorPluginInfoList CContextSimulatorProxy::getAvailableSimulatorPlugins() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<CSimulatorInfoList>(QLatin1Literal("getAvailableSimulatorPlugins"));
|
||||
return m_dBusInterface->callDBusRet<CSimulatorPluginInfoList>(QLatin1Literal("getAvailableSimulatorPlugins"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::isConnected() const
|
||||
@@ -114,9 +114,9 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<CAircraftIcao>(QLatin1Literal("getIcaoForModelString"), modelString);
|
||||
}
|
||||
|
||||
BlackSim::CSimulatorInfo CContextSimulatorProxy::getSimulatorInfo() const
|
||||
BlackSim::CSimulatorPluginInfo CContextSimulatorProxy::getSimulatorInfo() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorInfo>(QLatin1Literal("getSimulatorInfo"));
|
||||
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorPluginInfo>(QLatin1Literal("getSimulatorInfo"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::setTimeSynchronization(bool enable, CTime offset)
|
||||
@@ -174,7 +174,7 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::PhysicalQuantities::CTime>(QLatin1Literal("getTimeSynchronizationOffset"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo)
|
||||
bool CContextSimulatorProxy::loadSimulatorPlugin(const BlackSim::CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPlugin"), simulatorInfo);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPluginFromSettings"));
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::listenForSimulator(const CSimulatorInfo &simulatorInfo)
|
||||
void CContextSimulatorProxy::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("listenForSimulator"), simulatorInfo);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BlackCore
|
||||
public slots:
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
virtual BlackSim::CSimulatorInfoList getAvailableSimulatorPlugins() const override;
|
||||
virtual BlackSim::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::isConnected()
|
||||
virtual bool isConnected() const override;
|
||||
@@ -87,7 +87,7 @@ namespace BlackCore
|
||||
virtual BlackMisc::Aviation::CAircraftIcao getIcaoForModelString(const QString &modelString) const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
virtual BlackSim::CSimulatorPluginInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::setTimeSynchronization
|
||||
virtual bool setTimeSynchronization(bool enable, BlackMisc::PhysicalQuantities::CTime offset) override;
|
||||
@@ -123,13 +123,13 @@ namespace BlackCore
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||
virtual bool loadSimulatorPluginFromSettings();
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulator()
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
virtual void listenForSimulator(const BlackSim::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForAllSimulators()
|
||||
virtual void listenForAllSimulators() override;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifndef BLACKCORE_NETWORK_H
|
||||
#define BLACKCORE_NETWORK_H
|
||||
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blacksim/simulatorplugininfo.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
#include "blackmisc/pqfrequency.h"
|
||||
#include "blackmisc/coordinategeodetic.h"
|
||||
@@ -182,7 +182,7 @@ namespace BlackCore
|
||||
* Set simulator info before connecting.
|
||||
* \pre Network must be disconnected when calling this function.
|
||||
*/
|
||||
virtual void presetSimulatorInfo(const BlackSim::CSimulatorInfo &simInfo) = 0;
|
||||
virtual void presetSimulatorInfo(const BlackSim::CSimulatorPluginInfo &simInfo) = 0;
|
||||
|
||||
/*!
|
||||
* Initiate a connection to the network server.
|
||||
|
||||
@@ -256,13 +256,16 @@ namespace BlackCore
|
||||
return escaped;
|
||||
}
|
||||
|
||||
VatSimType CNetworkVatlib::convertToSimType(CSimulatorInfo &simInfo)
|
||||
VatSimType CNetworkVatlib::convertToSimType(CSimulatorPluginInfo &simInfo)
|
||||
{
|
||||
if (simInfo.isUnspecified()) { return vatSimTypeUnknown; }
|
||||
if (CSimulatorInfo::FS9().isSameSimulator(simInfo)) { return vatSimTypeMSCFS; }
|
||||
if (CSimulatorInfo::FSX().isSameSimulator(simInfo)) { return vatSimTypeMSCFS; }
|
||||
if (CSimulatorInfo::XP().isSameSimulator(simInfo)) { return vatSimTypeXPLANE; }
|
||||
return vatSimTypeUnknown;
|
||||
/* TODO Define recognized simulators somewhere */
|
||||
if (simInfo.simulator() == "fs9" || simInfo.simulator() == "fsx") {
|
||||
return vatSimTypeMSCFS;
|
||||
} else if (simInfo.simulator() == "xplane") {
|
||||
return vatSimTypeXPLANE;
|
||||
} else {
|
||||
return vatSimTypeUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
|
||||
@@ -275,7 +278,7 @@ namespace BlackCore
|
||||
m_server = server;
|
||||
}
|
||||
|
||||
void CNetworkVatlib::presetSimulatorInfo(const CSimulatorInfo &simInfo)
|
||||
void CNetworkVatlib::presetSimulatorInfo(const CSimulatorPluginInfo &simInfo)
|
||||
{
|
||||
Q_ASSERT_X(isDisconnected(), "CNetworkVatlib", "Can't change server details while still connected");
|
||||
m_simulatorInfo = simInfo;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace BlackCore
|
||||
virtual void presetServer(const BlackMisc::Network::CServer &server) override;
|
||||
virtual void presetCallsign(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual void presetIcaoCodes(const BlackMisc::Aviation::CAircraftIcao &icao) override;
|
||||
virtual void presetSimulatorInfo(const BlackSim::CSimulatorInfo &simInfo) override;
|
||||
virtual void presetSimulatorInfo(const BlackSim::CSimulatorPluginInfo &simInfo) override;
|
||||
virtual void initiateConnection() override;
|
||||
virtual void terminateConnection() override;
|
||||
virtual void sendPing(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
@@ -131,7 +131,7 @@ namespace BlackCore
|
||||
void changeConnectionStatus(VatConnectionStatus newStatus);
|
||||
bool isDisconnected() const { return m_status != vatStatusConnecting && m_status != vatStatusConnected; }
|
||||
static QString convertToUnicodeEscaped(const QString &str);
|
||||
static VatSimType convertToSimType(BlackSim::CSimulatorInfo &simInfo);
|
||||
static VatSimType convertToSimType(BlackSim::CSimulatorPluginInfo &simInfo);
|
||||
static void networkLogHandler(SeverityLevel severity, const char *message);
|
||||
|
||||
struct JsonPackets
|
||||
@@ -160,7 +160,7 @@ namespace BlackCore
|
||||
LoginMode m_loginMode;
|
||||
VatConnectionStatus m_status;
|
||||
BlackMisc::Network::CServer m_server;
|
||||
BlackSim::CSimulatorInfo m_simulatorInfo;
|
||||
BlackSim::CSimulatorPluginInfo m_simulatorInfo;
|
||||
BlackMisc::Aviation::CCallsign m_callsign; //!< "buffered callsign", as this must not change when connected
|
||||
BlackMisc::Aviation::CAircraftIcao m_icaoCode; //!< "buffered icao", as this must not change when connected
|
||||
bool m_sendInterimPositions = false; //!< send interim positions
|
||||
|
||||
@@ -33,10 +33,12 @@ namespace BlackCore
|
||||
{
|
||||
}
|
||||
|
||||
CSimulatorCommon::CSimulatorCommon(const BlackSim::CSimulatorInfo &simInfo, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent)
|
||||
CSimulatorCommon::CSimulatorCommon(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent)
|
||||
: ISimulator(parent),
|
||||
COwnAircraftProviderSupport(ownAircraftProvider),
|
||||
CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo)
|
||||
CRemoteAircraftProviderSupport(remoteAircraftProvider)
|
||||
{
|
||||
m_oneSecondTimer = new QTimer(this);
|
||||
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
@@ -195,12 +197,7 @@ namespace BlackCore
|
||||
{
|
||||
return !m_maxRenderedDistance.isNull();
|
||||
}
|
||||
|
||||
CSimulatorInfo CSimulatorCommon::getSimulatorInfo() const
|
||||
{
|
||||
return m_simulatorInfo;
|
||||
}
|
||||
|
||||
|
||||
void CSimulatorCommon::enableDebugMessages(bool driver, bool interpolator)
|
||||
{
|
||||
this->m_debugMessages = driver;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#define BLACKCORE_SIMULATOR_H
|
||||
|
||||
#include "blackcore/interpolator.h"
|
||||
#include "blacksim/simulatorinfo.h"
|
||||
#include "blacksim/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/simdirectaccessownaircraft.h"
|
||||
@@ -104,9 +104,6 @@ namespace BlackCore
|
||||
//! ICAO data for model string
|
||||
virtual BlackMisc::Aviation::CAircraftIcao getIcaoForModelString(const QString &modelString) const = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
|
||||
//! Display a status message in the simulator
|
||||
virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const = 0;
|
||||
|
||||
@@ -230,7 +227,7 @@ namespace BlackCore
|
||||
signals:
|
||||
|
||||
//! Emitted when the listener discovers the simulator running.
|
||||
void simulatorStarted(BlackSim::CSimulatorInfo simulatorInfo);
|
||||
void simulatorStarted();
|
||||
|
||||
};
|
||||
|
||||
@@ -253,9 +250,6 @@ namespace BlackCore
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
QObject *parent = nullptr) = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
|
||||
//! Simulator listener instance
|
||||
virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0;
|
||||
@@ -293,9 +287,6 @@ namespace BlackCore
|
||||
//! \copydoc ISimulator::isMaxDistanceRestricted
|
||||
virtual bool isMaxDistanceRestricted() const override;
|
||||
|
||||
//! \copydoc ISimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc ISimulator::enableDebuggingMessages
|
||||
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
||||
|
||||
@@ -321,12 +312,10 @@ namespace BlackCore
|
||||
protected:
|
||||
//! Constructor
|
||||
CSimulatorCommon(
|
||||
const BlackSim::CSimulatorInfo &simInfo,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
|
||||
//! Blink the highlighted aircraft
|
||||
void blinkHighlightedAircraft();
|
||||
|
||||
@@ -339,7 +328,6 @@ namespace BlackCore
|
||||
//! Override parts and situation from current interpolator values, if any!
|
||||
void setInitialAircraftSituationAndParts(BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
BlackSim::CSimulatorInfo m_simulatorInfo; //!< about the simulator
|
||||
bool m_debugMessages = false; //!< Display debug messages
|
||||
bool m_blinkCycle = false; //!< use for highlighting
|
||||
IInterpolator *m_interpolator = nullptr; //!< interpolator instance
|
||||
|
||||
Reference in New Issue
Block a user