JSON plugin metadata initial

* Added json files along with FILE macro for all drivers
* Get CSimulatorInfo from JSON rather than from ISimulatorFactory
This commit is contained in:
Michał Garapich
2015-02-11 18:54:11 +01:00
committed by Roland Winklmeier
parent c5a1a6048b
commit afc22397bb
10 changed files with 30 additions and 4 deletions

View File

@@ -573,13 +573,15 @@ namespace BlackCore
CLogMessage(this).info("Try to load plugin: %1") << fileName; CLogMessage(this).info("Try to load plugin: %1") << fileName;
QString pluginPath = m_pluginsDir.absoluteFilePath(fileName); QString pluginPath = m_pluginsDir.absoluteFilePath(fileName);
QPluginLoader loader(pluginPath); QPluginLoader loader(pluginPath);
QJsonObject json = loader.metaData();
QObject *plugin = loader.instance(); QObject *plugin = loader.instance();
if (plugin) if (plugin)
{ {
ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(plugin); ISimulatorFactory *factory = qobject_cast<ISimulatorFactory *>(plugin);
if (factory) if (factory)
{ {
CSimulatorInfo simulatorInfo = factory->getSimulatorInfo(); // CSimulatorInfo simulatorInfo = factory->getSimulatorInfo();
CSimulatorInfo simulatorInfo(json);
m_simulatorFactories.insert(factory); m_simulatorFactories.insert(factory);
ISimulatorListener *listener = factory->createListener(this); ISimulatorListener *listener = factory->createListener(this);

View File

@@ -257,6 +257,7 @@ namespace BlackCore
//! Simulator listener instance //! Simulator listener instance
virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0; virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0;
}; };
//! Common base class with providers, interface and some base functionality //! Common base class with providers, interface and some base functionality

View File

@@ -20,6 +20,14 @@ namespace BlackSim
CSimulatorInfo::CSimulatorInfo() : m_fullName("Unknown"), m_shortName("Unknown") CSimulatorInfo::CSimulatorInfo() : m_fullName("Unknown"), m_shortName("Unknown")
{} {}
CSimulatorInfo::CSimulatorInfo(const QJsonObject &json)
{
Q_ASSERT(json["IID"].toString() == "net.vatsim.PilotClient.BlackCore.SimulatorInterface");
QJsonObject data = json["MetaData"].toObject();
m_fullName = data["full_name"].toString("Unknown");
m_shortName = data["short_name"].toString("Unknown");
}
CVariant CSimulatorInfo::getSimulatorSetupValue(int index) const CVariant CSimulatorInfo::getSimulatorSetupValue(int index) const
{ {
return this->m_simsetup.value(index); return this->m_simsetup.value(index);

View File

@@ -27,6 +27,9 @@ namespace BlackSim
//! Constructor //! Constructor
CSimulatorInfo(const QString &shortname, const QString &fullname); CSimulatorInfo(const QString &shortname, const QString &fullname);
//! This constructor takes a JSON object that comes with the driver.
CSimulatorInfo(const QJsonObject& json);
//! Unspecified simulator //! Unspecified simulator
bool isUnspecified() const { return this->m_shortName.isEmpty() || this->m_shortName.startsWith("Unspecified", Qt::CaseInsensitive); } bool isUnspecified() const { return this->m_shortName.isEmpty() || this->m_shortName.startsWith("Unspecified", Qt::CaseInsensitive); }

View File

@@ -36,7 +36,7 @@ namespace BlackSimPlugin
class CSimulatorFs9Factory : public QObject, public BlackCore::ISimulatorFactory class CSimulatorFs9Factory : public QObject, public BlackCore::ISimulatorFactory
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface") Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface" FILE "simulator_fs9.json")
Q_INTERFACES(BlackCore::ISimulatorFactory) Q_INTERFACES(BlackCore::ISimulatorFactory)
public: public:

View File

@@ -0,0 +1,4 @@
{
"short_name" : "FS9",
"full_name" : "Microsoft Flight Simulator 2004"
}

View File

@@ -0,0 +1,4 @@
{
"short_name" : "FSX",
"full_name" : "Microsoft Flight Simulator X (2006)"
}

View File

@@ -28,7 +28,7 @@ namespace BlackSimPlugin
{ {
Q_OBJECT Q_OBJECT
// TODO: @RW, move this string into CProject please // TODO: @RW, move this string into CProject please
Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface") Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface" FILE "simulator_fsx.json")
Q_INTERFACES(BlackCore::ISimulatorFactory) Q_INTERFACES(BlackCore::ISimulatorFactory)
public: public:

View File

@@ -201,7 +201,7 @@ namespace BlackSimPlugin
class CSimulatorXPlaneFactory : public QObject, public BlackCore::ISimulatorFactory class CSimulatorXPlaneFactory : public QObject, public BlackCore::ISimulatorFactory
{ {
Q_OBJECT Q_OBJECT
Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface") Q_PLUGIN_METADATA(IID "org.swift.pilotclient.BlackCore.SimulatorInterface" FILE "simulator_xplane.json")
Q_INTERFACES(BlackCore::ISimulatorFactory) Q_INTERFACES(BlackCore::ISimulatorFactory)
public: public:

View File

@@ -0,0 +1,4 @@
{
"short_name" : "XP",
"full_name" : "X-Plane"
}