mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 21:15:33 +08:00
refs #438, added plug info to listeners
* listener signal can be directly used without mapping * (during debugging) it is much easier to identify a listener
This commit is contained in:
@@ -34,13 +34,10 @@ using namespace BlackMisc::Simulation::Settings;
|
||||
namespace BlackCore
|
||||
{
|
||||
CContextSimulator::CContextSimulator(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
|
||||
IContextSimulator(mode, runtime),
|
||||
m_mapper(new QSignalMapper(this))
|
||||
IContextSimulator(mode, runtime)
|
||||
{
|
||||
this->setObjectName("CContextSimulator");
|
||||
findSimulatorPlugins();
|
||||
// Maps listener instance
|
||||
connect(m_mapper, static_cast<void (QSignalMapper::*)(QObject *)>(&QSignalMapper::mapped), this, &CContextSimulator::ps_simulatorStarted);
|
||||
}
|
||||
|
||||
CContextSimulator::~CContextSimulator()
|
||||
@@ -489,15 +486,13 @@ namespace BlackCore
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
|
||||
plugin->listener = factory->createListener();
|
||||
bool c = connect(plugin->listener, &ISimulatorListener::simulatorStarted,
|
||||
m_mapper, static_cast<void (QSignalMapper::*)()> (&QSignalMapper::map));
|
||||
plugin->listener = factory->createListener(simulatorInfo, this);
|
||||
bool c = connect(plugin->listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
|
||||
if (!c)
|
||||
{
|
||||
CLogMessage(this).error("Unable to use '%1'") << simulatorInfo.toQString();
|
||||
return;
|
||||
}
|
||||
m_mapper->setMapping(plugin->listener, plugin->listener);
|
||||
plugin->listener->moveToThread(&m_listenersThread);
|
||||
}
|
||||
|
||||
@@ -509,7 +504,9 @@ namespace BlackCore
|
||||
m_listenersThread.start(QThread::LowPriority);
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(listener, "start");
|
||||
bool s = QMetaObject::invokeMethod(listener, "start");
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method");
|
||||
Q_UNUSED(s);
|
||||
CLogMessage(this).debug() << "Listening for simulator: " << simulatorInfo.toQString(true);
|
||||
}
|
||||
|
||||
@@ -572,8 +569,7 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::ps_removedRemoteAircraft(const CCallsign &callsign)
|
||||
{
|
||||
// todo:
|
||||
// This was previously an assert and it should be one again in the future.
|
||||
// \fixme: 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.
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
@@ -695,25 +691,10 @@ namespace BlackCore
|
||||
this->m_simulatorPlugin->simulator->highlightAircraft(aircraftToHighlight, enableHighlight, displayTime);
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_simulatorStarted(QObject *listener)
|
||||
void CContextSimulator::ps_simulatorStarted(const CSimulatorPluginInfo &info)
|
||||
{
|
||||
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(plugin->info, false);
|
||||
loadSimulatorPlugin(info, false);
|
||||
}
|
||||
|
||||
void CContextSimulator::findSimulatorPlugins()
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace BlackCore
|
||||
void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);
|
||||
|
||||
//! Listener reports the simulator has started
|
||||
void ps_simulatorStarted(QObject *listener);
|
||||
void ps_simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
//! Simulator has changed cockpit
|
||||
void ps_cockpitChangedFromSimulator(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
|
||||
@@ -225,7 +225,6 @@ namespace BlackCore
|
||||
QList<PluginData> m_simulatorPlugins;
|
||||
PluginData *m_simulatorPlugin = nullptr; //!< Currently loaded simulator plugin
|
||||
BlackMisc::CRegularThread m_listenersThread;
|
||||
QSignalMapper *m_mapper = nullptr;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -59,7 +59,8 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
ISimulatorListener::ISimulatorListener(QObject *parent) : QObject(parent)
|
||||
ISimulatorListener::ISimulatorListener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
QObject(parent), m_info(info)
|
||||
{ }
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -245,11 +245,14 @@ namespace BlackCore
|
||||
//! Constructor
|
||||
//! \sa ISimulatorFactory::createListener().
|
||||
//! \note msvc2015: use inherited constructor
|
||||
ISimulatorListener(QObject *parent);
|
||||
ISimulatorListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
|
||||
//! Destructor
|
||||
virtual ~ISimulatorListener() = default;
|
||||
|
||||
//! Corresponding info
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &getPluginInfo() const { return m_info; }
|
||||
|
||||
public slots:
|
||||
//! Start listening for the simulator to start.
|
||||
virtual void start() = 0;
|
||||
@@ -259,7 +262,10 @@ namespace BlackCore
|
||||
|
||||
signals:
|
||||
//! Emitted when the listener discovers the simulator running.
|
||||
void simulatorStarted();
|
||||
void simulatorStarted(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
|
||||
|
||||
private:
|
||||
BlackMisc::Simulation::CSimulatorPluginInfo m_info;
|
||||
};
|
||||
|
||||
//! Factory pattern class to create instances of ISimulator
|
||||
@@ -283,7 +289,7 @@ namespace BlackCore
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) = 0;
|
||||
|
||||
//! Simulator listener instance
|
||||
virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0;
|
||||
virtual ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) = 0;
|
||||
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -327,8 +327,8 @@ namespace BlackSimPlugin
|
||||
return exclude;
|
||||
}
|
||||
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(QObject *parent) :
|
||||
BlackCore::ISimulatorListener(parent),
|
||||
CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
BlackCore::ISimulatorListener(info, parent),
|
||||
m_timer(new QTimer(this))
|
||||
{
|
||||
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||
@@ -353,7 +353,7 @@ namespace BlackSimPlugin
|
||||
|
||||
if (!m_isStarted && fs9Host->isConnected())
|
||||
{
|
||||
emit simulatorStarted();
|
||||
emit simulatorStarted(getPluginInfo());
|
||||
m_isStarted = true;
|
||||
m_isConnecting = false;
|
||||
}
|
||||
@@ -402,9 +402,9 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorFs9(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent)
|
||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(const CSimulatorPluginInfo &info, QObject *parent)
|
||||
{
|
||||
return new CSimulatorFs9Listener(parent);
|
||||
return new CSimulatorFs9Listener(info, parent);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorFs9Listener(QObject *parent);
|
||||
CSimulatorFs9Listener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
@@ -167,7 +167,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override;
|
||||
|
||||
};
|
||||
} // namespace Fs9
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace BlackSimPlugin
|
||||
namespace Fsx
|
||||
{
|
||||
CSimulatorFsx::CSimulatorFsx(const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider,
|
||||
simObjectsDir(), excludeDirectories(), parent)
|
||||
{
|
||||
@@ -54,11 +54,11 @@ namespace BlackSimPlugin
|
||||
m_useFsuipc = false; // do not use FSUIPC at the moment with FSX
|
||||
this->m_interpolator = new CInterpolatorLinear(remoteAircraftProvider, this);
|
||||
m_modelMatcher.setDefaultModel(CAircraftModel(
|
||||
"Boeing 737-800 Paint1",
|
||||
CAircraftModel::TypeModelMatchingDefaultModel,
|
||||
"B737-800 default model",
|
||||
CAircraftIcaoData(CAircraftIcaoCode("B738", "L2J"), CAirlineIcaoCode(), "FFFFFF")
|
||||
));
|
||||
"Boeing 737-800 Paint1",
|
||||
CAircraftModel::TypeModelMatchingDefaultModel,
|
||||
"B737-800 default model",
|
||||
CAircraftIcaoData(CAircraftIcaoCode("B738", "L2J"), CAirlineIcaoCode(), "FFFFFF")
|
||||
));
|
||||
}
|
||||
|
||||
CSimulatorFsx::~CSimulatorFsx()
|
||||
@@ -860,7 +860,8 @@ namespace BlackSimPlugin
|
||||
return exclude;
|
||||
}
|
||||
|
||||
CSimulatorFsxListener::CSimulatorFsxListener(QObject *parent) : ISimulatorListener(parent),
|
||||
CSimulatorFsxListener::CSimulatorFsxListener(const CSimulatorPluginInfo &info, QObject *parent) :
|
||||
ISimulatorListener(info, parent),
|
||||
m_timer(new QTimer(this))
|
||||
{
|
||||
Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds
|
||||
@@ -873,8 +874,7 @@ namespace BlackSimPlugin
|
||||
HANDLE hSimConnect;
|
||||
HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::systemNameAndVersionChar(), nullptr, 0, 0, 0);
|
||||
SimConnect_Close(hSimConnect);
|
||||
|
||||
if (result == S_OK) { emit simulatorStarted(); }
|
||||
if (result == S_OK) { emit simulatorStarted(this->getPluginInfo()); }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorFsxListener(QObject *parent);
|
||||
CSimulatorFsxListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
|
||||
@@ -27,9 +27,9 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorFsx(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(QObject *parent)
|
||||
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent)
|
||||
{
|
||||
return new CSimulatorFsxListener(parent);
|
||||
return new CSimulatorFsxListener(info, parent);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -24,7 +24,9 @@ namespace BlackSimPlugin
|
||||
namespace Fsx
|
||||
{
|
||||
//! Factory implementation to create CSimulatorFsx instances
|
||||
class CSimulatorFsxFactory : public QObject, public BlackCore::ISimulatorFactory
|
||||
class CSimulatorFsxFactory :
|
||||
public QObject,
|
||||
public BlackCore::ISimulatorFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.swift-project.blackcore.simulatorinterface" FILE "simulator_fsx.json")
|
||||
@@ -38,7 +40,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::getListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -430,7 +430,7 @@ namespace BlackSimPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider)
|
||||
@@ -438,19 +438,15 @@ namespace BlackSimPlugin
|
||||
return new CSimulatorXPlane(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
CSimulatorXPlaneListener::CSimulatorXPlaneListener(QObject *parent): ISimulatorListener(parent)
|
||||
{
|
||||
|
||||
}
|
||||
CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info, QObject *parent): ISimulatorListener(info, parent)
|
||||
{ }
|
||||
|
||||
void CSimulatorXPlaneListener::start()
|
||||
{
|
||||
if (m_watcher) // already started
|
||||
return;
|
||||
|
||||
if (m_watcher) { return; } // already started
|
||||
if (isXBusRunning())
|
||||
{
|
||||
emit simulatorStarted();
|
||||
emit simulatorStarted(getPluginInfo());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -486,7 +482,9 @@ namespace BlackSimPlugin
|
||||
void CSimulatorXPlaneListener::ps_serviceRegistered(const QString &serviceName)
|
||||
{
|
||||
if (serviceName == xbusServiceName())
|
||||
emit simulatorStarted();
|
||||
{
|
||||
emit simulatorStarted(getPluginInfo());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorXPlaneListener(QObject *parent);
|
||||
CSimulatorXPlaneListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent);
|
||||
|
||||
public slots:
|
||||
//! \copydoc BlackCore::ISimulatorListener::start
|
||||
@@ -205,7 +205,6 @@ namespace BlackSimPlugin
|
||||
private:
|
||||
QDBusConnection m_conn { "default" };
|
||||
QDBusServiceWatcher *m_watcher { nullptr };
|
||||
|
||||
};
|
||||
|
||||
//! Factory for creating CSimulatorXPlane instance
|
||||
@@ -223,7 +222,7 @@ namespace BlackSimPlugin
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(parent); }
|
||||
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info, QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(info, parent); }
|
||||
};
|
||||
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user