refs #366, passing Simulator plugin info to drivers

Add. some finetuning
This commit is contained in:
Klaus Basan
2015-04-10 00:16:00 +02:00
parent 1f5eb16bb1
commit f7b50b3f5a
15 changed files with 221 additions and 150 deletions

View File

@@ -32,8 +32,8 @@ using namespace BlackMisc::Simulation::Settings;
namespace BlackCore namespace BlackCore
{ {
CContextSimulator::CContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextSimulator::CContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
IContextSimulator(mode, runtime), IContextSimulator(mode, runtime),
m_mapper(new QSignalMapper(this)) m_mapper(new QSignalMapper(this))
{ {
findSimulatorPlugins(); findSimulatorPlugins();
// Maps listener instance // Maps listener instance
@@ -49,8 +49,7 @@ namespace BlackCore
ISimulatorFactory *CContextSimulator::getSimulatorFactory(const CSimulatorPluginInfo &simulator) ISimulatorFactory *CContextSimulator::getSimulatorFactory(const CSimulatorPluginInfo &simulator)
{ {
PluginData *plugin = findPlugin(simulator); PluginData *plugin = findPlugin(simulator);
if (!plugin) if (!plugin) { return nullptr; }
return nullptr;
if (!plugin->factory) if (!plugin->factory)
{ {
@@ -62,9 +61,11 @@ namespace BlackCore
if (factory) if (factory)
{ {
plugin->factory = factory; plugin->factory = factory;
CLogMessage(this).debug() << "Loaded plugin: " << plugin->info.toQString(); CLogMessage(this).info("Loaded driver: %1") << plugin->info.toQString();
} }
} else { }
else
{
QString errorMsg = loader.errorString().append(" ").append("Also check if required dll/libs of plugin exists"); QString errorMsg = loader.errorString().append(" ").append("Also check if required dll/libs of plugin exists");
CLogMessage(this).error(errorMsg); CLogMessage(this).error(errorMsg);
} }
@@ -77,7 +78,7 @@ namespace BlackCore
{ {
CSimulatorPluginInfoList list; CSimulatorPluginInfoList list;
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&list](const PluginData &driver) std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&list](const PluginData & driver)
{ {
list.push_back(driver.info); list.push_back(driver.info);
}); });
@@ -349,7 +350,7 @@ namespace BlackCore
Q_ASSERT(!simulatorInfo.isUnspecified()); Q_ASSERT(!simulatorInfo.isUnspecified());
// warning if we do not have any plugins // warning if we do not have any plugins
if (m_simulatorPlugins.isEmpty()) if (m_simulatorPlugins.isEmpty() || simulatorInfo.isUnspecified())
{ {
CLogMessage(this).error("No simulator plugins"); CLogMessage(this).error("No simulator plugins");
return false; return false;
@@ -364,12 +365,12 @@ namespace BlackCore
Q_ASSERT(this->getIContextNetwork()->isUsingImplementingObject()); Q_ASSERT(this->getIContextNetwork()->isUsingImplementingObject());
IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft(); IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft();
IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork(); IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork();
ISimulator *newSimulator = factory->create(ownAircraftProvider, renderedAircraftProvider, this); ISimulator *newSimulator = factory->create(simulatorInfo, ownAircraftProvider, renderedAircraftProvider, this);
Q_ASSERT(newSimulator); Q_ASSERT(newSimulator);
unloadSimulatorPlugin(); // old plugin unloaded unloadSimulatorPlugin(); // old plugin unloaded
PluginData* plugin = findPlugin(simulatorInfo); PluginData *plugin = findPlugin(simulatorInfo);
plugin->simulator = newSimulator; plugin->simulator = newSimulator;
m_simulator = plugin; m_simulator = plugin;
@@ -381,7 +382,7 @@ namespace BlackCore
// log from context to simulator // log from context to simulator
connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator->simulator, &ISimulator::displayStatusMessage); connect(CLogHandler::instance(), &CLogHandler::localMessageLogged, m_simulator->simulator, &ISimulator::displayStatusMessage);
connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged,m_simulator->simulator, &ISimulator::displayStatusMessage); connect(CLogHandler::instance(), &CLogHandler::remoteMessageLogged, m_simulator->simulator, &ISimulator::displayStatusMessage);
// connect with network // connect with network
IContextNetwork *networkContext = this->getIContextNetwork(); IContextNetwork *networkContext = this->getIContextNetwork();
@@ -441,8 +442,9 @@ namespace BlackCore
Q_ASSERT(!simulatorInfo.isUnspecified()); Q_ASSERT(!simulatorInfo.isUnspecified());
if (this->m_simulator) if (this->m_simulator)
{ // already loaded {
qWarning("Cannot listen for simulator while the driver is still loaded"); // already loaded
CLogMessage(this).warning("Cannot listen for simulator while the driver %1 is still loaded") << m_simulator->info.toQString();
return; return;
} }
@@ -453,7 +455,7 @@ namespace BlackCore
return; return;
} }
PluginData* plugin = findPlugin(simulatorInfo); PluginData *plugin = findPlugin(simulatorInfo);
if (!plugin) if (!plugin)
{ {
CLogMessage(this).error("Driver not found for '%1'") << simulatorInfo.toQString(); CLogMessage(this).error("Driver not found for '%1'") << simulatorInfo.toQString();
@@ -462,11 +464,17 @@ namespace BlackCore
if (!plugin->listener) if (!plugin->listener)
{ {
ISimulatorFactory* factory = getSimulatorFactory(simulatorInfo); ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
Q_ASSERT(factory); Q_ASSERT(factory);
plugin->listener = factory->createListener(); plugin->listener = factory->createListener();
connect(plugin->listener, SIGNAL(simulatorStarted()), m_mapper, SLOT(map())); bool c = connect(plugin->listener, &ISimulatorListener::simulatorStarted,
m_mapper, static_cast<void (QSignalMapper::*)()> (&QSignalMapper::map));
if (!c)
{
CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString();
return;
}
m_mapper->setMapping(plugin->listener, plugin->listener); m_mapper->setMapping(plugin->listener, plugin->listener);
plugin->listener->moveToThread(&m_listenersThread); plugin->listener->moveToThread(&m_listenersThread);
} }
@@ -480,14 +488,16 @@ namespace BlackCore
} }
QMetaObject::invokeMethod(listener, "start"); QMetaObject::invokeMethod(listener, "start");
CLogMessage(this).debug() << "Listening for simulator:" << simulatorInfo.toQString(true); CLogMessage(this).debug() << "Listening for simulator: " << simulatorInfo.toQString(true);
} }
void CContextSimulator::listenForAllSimulators() void CContextSimulator::listenForAllSimulators()
{ {
auto plugins = getAvailableSimulatorPlugins(); auto plugins = getAvailableSimulatorPlugins();
for (const auto &p: plugins) for (const auto &p : plugins)
{
listenForSimulator(p); listenForSimulator(p);
}
} }
void CContextSimulator::listenForSimulatorFromSettings() void CContextSimulator::listenForSimulatorFromSettings()
@@ -534,7 +544,7 @@ namespace BlackCore
// todo: // todo:
// This was previously an assert and it should be one again in the future. // This was previously an assert and it should be one again in the future.
// This slot should not even be called when no simulator is available. // This slot should not even be called when no simulator is available.
if(!m_simulator) if (!m_simulator)
{ {
// Do something if no simulator is running // Do something if no simulator is running
return; return;
@@ -551,7 +561,7 @@ namespace BlackCore
// todo: // todo:
// This was previously an assert and it should be one again in the future. // This was previously an assert and it should be one again in the future.
// This slot should not even be called when no simulator is available. // This slot should not even be called when no simulator is available.
if(!m_simulator) if (!m_simulator)
{ {
// Do something if no simulator is running // Do something if no simulator is running
return; return;
@@ -580,7 +590,7 @@ namespace BlackCore
// todo: // todo:
// This was previously an assert and it should be one again in the future. // This was previously an assert and it should be one again in the future.
// This slot should not even be called when no simulator is available. // This slot should not even be called when no simulator is available.
if(!m_simulator) if (!m_simulator)
{ {
// Do something if no simulator is running // Do something if no simulator is running
return; return;
@@ -617,7 +627,7 @@ namespace BlackCore
// todo: // todo:
// This was previously an assert and it should be one again in the future. // This was previously an assert and it should be one again in the future.
// This slot should not even be called when no simulator is available. // This slot should not even be called when no simulator is available.
if(!m_simulator) if (!m_simulator)
{ {
// Do something if no simulator is running // Do something if no simulator is running
return; return;
@@ -720,11 +730,11 @@ namespace BlackCore
Q_ASSERT(listener->inherits("BlackCore::ISimulatorListener")); Q_ASSERT(listener->inherits("BlackCore::ISimulatorListener"));
/* Find caller */ /* Find caller */
PluginData *plugin = [this](QObject *listener) PluginData *plugin = [this](QObject * listener)
{ {
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [listener](const PluginData &plugin) auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [listener](const PluginData & plugin)
{ {
return plugin.listener == listener; return plugin.listener == listener;
}); });
return &(*it); return &(*it);
}(listener); }(listener);
@@ -747,7 +757,7 @@ namespace BlackCore
QStringList fileNames = m_pluginsDir.entryList(QDir::Files); QStringList fileNames = m_pluginsDir.entryList(QDir::Files);
fileNames.sort(Qt::CaseInsensitive); // give a certain order, rather than random file order fileNames.sort(Qt::CaseInsensitive); // give a certain order, rather than random file order
for (const auto& fileName: fileNames) for (const auto &fileName : fileNames)
{ {
if (!QLibrary::isLibrary(fileName)) if (!QLibrary::isLibrary(fileName))
{ {
@@ -762,7 +772,7 @@ namespace BlackCore
simulatorPluginInfo.convertFromJson(json); simulatorPluginInfo.convertFromJson(json);
if (simulatorPluginInfo.isValid()) if (simulatorPluginInfo.isValid())
{ {
m_simulatorPlugins << PluginData{ simulatorPluginInfo, nullptr, nullptr, nullptr, pluginPath}; m_simulatorPlugins << PluginData { simulatorPluginInfo, nullptr, nullptr, nullptr, pluginPath};
CLogMessage(this).debug() << "Found simulator driver: " << simulatorPluginInfo.toQString(); CLogMessage(this).debug() << "Found simulator driver: " << simulatorPluginInfo.toQString();
} }
else else
@@ -774,7 +784,7 @@ namespace BlackCore
void CContextSimulator::stopSimulatorListeners() void CContextSimulator::stopSimulatorListeners()
{ {
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [](PluginData& plugin) std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [](PluginData & plugin)
{ {
if (plugin.listener) if (plugin.listener)
QMetaObject::invokeMethod(plugin.listener, "stop"); QMetaObject::invokeMethod(plugin.listener, "stop");
@@ -783,7 +793,7 @@ namespace BlackCore
CContextSimulator::PluginData *CContextSimulator::findPlugin(const CSimulatorPluginInfo &info) CContextSimulator::PluginData *CContextSimulator::findPlugin(const CSimulatorPluginInfo &info)
{ {
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&info](PluginData& plugin) auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&info](PluginData & plugin)
{ {
return plugin.info == info; return plugin.info == info;
}); });

View File

@@ -9,6 +9,7 @@
#include "simulator.h" #include "simulator.h"
#include "interpolator.h" #include "interpolator.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/collection.h" #include "blackmisc/collection.h"
using namespace BlackMisc; using namespace BlackMisc;
@@ -23,26 +24,30 @@ namespace BlackCore
{ {
int status = int status =
(isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0)) (isConnected() ? Connected : static_cast<ISimulator::SimulatorStatus>(0))
| (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0)) | (isSimulating() ? Running : static_cast<ISimulator::SimulatorStatus>(0))
| (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0)) | (isPaused() ? Paused : static_cast<ISimulator::SimulatorStatus>(0))
; ;
emit simulatorStatusChanged(status); emit simulatorStatusChanged(status);
} }
ISimulatorListener::ISimulatorListener(QObject* parent) : QObject(parent) ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
{ { }
}
CSimulatorCommon::CSimulatorCommon(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, CSimulatorCommon::CSimulatorCommon(const CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent) QObject *parent)
: ISimulator(parent), : ISimulator(parent),
m_simulatorPluginInfo(info),
COwnAircraftAware(ownAircraftProvider), COwnAircraftAware(ownAircraftProvider),
CRemoteAircraftAware(remoteAircraftProvider) CRemoteAircraftAware(remoteAircraftProvider)
{ {
this->setObjectName("CSimulatorCommon");
m_oneSecondTimer = new QTimer(this); m_oneSecondTimer = new QTimer(this);
m_oneSecondTimer->setObjectName(this->objectName().append(":OneSecondTimer"));
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer); connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
m_oneSecondTimer->start(1000); m_oneSecondTimer->start(1000);
CLogMessage(this).info("Initialized simulator driver %1") << m_simulatorPluginInfo.toQString();
} }
void CSimulatorCommon::blinkHighlightedAircraft() void CSimulatorCommon::blinkHighlightedAircraft()
@@ -235,6 +240,11 @@ namespace BlackCore
return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted(); return this->isMaxDistanceRestricted() || this->isMaxAircraftRestricted();
} }
const CSimulatorPluginInfo &CSimulatorCommon::getSimulatorPluginInfo() const
{
return m_simulatorPluginInfo;
}
void CSimulatorCommon::deleteAllRenderingRestrictions() void CSimulatorCommon::deleteAllRenderingRestrictions()
{ {
if (!isRenderingEnabled()) { return; } if (!isRenderingEnabled()) { return; }

View File

@@ -62,6 +62,9 @@ namespace BlackCore
//! Simulator running? //! Simulator running?
virtual bool isSimulating() const = 0; virtual bool isSimulating() const = 0;
//! Get the simulator info
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const = 0;
//! Originator //! Originator
const QString &simulatorOriginator() const QString &simulatorOriginator()
{ {
@@ -212,7 +215,7 @@ namespace BlackCore
//! Constructor //! Constructor
//! \sa ISimulatorFactory::createListener(). //! \sa ISimulatorFactory::createListener().
//! \note msvc2015: use inherited constructor //! \note msvc2015: use inherited constructor
ISimulatorListener(QObject* parent); ISimulatorListener(QObject *parent);
//! Destructor //! Destructor
virtual ~ISimulatorListener() = default; virtual ~ISimulatorListener() = default;
@@ -241,12 +244,14 @@ namespace BlackCore
//! //!
//! Create a new instance of a driver //! Create a new instance of a driver
//! \param info metadata about simulator
//! \param ownAircraftProvider in memory access to own aircraft data //! \param ownAircraftProvider in memory access to own aircraft data
//! \param renderedAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself //! \param renderedAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself
//! \param parent QObject //! \param parent QObject
//! \return driver instance //! \return driver instance
//! //!
virtual ISimulator *create( virtual ISimulator *create(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent = nullptr) = 0; QObject *parent = nullptr) = 0;
@@ -302,6 +307,9 @@ namespace BlackCore
//! \copydoc IContextSimulator::isRenderingRestricted //! \copydoc IContextSimulator::isRenderingRestricted
virtual bool isRenderingRestricted() const override; virtual bool isRenderingRestricted() const override;
//! \copydoc IContextSimulator::getSimulatorPluginInfo
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const override;
//! \copydoc IContextSimulator::deleteAllRenderingRestrictions //! \copydoc IContextSimulator::deleteAllRenderingRestrictions
virtual void deleteAllRenderingRestrictions(); virtual void deleteAllRenderingRestrictions();
@@ -311,10 +319,10 @@ namespace BlackCore
protected: protected:
//! Constructor //! Constructor
CSimulatorCommon( CSimulatorCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent = nullptr); QObject *parent = nullptr);
//! Blink the highlighted aircraft //! Blink the highlighted aircraft
void blinkHighlightedAircraft(); void blinkHighlightedAircraft();
@@ -334,8 +342,9 @@ namespace BlackCore
qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting qint64 m_highlightEndTimeMsEpoch = 0; //!< end highlighting
int m_timerCounter = 0; //!< allows to calculate n seconds int m_timerCounter = 0; //!< allows to calculate n seconds
QTimer *m_oneSecondTimer = nullptr; //!< timer QTimer *m_oneSecondTimer = nullptr; //!< timer
BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorPluginInfo; //!< info object
BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored BlackMisc::Simulation::CSimulatedAircraftList m_highlightedAircraft; //!< all other aircraft are to be ignored
BlackMisc::Aviation::CCallsignSet m_callsignsToBeRendered; //!< callsigns which will be rendered BlackMisc::Aviation::CCallsignSet m_callsignsToBeRendered; //!< callsigns which will be rendered
int m_maxRenderedAircraft = MaxAircraftInfinite; //!< max.rendered aircraft int m_maxRenderedAircraft = MaxAircraftInfinite; //!< max.rendered aircraft
BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< max.distance for rendering BlackMisc::PhysicalQuantities::CLength m_maxRenderedDistance { 0.0, BlackMisc::PhysicalQuantities::CLengthUnit::nullUnit()}; //!< max.distance for rendering
}; };

View File

@@ -108,10 +108,11 @@ namespace BlackGui
return; return;
} }
int p = port.toInt(); int p = port.toInt();
//! \todo filename is only available if driver has been loaded
QString fileName = this->getIContextSimulator()->getSimulatorInfo().getSimulatorSetupValueAsString(CFsxSimulatorSetup::SetupSimConnectCfgFile); QString fileName = this->getIContextSimulator()->getSimulatorInfo().getSimulatorSetupValueAsString(CFsxSimulatorSetup::SetupSimConnectCfgFile);
if (fileName.isEmpty()) if (fileName.isEmpty())
{ {
CLogMessage(this).validationError("Invalid filename or filename empty"); CLogMessage(this).validationError("Invalid or empty filename empty, driver loaded?");
return; return;
} }

View File

@@ -52,8 +52,14 @@ namespace BlackMisc
QString CSimulatorPluginInfo::getSimulatorSetupValueAsString(int index) const QString CSimulatorPluginInfo::getSimulatorSetupValueAsString(int index) const
{ {
CVariant qv = getSimulatorSetupValue(index); CVariant qv = getSimulatorSetupValue(index);
Q_ASSERT(qv.canConvert<QString>()); if (qv.canConvert<QString>())
return qv.toQString(); {
return qv.toQString();
}
else
{
return "";
}
} }
void CSimulatorPluginInfo::setSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &setup) void CSimulatorPluginInfo::setSimulatorSetup(const BlackMisc::CPropertyIndexVariantMap &setup)

View File

@@ -34,7 +34,8 @@ using namespace BlackSimPlugin::Fs9;
using namespace BlackSimPlugin::FsCommon; using namespace BlackSimPlugin::FsCommon;
namespace { namespace
{
/* These instances should be global, as they are shared between all classes /* These instances should be global, as they are shared between all classes
* this file contains. They are instantied by CFs9Factory. */ * this file contains. They are instantied by CFs9Factory. */
QSharedPointer<CFs9Host> fs9Host; QSharedPointer<CFs9Host> fs9Host;
@@ -45,9 +46,12 @@ namespace BlackSimPlugin
{ {
namespace Fs9 namespace Fs9
{ {
CSimulatorFs9::CSimulatorFs9(IOwnAircraftProvider *ownAircraftProvider, CSimulatorFs9::CSimulatorFs9(
IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent) : const CSimulatorPluginInfo &info,
CSimulatorFsCommon(ownAircraftProvider, remoteAircraftProvider, parent) IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent) :
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
{ {
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0)); connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
connect(fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::ps_processFs9Message); connect(fs9Host.data(), &CFs9Host::customPacketReceived, this, &CSimulatorFs9::ps_processFs9Message);
@@ -288,7 +292,7 @@ namespace BlackSimPlugin
if (m_lobbyConnected || lobbyClient->connectFs9ToHost(fs9Host->getHostAddress()) == S_OK) if (m_lobbyConnected || lobbyClient->connectFs9ToHost(fs9Host->getHostAddress()) == S_OK)
{ {
m_lobbyConnected = true; m_lobbyConnected = true;
CLogMessage(this).info("Swift is joining FS9 to the multiplayer session..."); CLogMessage(this).info("Swift is joining FS9 to the multiplayer session...");
} }
if (m_lobbyConnected && fs9Host->isConnected()) if (m_lobbyConnected && fs9Host->isConnected())
@@ -332,11 +336,12 @@ namespace BlackSimPlugin
} }
BlackCore::ISimulator *CSimulatorFs9Factory::create( BlackCore::ISimulator *CSimulatorFs9Factory::create(
IOwnAircraftProvider *ownAircraftProvider, const CSimulatorPluginInfo &info,
IRemoteAircraftProvider *remoteAircraftProvider, IOwnAircraftProvider *ownAircraftProvider,
QObject *parent) IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent)
{ {
return new CSimulatorFs9(ownAircraftProvider, remoteAircraftProvider, parent); return new CSimulatorFs9(info, ownAircraftProvider, remoteAircraftProvider, parent);
} }
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent) BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent)

View File

@@ -40,6 +40,7 @@ namespace BlackSimPlugin
public: public:
//! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create //! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create
CSimulatorFs9( CSimulatorFs9(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent = nullptr); QObject *parent = nullptr);
@@ -112,12 +113,13 @@ namespace BlackSimPlugin
//! Listener starts the FS9 multiplayer host and tries to make the running instance //! Listener starts the FS9 multiplayer host and tries to make the running instance
//! of simulator to connect to it. When emitting the simulatorStarted() signal, //! of simulator to connect to it. When emitting the simulatorStarted() signal,
//! FS9 is already connected. //! FS9 is already connected.
class CSimulatorFs9Listener : public BlackCore::ISimulatorListener { class CSimulatorFs9Listener : public BlackCore::ISimulatorListener
{
Q_OBJECT Q_OBJECT
public: public:
//! Constructor //! Constructor
CSimulatorFs9Listener(QObject* parent); CSimulatorFs9Listener(QObject *parent);
public slots: public slots:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::start
@@ -128,7 +130,7 @@ namespace BlackSimPlugin
private: private:
QTimer* m_timer = nullptr; QTimer *m_timer = nullptr;
bool m_lobbyConnected = false; bool m_lobbyConnected = false;
}; };
@@ -142,16 +144,17 @@ namespace BlackSimPlugin
public: public:
//! Constructor //! Constructor
CSimulatorFs9Factory(QObject* parent = nullptr); CSimulatorFs9Factory(QObject *parent = nullptr);
//! Destructor //! Destructor
virtual ~CSimulatorFs9Factory(); virtual ~CSimulatorFs9Factory();
//! \copydoc BlackCore::ISimulatorFactory::create(ownAircraftProvider, remoteAircraftProvider, parent) //! \copydoc BlackCore::ISimulatorFactory::create(ownAircraftProvider, remoteAircraftProvider, parent)
virtual BlackCore::ISimulator *create( virtual BlackCore::ISimulator *create(
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
QObject *parent) override; BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent) override;
//! \copydoc BlackCore::ISimulatorFactory::createListener //! \copydoc BlackCore::ISimulatorFactory::createListener
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override; virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;

View File

@@ -25,8 +25,12 @@ namespace BlackSimPlugin
{ {
namespace FsCommon namespace FsCommon
{ {
CSimulatorFsCommon::CSimulatorFsCommon(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *renderedAircraftProvider, QObject *parent) : CSimulatorFsCommon::CSimulatorFsCommon(
CSimulatorCommon(ownAircraftProvider, renderedAircraftProvider, parent), const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent) :
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, parent),
m_fsuipc(new FsCommon::CFsuipc()) m_fsuipc(new FsCommon::CFsuipc())
{ {
// hack to init mapper // hack to init mapper

View File

@@ -80,7 +80,7 @@ namespace BlackSimPlugin
protected: protected:
//! Constructor //! Constructor
CSimulatorFsCommon( CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent = nullptr); QObject *parent = nullptr);

View File

@@ -38,17 +38,22 @@ namespace BlackSimPlugin
{ {
namespace Fsx namespace Fsx
{ {
CSimulatorFsx::CSimulatorFsx(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent) : CSimulatorFsx::CSimulatorFsx(
CSimulatorFsCommon(ownAircraftProvider, remoteAircraftProvider, parent) const CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent) :
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
{ {
Q_ASSERT(ownAircraftProvider); Q_ASSERT(ownAircraftProvider);
Q_ASSERT(remoteAircraftProvider); Q_ASSERT(remoteAircraftProvider);
CFsxSimulatorSetup setup; CFsxSimulatorSetup setup;
setup.init(); // this fetches important settings on local side setup.init(); // this fetches important settings on local side
this->m_simulatorPluginInfo.setSimulatorSetup(setup.getSettings());
m_useFsuipc = false; // do not use FSUIPC at the moment with FSX m_useFsuipc = false; // do not use FSUIPC at the moment with FSX
this->m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this); this->m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this);
this->m_interpolator->start(); this->m_interpolator->start();
this->m_simulatorInfo.setSimulatorSetup(setup.getSettings());
} }
CSimulatorFsx::~CSimulatorFsx() CSimulatorFsx::~CSimulatorFsx()
@@ -334,7 +339,8 @@ namespace BlackSimPlugin
void CSimulatorFsx::onSimStopped() void CSimulatorFsx::onSimStopped()
{ {
if (m_simRunning) { if (m_simRunning)
{
m_simRunning = false; m_simRunning = false;
mapperInstance()->gracefulShutdown(); // stop background reading if ongoing mapperInstance()->gracefulShutdown(); // stop background reading if ongoing
} }
@@ -814,7 +820,8 @@ namespace BlackSimPlugin
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
m_timer->setInterval(QueryInterval); m_timer->setInterval(QueryInterval);
connect(m_timer, &QTimer::timeout, [this]() { connect(m_timer, &QTimer::timeout, [this]()
{
HANDLE hSimConnect; HANDLE hSimConnect;
HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0); HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0);
SimConnect_Close(hSimConnect); SimConnect_Close(hSimConnect);

View File

@@ -74,6 +74,7 @@ namespace BlackSimPlugin
public: public:
//! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create //! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create
CSimulatorFsx( CSimulatorFsx(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent = nullptr); QObject *parent = nullptr);
@@ -195,7 +196,6 @@ namespace BlackSimPlugin
uint m_nextObjID = 1; //!< object ID TODO: also used as request id, where to we place other request ids as for facilities uint m_nextObjID = 1; //!< object ID TODO: also used as request id, where to we place other request ids as for facilities
QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects; QHash<BlackMisc::Aviation::CCallsign, CSimConnectObject> m_simConnectObjects;
QFutureWatcher<bool> m_watcherConnect; QFutureWatcher<bool> m_watcherConnect;
BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorInfo;
// statistics // statistics
qint64 m_statsUpdateAircraftTimeTotal = 0; qint64 m_statsUpdateAircraftTimeTotal = 0;
@@ -204,12 +204,13 @@ namespace BlackSimPlugin
}; };
//! Listener for FSX //! Listener for FSX
class CSimulatorFsxListener : public BlackCore::ISimulatorListener { class CSimulatorFsxListener : public BlackCore::ISimulatorListener
{
Q_OBJECT Q_OBJECT
public: public:
//! Constructor //! Constructor
CSimulatorFsxListener(QObject* parent); CSimulatorFsxListener(QObject *parent);
public slots: public slots:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::start
@@ -219,7 +220,7 @@ namespace BlackSimPlugin
virtual void stop() override; virtual void stop() override;
private: private:
QTimer* m_timer; QTimer *m_timer;
}; };
} }

View File

@@ -18,10 +18,10 @@ namespace BlackSimPlugin
{ {
namespace Fsx namespace Fsx
{ {
BlackCore::ISimulator *CSimulatorFsxFactory::create(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, QObject *parent) BlackCore::ISimulator *CSimulatorFsxFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, QObject *parent)
{ {
Q_ASSERT(ownAircraftProvider); Q_ASSERT(ownAircraftProvider);
return new CSimulatorFsx(ownAircraftProvider, renderedAircraftProvider, parent); return new CSimulatorFsx(info, ownAircraftProvider, renderedAircraftProvider, parent);
} }
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(QObject *parent) BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(QObject *parent)

View File

@@ -27,16 +27,15 @@ namespace BlackSimPlugin
class CSimulatorFsxFactory : public QObject, public BlackCore::ISimulatorFactory class CSimulatorFsxFactory : public QObject, public BlackCore::ISimulatorFactory
{ {
Q_OBJECT Q_OBJECT
// TODO: @RW, move this string into CProject please
Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface" FILE "simulator_fsx.json") Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface" FILE "simulator_fsx.json")
Q_INTERFACES(BlackCore::ISimulatorFactory) Q_INTERFACES(BlackCore::ISimulatorFactory)
public: public:
//! \copydoc BlackCore::ISimulatorFactory::create //! \copydoc BlackCore::ISimulatorFactory::create
virtual BlackCore::ISimulator *create( virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent) override; QObject *parent) override;
//! \copydoc BlackCore::ISimulatorFactory::getListener //! \copydoc BlackCore::ISimulatorFactory::getListener
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override; virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;

View File

@@ -24,8 +24,10 @@ using namespace BlackMisc::Simulation;
using namespace BlackMisc::Geo; using namespace BlackMisc::Geo;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
namespace { namespace
inline QString xbusServiceName() { {
inline QString xbusServiceName()
{
return QStringLiteral("org.swift.xbus"); return QStringLiteral("org.swift.xbus");
} }
} }
@@ -35,8 +37,12 @@ namespace BlackSimPlugin
namespace XPlane namespace XPlane
{ {
CSimulatorXPlane::CSimulatorXPlane(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent) : CSimulatorXPlane::CSimulatorXPlane(
CSimulatorCommon(ownAircraftProvider, remoteAircraftProvider, parent) const BlackMisc::Simulation::CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent) :
CSimulatorCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
{ {
m_watcher = new QDBusServiceWatcher(this); m_watcher = new QDBusServiceWatcher(this);
m_watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); m_watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
@@ -161,7 +167,8 @@ namespace BlackSimPlugin
bool CSimulatorXPlane::connectTo() bool CSimulatorXPlane::connectTo()
{ {
if (isConnected()) { if (isConnected())
{
qWarning("X-Plane already connected"); qWarning("X-Plane already connected");
return true; return true;
} }
@@ -170,7 +177,8 @@ namespace BlackSimPlugin
m_service = new CXBusServiceProxy(m_conn, this); m_service = new CXBusServiceProxy(m_conn, this);
m_traffic = new CXBusTrafficProxy(m_conn, this); m_traffic = new CXBusTrafficProxy(m_conn, this);
if (m_service->isValid() && m_traffic->isValid() && m_traffic->initialize()) { if (m_service->isValid() && m_traffic->isValid() && m_traffic->initialize())
{
// FIXME duplication // FIXME duplication
connect(m_service, &CXBusServiceProxy::aircraftModelChanged, this, &CSimulatorXPlane::ps_emitOwnAircraftModelChanged); connect(m_service, &CXBusServiceProxy::aircraftModelChanged, this, &CSimulatorXPlane::ps_emitOwnAircraftModelChanged);
connect(m_service, &CXBusServiceProxy::airportsInRangeUpdated, this, &CSimulatorXPlane::ps_setAirportsInRange); connect(m_service, &CXBusServiceProxy::airportsInRangeUpdated, this, &CSimulatorXPlane::ps_setAirportsInRange);
@@ -178,7 +186,9 @@ namespace BlackSimPlugin
m_watcher->setConnection(m_conn); m_watcher->setConnection(m_conn);
emitSimulatorCombinedStatus(); emitSimulatorCombinedStatus();
return true; return true;
} else { }
else
{
disconnectFrom(); disconnectFrom();
return false; return false;
} }
@@ -192,7 +202,8 @@ namespace BlackSimPlugin
bool CSimulatorXPlane::disconnectFrom() bool CSimulatorXPlane::disconnectFrom()
{ {
if (m_traffic) { if (m_traffic)
{
m_traffic->cleanup(); m_traffic->cleanup();
} }
@@ -427,12 +438,16 @@ namespace BlackSimPlugin
return true; return true;
} }
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *renderedAircraftProvider, QObject *parent) BlackCore::ISimulator *CSimulatorXPlaneFactory::create(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent)
{ {
return new CSimulatorXPlane(ownAircraftProvider, renderedAircraftProvider, parent); return new CSimulatorXPlane(info, ownAircraftProvider, renderedAircraftProvider, parent);
} }
CSimulatorXPlaneListener::CSimulatorXPlaneListener(QObject* parent): ISimulatorListener(parent) CSimulatorXPlaneListener::CSimulatorXPlaneListener(QObject *parent): ISimulatorListener(parent)
{ {
} }
@@ -449,7 +464,8 @@ namespace BlackSimPlugin
void CSimulatorXPlaneListener::stop() void CSimulatorXPlaneListener::stop()
{ {
if (m_watcher) { if (m_watcher)
{
m_watcher->deleteLater(); m_watcher->deleteLater();
m_watcher = nullptr; m_watcher = nullptr;
} }

View File

@@ -35,10 +35,10 @@ namespace BlackSimPlugin
public: public:
//! \copydoc BlackCore::ISimulatorFactory::create(ownAircraftProvider, remoteAircraftProvider, parent) //! \copydoc BlackCore::ISimulatorFactory::create(ownAircraftProvider, remoteAircraftProvider, parent)
CSimulatorXPlane( CSimulatorXPlane(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
QObject *parent = nullptr); QObject *parent = nullptr);
//! \copydoc BlackCore::ISimulator::isConnected //! \copydoc BlackCore::ISimulator::isConnected
virtual bool isConnected() const override; virtual bool isConnected() const override;
@@ -179,7 +179,7 @@ namespace BlackSimPlugin
public: public:
//! Constructor //! Constructor
CSimulatorXPlaneListener(QObject* parent); CSimulatorXPlaneListener(QObject *parent);
public slots: public slots:
//! \copydoc BlackCore::ISimulatorListener::start //! \copydoc BlackCore::ISimulatorListener::start
@@ -193,7 +193,7 @@ namespace BlackSimPlugin
private: private:
QDBusConnection m_conn { "default" }; QDBusConnection m_conn { "default" };
QDBusServiceWatcher* m_watcher { nullptr }; QDBusServiceWatcher *m_watcher { nullptr };
}; };
@@ -206,16 +206,16 @@ namespace BlackSimPlugin
public: public:
//! \copydoc BlackCore::ISimulatorFactory::create() //! \copydoc BlackCore::ISimulatorFactory::create()
virtual BlackCore::ISimulator *create( virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
QObject *parent) override; QObject *parent) override;
//! \copydoc BlackCore::ISimulatorFactory::createListener //! \copydoc BlackCore::ISimulatorFactory::createListener
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(parent); } virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(parent); }
}; };
} } // ns
} } // ns
#endif // guard #endif // guard