Find and catalog all plugins in findSimulatorPlugins

refs #215
This commit is contained in:
Roland Winklmeier
2014-04-21 22:44:27 +02:00
parent 7a2d957349
commit 04906e4bfc
2 changed files with 9 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ namespace BlackCore
m_simulator(nullptr), m_updateTimer(nullptr) m_simulator(nullptr), m_updateTimer(nullptr)
{ {
m_updateTimer = new QTimer(this); m_updateTimer = new QTimer(this);
loadPlugins(); findSimulatorPlugins();
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft); connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
connectTo(); connectTo();
} }
@@ -89,7 +89,7 @@ namespace BlackCore
emit connectionChanged(value); emit connectionChanged(value);
} }
void CContextSimulator::loadPlugins() void CContextSimulator::findSimulatorPlugins()
{ {
m_pluginsDir = QDir(qApp->applicationDirPath().append("/plugins/simulator")); m_pluginsDir = QDir(qApp->applicationDirPath().append("/plugins/simulator"));
if (!m_pluginsDir.exists()) if (!m_pluginsDir.exists())
@@ -107,9 +107,9 @@ namespace BlackCore
ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(plugin); ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(plugin);
if (factory) if (factory)
{ {
m_simulator = factory->create(this); CSimulatorInfo simulatorInfo = factory->getSimulatorInfo();
connect(m_simulator, SIGNAL(connectionChanged(bool)), this, SLOT(setConnectionStatus(bool))); qDebug() << "Found simulator plugin: " << simulatorInfo.toQString();
qDebug() << "Simulator plugin:" << m_simulator->getSimulatorInfo().toQString(); m_simulatorFactories.insert(factory);
break; break;
} }
} }

View File

@@ -68,16 +68,14 @@ namespace BlackCore
void setConnectionStatus(bool value); void setConnectionStatus(bool value);
private: private:
/*! //! \brief find and catalog all simulator plugins
* \brief Load any kind of plugins void findSimulatorPlugins();
* \todo Currently it goes through the plugins folder and creates an instance for any plugin it may find
* In case an FSX and an X-Plane are in that folder, m_simulator will always point to X-Plane in the end.
*/
void loadPlugins();
BlackMisc::Aviation::CAircraft m_ownAircraft; BlackMisc::Aviation::CAircraft m_ownAircraft;
BlackCore::ISimulator *m_simulator; BlackCore::ISimulator *m_simulator;
QTimer *m_updateTimer; QTimer *m_updateTimer;
QDir m_pluginsDir; QDir m_pluginsDir;
QSet<ISimulatorFactory*> m_simulatorFactories;
}; };
} // namespace BlackCore } // namespace BlackCore