Listen for X-Plane to start

This commit is contained in:
Michał Garapich
2015-03-31 20:10:17 +02:00
committed by Roland Winklmeier
parent adc623f0e7
commit 45f48f7594
6 changed files with 91 additions and 5 deletions

View File

@@ -196,11 +196,12 @@ namespace BlackCore
if (this->m_contextSettings)
{
connect(this->m_contextSettings, &IContextSettings::changedSettings, this->m_contextSimulator, &IContextSimulator::settingsChanged);
if (!this->m_contextSimulator->loadSimulatorPluginFromSettings())
{
CLogMessage(this).warning("No simulator plugin loaded");
}
times.insert("Post setup, load sim. plugin", time.restart());
// if (!this->m_contextSimulator->loadSimulatorPluginFromSettings())
// {
// CLogMessage(this).warning("No simulator plugin loaded");
// }
this->m_contextSimulator->listenForSimulatorFromSettings();
times.insert("Post setup, load sim. listener(s)", time.restart());
}
}

View File

@@ -170,6 +170,12 @@ namespace BlackCore
//! 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;
//! Listen for simulator as set in settings
virtual void listenForSimulatorFromSettings() = 0;
//! Unload simulator plugin
virtual void unloadSimulatorPlugin() = 0;

View File

@@ -356,6 +356,44 @@ namespace BlackCore
return false;
}
}
void CContextSimulator::listenForSimulator(const CSimulatorInfo &simulatorInfo)
{
Q_ASSERT(this->getIContextApplication());
Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject());
if (this->m_simulator && this->m_simulator->getSimulatorInfo() == simulatorInfo) { // already loaded
qWarning("Cannot listen for simulator while still plugin is loaded");
return;
}
if (simulatorInfo.isUnspecified()) {
return;
}
// warning if we do not have any plugins
if (m_simulatorListeners.isEmpty()) {
CLogMessage(this).error("No simulator listeners");
return;
}
if (!m_simulatorListeners.contains(simulatorInfo)) {
CLogMessage(this).error("Listener not found for '%1'") << simulatorInfo.toQString(true);
return;
} else {
ISimulatorListener *listener = m_simulatorListeners[simulatorInfo];
Q_ASSERT(listener);
listener->start();
CLogMessage(this).info("Listening for simulator: '%1'") << simulatorInfo.toQString(true);
}
}
void CContextSimulator::listenForSimulatorFromSettings()
{
Q_ASSERT(this->getIContextSettings());
listenForSimulator(getIContextSettings()->getSimulatorSettings().getSelectedPlugin());
}
void CContextSimulator::unloadSimulatorPlugin()
{
@@ -505,6 +543,12 @@ namespace BlackCore
if (!this->m_simulator) return false;
return this->m_simulator->isSimulating();
}
void CContextSimulator::ps_simulatorStarted(CSimulatorInfo simulatorInfo)
{
CLogMessage(this).info("Simulator %1 started.") << simulatorInfo.toQString();
loadSimulatorPlugin(simulatorInfo);
}
void CContextSimulator::findSimulatorPlugins()
{
@@ -532,6 +576,15 @@ namespace BlackCore
{
CSimulatorInfo simulatorInfo = factory->getSimulatorInfo();
m_simulatorFactories.insert(factory);
ISimulatorListener *listener = factory->createListener(this);
Q_ASSERT(listener);
Q_ASSERT(listener->parent() == this); // requirement
m_simulatorListeners.insert(simulatorInfo, listener);
/* Will not happen unless start() is called */
connect(listener, &ISimulatorListener::simulatorStarted, this, &CContextSimulator::ps_simulatorStarted);
CLogMessage(this).info("Loaded plugin: %1") << simulatorInfo.toQString();
}
}

View File

@@ -124,6 +124,12 @@ namespace BlackCore
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
virtual bool loadSimulatorPluginFromSettings() override;
//! \copydoc IContextSimulator::listenForSimulator()
virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::listenForSimulatorFromSettings()
virtual void listenForSimulatorFromSettings() override;
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
virtual void unloadSimulatorPlugin() override;
@@ -164,6 +170,9 @@ namespace BlackCore
//! Text message received
void ps_textMessagesReceived(const BlackMisc::Network::CTextMessageList &textMessages);
//! Listener reports the simulator has started
void ps_simulatorStarted(BlackSim::CSimulatorInfo simulatorInfo);
//! Simulator has changed cockpit
void ps_cockitChangedFromSim(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft);
@@ -185,6 +194,7 @@ namespace BlackCore
BlackCore::ISimulator *m_simulator = nullptr; //!< simulator plugin
QDir m_pluginsDir;
QSet<ISimulatorFactory *> m_simulatorFactories;
QMap<BlackSim::CSimulatorInfo, ISimulatorListener *> m_simulatorListeners;
QFuture<bool> m_canConnectResult;
};

View File

@@ -186,6 +186,16 @@ namespace BlackCore
{
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPluginFromSettings"));
}
void CContextSimulatorProxy::listenForSimulator(const CSimulatorInfo &simulatorInfo)
{
m_dBusInterface->callDBus(QLatin1Literal("listenForSimulator"), simulatorInfo);
}
void CContextSimulatorProxy::listenForSimulatorFromSettings()
{
m_dBusInterface->callDBus(QLatin1Literal("listenForSimulatorFromSettings"));
}
void CContextSimulatorProxy::unloadSimulatorPlugin()
{

View File

@@ -127,6 +127,12 @@ namespace BlackCore
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
virtual bool loadSimulatorPluginFromSettings();
//! \copydoc IContextSimulator::listenForSimulator()
virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::listenForSimulatorFromSettings()
virtual void listenForSimulatorFromSettings() override;
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
virtual void unloadSimulatorPlugin() override;