mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 06:35:52 +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
|
||||
|
||||
Reference in New Issue
Block a user