mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 18:55:38 +08:00
refs #273, added support for loading plugin from settings
This commit is contained in:
@@ -409,9 +409,10 @@ namespace BlackCore
|
|||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_contextSimulator && this->m_contextSimulator->usingLocalObjects() && this->getCContextSimulator()->m_simulator)
|
// local simulator?
|
||||||
|
if (this->m_contextSimulator && this->m_contextSimulator->usingLocalObjects())
|
||||||
{
|
{
|
||||||
// only connect if simulator running locally, no round trips
|
// only connect if simulator runs locally, no round trips
|
||||||
if (this->m_contextNetwork && this->m_contextNetwork->usingLocalObjects())
|
if (this->m_contextNetwork && this->m_contextNetwork->usingLocalObjects())
|
||||||
{
|
{
|
||||||
c = connect(this->m_contextNetwork, &IContextNetwork::changedAircraftSituation,
|
c = connect(this->m_contextNetwork, &IContextNetwork::changedAircraftSituation,
|
||||||
@@ -423,7 +424,7 @@ namespace BlackCore
|
|||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only if own aircraft running locally
|
// only if own aircraft runs locally
|
||||||
if (this->m_contextOwnAircraft && this->m_contextOwnAircraft->usingLocalObjects())
|
if (this->m_contextOwnAircraft && this->m_contextOwnAircraft->usingLocalObjects())
|
||||||
{
|
{
|
||||||
c = connect(this->m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit,
|
c = connect(this->m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit,
|
||||||
@@ -431,7 +432,7 @@ namespace BlackCore
|
|||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only if own aircraft running locally
|
// only if application runs locally
|
||||||
if (this->m_contextApplication && this->m_contextApplication->usingLocalObjects())
|
if (this->m_contextApplication && this->m_contextApplication->usingLocalObjects())
|
||||||
{
|
{
|
||||||
c = connect(this->m_contextApplication, &IContextApplication::statusMessage,
|
c = connect(this->m_contextApplication, &IContextApplication::statusMessage,
|
||||||
@@ -442,11 +443,25 @@ namespace BlackCore
|
|||||||
this->getCContextSimulator(), &CContextSimulator::statusMessagesReceived);
|
this->getCContextSimulator(), &CContextSimulator::statusMessagesReceived);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// connect local simulator and settings
|
||||||
|
if (this->m_contextSettings)
|
||||||
|
{
|
||||||
|
connect(this->m_contextSettings, &IContextSettings::changedSettings, this->m_contextSimulator, &IContextSimulator::settingsChanged);
|
||||||
|
if (this->m_contextSimulator->loadSimulatorPluginFromSettings())
|
||||||
|
{
|
||||||
|
qDebug() << "Simulator driver loaded";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning() << "No simulator driver loaded";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only where network and(!) own aircraft run locally
|
||||||
if (this->m_contextNetwork && this->m_contextOwnAircraft && this->m_contextNetwork->usingLocalObjects() && this->m_contextOwnAircraft->usingLocalObjects())
|
if (this->m_contextNetwork && this->m_contextOwnAircraft && this->m_contextNetwork->usingLocalObjects() && this->m_contextOwnAircraft->usingLocalObjects())
|
||||||
{
|
{
|
||||||
// only where network and(!) own aircraft run locally
|
|
||||||
c = this->connect(this->m_contextNetwork, &IContextNetwork::changedAtcStationOnlineConnectionStatus,
|
c = this->connect(this->m_contextNetwork, &IContextNetwork::changedAtcStationOnlineConnectionStatus,
|
||||||
this->getCContextOwnAircraft(), &CContextOwnAircraft::changedAtcStationOnlineConnectionStatus);
|
this->getCContextOwnAircraft(), &CContextOwnAircraft::changedAtcStationOnlineConnectionStatus);
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|||||||
@@ -87,12 +87,18 @@ namespace BlackCore
|
|||||||
//! Load specific simulator plugin
|
//! Load specific simulator plugin
|
||||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) = 0;
|
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) = 0;
|
||||||
|
|
||||||
|
//! Load specific simulator plugin as set in settings
|
||||||
|
virtual bool loadSimulatorPluginFromSettings() = 0;
|
||||||
|
|
||||||
//! Unload simulator plugin
|
//! Unload simulator plugin
|
||||||
virtual void unloadSimulatorPlugin() = 0;
|
virtual void unloadSimulatorPlugin() = 0;
|
||||||
|
|
||||||
//! Simulator avialable?
|
//! Simulator avialable?
|
||||||
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorInfo().isUnspecified(); }
|
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorInfo().isUnspecified(); }
|
||||||
|
|
||||||
|
//! Settings have been changed
|
||||||
|
virtual void settingsChanged(uint type) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
IContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
|
IContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "context_simulator_impl.h"
|
#include "context_simulator_impl.h"
|
||||||
#include "context_ownaircraft.h"
|
#include "context_ownaircraft.h"
|
||||||
|
#include "context_settings.h"
|
||||||
|
#include "context_application.h"
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
#include "context_runtime.h"
|
#include "context_runtime.h"
|
||||||
@@ -23,10 +25,10 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
m_updateTimer = new QTimer(this);
|
m_updateTimer = new QTimer(this);
|
||||||
findSimulatorPlugins();
|
findSimulatorPlugins();
|
||||||
loadSimulatorPlugin(CSimulatorInfo::FSX());
|
|
||||||
|
|
||||||
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
|
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
|
||||||
asyncConnectTo();
|
|
||||||
|
// do not load plugin here, as it depends on settings
|
||||||
|
// it has to be guaranteed the settings are alredy loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
CContextSimulator::~CContextSimulator()
|
CContextSimulator::~CContextSimulator()
|
||||||
@@ -98,31 +100,57 @@ namespace BlackCore
|
|||||||
|
|
||||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
|
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
|
||||||
{
|
{
|
||||||
|
if (this->m_simulator && this->m_simulator->getSimulatorInfo() == simulatorInfo) { return true; } // already loaded
|
||||||
|
if (simulatorInfo.isUnspecified()) { return false; }
|
||||||
|
|
||||||
ISimulatorFactory *factory = nullptr;
|
ISimulatorFactory *factory = nullptr;
|
||||||
QSet<ISimulatorFactory *>::iterator iterator = std::find_if(m_simulatorFactories.begin(), m_simulatorFactories.end(), [ = ](const ISimulatorFactory * factory)
|
QSet<ISimulatorFactory *>::iterator iterator = std::find_if(m_simulatorFactories.begin(), m_simulatorFactories.end(), [ = ](const ISimulatorFactory * factory)
|
||||||
{
|
{
|
||||||
return factory->getSimulatorInfo() == simulatorInfo;
|
return factory->getSimulatorInfo() == simulatorInfo;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (iterator == m_simulatorFactories.end())
|
if (iterator == m_simulatorFactories.end()) { return false; }
|
||||||
return false;
|
|
||||||
|
|
||||||
factory = *iterator;
|
factory = *iterator;
|
||||||
Q_ASSERT(factory);
|
Q_ASSERT(factory);
|
||||||
|
|
||||||
m_simulator = factory->create(this);
|
ISimulator *newSimulator = factory->create(this);
|
||||||
Q_ASSERT(m_simulator);
|
Q_ASSERT(newSimulator);
|
||||||
|
|
||||||
|
this->unloadSimulatorPlugin(); // old plugin unloaded
|
||||||
|
m_simulator = newSimulator;
|
||||||
|
|
||||||
connect(m_simulator, SIGNAL(statusChanged(ISimulator::Status)), this, SLOT(setConnectionStatus(ISimulator::Status)));
|
connect(m_simulator, SIGNAL(statusChanged(ISimulator::Status)), this, SLOT(setConnectionStatus(ISimulator::Status)));
|
||||||
connect(m_simulator, &ISimulator::aircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
connect(m_simulator, &ISimulator::aircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged);
|
||||||
|
asyncConnectTo(); // try to connect
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CContextSimulator::loadSimulatorPluginFromSettings()
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->getIContextSettings());
|
||||||
|
if (!this->getIContextSettings()) return false;
|
||||||
|
|
||||||
|
CSimulatorInfoList drivers = this->getAvailableSimulatorPlugins();
|
||||||
|
if (drivers.size() == 1)
|
||||||
|
{
|
||||||
|
// load, independent from settings, we have only driver
|
||||||
|
return this->loadSimulatorPlugin(drivers.front());
|
||||||
|
}
|
||||||
|
else if (drivers.size() > 1)
|
||||||
|
{
|
||||||
|
return this->loadSimulatorPlugin(
|
||||||
|
this->getIContextSettings()->getSimulatorSettings().getSelectedDriver()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CContextSimulator::unloadSimulatorPlugin()
|
void CContextSimulator::unloadSimulatorPlugin()
|
||||||
{
|
{
|
||||||
if (m_simulator)
|
if (m_simulator) { m_simulator->deleteLater(); }
|
||||||
m_simulator->deleteLater();
|
|
||||||
|
|
||||||
m_simulator = nullptr;
|
m_simulator = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +227,29 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CContextSimulator::settingsChanged(uint type)
|
||||||
|
{
|
||||||
|
Q_ASSERT(this->getIContextSettings());
|
||||||
|
if (!this->getIContextSettings()) return;
|
||||||
|
IContextSettings::SettingsType settingsType = static_cast<IContextSettings::SettingsType>(type);
|
||||||
|
if (settingsType == IContextSettings::SettingsSimulator)
|
||||||
|
{
|
||||||
|
CSimulatorInfo driver = this->getIContextSettings()->getSimulatorSettings().getSelectedDriver();
|
||||||
|
if (this->loadSimulatorPlugin(driver))
|
||||||
|
{
|
||||||
|
QString m = QString("Driver loaded: '%1'").arg(driver.toQString(true));
|
||||||
|
if (this->getIContextApplication())
|
||||||
|
this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage(m, CStatusMessage::TypeSimulator));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString m = QString("Cannot load driver: '%1'").arg(driver.toQString(true));
|
||||||
|
if (this->getIContextApplication())
|
||||||
|
this->getIContextApplication()->sendStatusMessage(CStatusMessage::getErrorMessage(m, CStatusMessage::TypeSimulator));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CContextSimulator::findSimulatorPlugins()
|
void CContextSimulator::findSimulatorPlugins()
|
||||||
{
|
{
|
||||||
m_pluginsDir = QDir(qApp->applicationDirPath().append("/plugins/simulator"));
|
m_pluginsDir = QDir(qApp->applicationDirPath().append("/plugins/simulator"));
|
||||||
|
|||||||
@@ -62,9 +62,15 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
||||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||||
|
virtual bool loadSimulatorPluginFromSettings();
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||||
virtual void unloadSimulatorPlugin() override;
|
virtual void unloadSimulatorPlugin() override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSimulator::settingsChanged
|
||||||
|
virtual void settingsChanged(uint type) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime);
|
CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime);
|
||||||
|
|||||||
@@ -73,9 +73,19 @@ namespace BlackCore
|
|||||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPlugin"), simulatorInfo);
|
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPlugin"), simulatorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CContextSimulatorProxy::loadSimulatorPluginFromSettings()
|
||||||
|
{
|
||||||
|
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPluginFromSettings"));
|
||||||
|
}
|
||||||
|
|
||||||
void CContextSimulatorProxy::unloadSimulatorPlugin()
|
void CContextSimulatorProxy::unloadSimulatorPlugin()
|
||||||
{
|
{
|
||||||
m_dBusInterface->callDBus(QLatin1Literal("unloadSimulatorPlugin"));
|
m_dBusInterface->callDBus(QLatin1Literal("unloadSimulatorPlugin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CContextSimulatorProxy::settingsChanged(uint type)
|
||||||
|
{
|
||||||
|
m_dBusInterface->callDBus(QLatin1Literal("settingsChanged"), type);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace BlackCore
|
} // namespace BlackCore
|
||||||
|
|||||||
@@ -63,12 +63,14 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextSimulator::loadSimulatorPlugin
|
//! \copydoc IContextSimulator::loadSimulatorPlugin
|
||||||
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||||
|
virtual bool loadSimulatorPluginFromSettings();
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||||
virtual void unloadSimulatorPlugin() override;
|
virtual void unloadSimulatorPlugin() override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSimulator::settingsChanged
|
||||||
|
virtual void settingsChanged(uint type) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BlackCore
|
} // namespace BlackCore
|
||||||
|
|||||||
Reference in New Issue
Block a user