From afc22397bb8f235e7e5c04cee107b1e1b11a6e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Garapich?= Date: Wed, 11 Feb 2015 18:54:11 +0100 Subject: [PATCH] JSON plugin metadata initial * Added json files along with FILE macro for all drivers * Get CSimulatorInfo from JSON rather than from ISimulatorFactory --- src/blackcore/context_simulator_impl.cpp | 4 +++- src/blackcore/simulator.h | 1 + src/blacksim/simulatorinfo.cpp | 8 ++++++++ src/blacksim/simulatorinfo.h | 3 +++ src/plugins/simulator/fs9/simulator_fs9.h | 2 +- src/plugins/simulator/fs9/simulator_fs9.json | 4 ++++ src/plugins/simulator/fsx/simulator_fsx.json | 4 ++++ src/plugins/simulator/fsx/simulator_fsxfactory.h | 2 +- src/plugins/simulator/xplane/simulator_xplane.h | 2 +- src/plugins/simulator/xplane/simulator_xplane.json | 4 ++++ 10 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/plugins/simulator/fs9/simulator_fs9.json create mode 100644 src/plugins/simulator/fsx/simulator_fsx.json create mode 100644 src/plugins/simulator/xplane/simulator_xplane.json diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index 41e4e0a7a..3b594a923 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -573,13 +573,15 @@ namespace BlackCore CLogMessage(this).info("Try to load plugin: %1") << fileName; QString pluginPath = m_pluginsDir.absoluteFilePath(fileName); QPluginLoader loader(pluginPath); + QJsonObject json = loader.metaData(); QObject *plugin = loader.instance(); if (plugin) { ISimulatorFactory *factory = qobject_cast(plugin); if (factory) { - CSimulatorInfo simulatorInfo = factory->getSimulatorInfo(); +// CSimulatorInfo simulatorInfo = factory->getSimulatorInfo(); + CSimulatorInfo simulatorInfo(json); m_simulatorFactories.insert(factory); ISimulatorListener *listener = factory->createListener(this); diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 9e6949a7f..549d03088 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -257,6 +257,7 @@ namespace BlackCore //! Simulator listener instance virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0; + }; //! Common base class with providers, interface and some base functionality diff --git a/src/blacksim/simulatorinfo.cpp b/src/blacksim/simulatorinfo.cpp index 9a4fa1179..42ac9506f 100644 --- a/src/blacksim/simulatorinfo.cpp +++ b/src/blacksim/simulatorinfo.cpp @@ -19,6 +19,14 @@ namespace BlackSim 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 { diff --git a/src/blacksim/simulatorinfo.h b/src/blacksim/simulatorinfo.h index a8a4dd7a7..e951b1aa1 100644 --- a/src/blacksim/simulatorinfo.h +++ b/src/blacksim/simulatorinfo.h @@ -26,6 +26,9 @@ namespace BlackSim //! Constructor CSimulatorInfo(const QString &shortname, const QString &fullname); + + //! This constructor takes a JSON object that comes with the driver. + CSimulatorInfo(const QJsonObject& json); //! Unspecified simulator bool isUnspecified() const { return this->m_shortName.isEmpty() || this->m_shortName.startsWith("Unspecified", Qt::CaseInsensitive); } diff --git a/src/plugins/simulator/fs9/simulator_fs9.h b/src/plugins/simulator/fs9/simulator_fs9.h index 20a71f10f..c9e2b914f 100644 --- a/src/plugins/simulator/fs9/simulator_fs9.h +++ b/src/plugins/simulator/fs9/simulator_fs9.h @@ -36,7 +36,7 @@ namespace BlackSimPlugin class CSimulatorFs9Factory : public QObject, public BlackCore::ISimulatorFactory { 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) public: diff --git a/src/plugins/simulator/fs9/simulator_fs9.json b/src/plugins/simulator/fs9/simulator_fs9.json new file mode 100644 index 000000000..2ca7d4a5f --- /dev/null +++ b/src/plugins/simulator/fs9/simulator_fs9.json @@ -0,0 +1,4 @@ +{ + "short_name" : "FS9", + "full_name" : "Microsoft Flight Simulator 2004" +} \ No newline at end of file diff --git a/src/plugins/simulator/fsx/simulator_fsx.json b/src/plugins/simulator/fsx/simulator_fsx.json new file mode 100644 index 000000000..6aed5f27c --- /dev/null +++ b/src/plugins/simulator/fsx/simulator_fsx.json @@ -0,0 +1,4 @@ +{ + "short_name" : "FSX", + "full_name" : "Microsoft Flight Simulator X (2006)" +} \ No newline at end of file diff --git a/src/plugins/simulator/fsx/simulator_fsxfactory.h b/src/plugins/simulator/fsx/simulator_fsxfactory.h index 5099ba315..bc5148b19 100644 --- a/src/plugins/simulator/fsx/simulator_fsxfactory.h +++ b/src/plugins/simulator/fsx/simulator_fsxfactory.h @@ -28,7 +28,7 @@ namespace BlackSimPlugin { Q_OBJECT // 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) public: diff --git a/src/plugins/simulator/xplane/simulator_xplane.h b/src/plugins/simulator/xplane/simulator_xplane.h index 246b216f7..71c6054f8 100644 --- a/src/plugins/simulator/xplane/simulator_xplane.h +++ b/src/plugins/simulator/xplane/simulator_xplane.h @@ -201,7 +201,7 @@ namespace BlackSimPlugin class CSimulatorXPlaneFactory : public QObject, public BlackCore::ISimulatorFactory { 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) public: diff --git a/src/plugins/simulator/xplane/simulator_xplane.json b/src/plugins/simulator/xplane/simulator_xplane.json new file mode 100644 index 000000000..1e44f0849 --- /dev/null +++ b/src/plugins/simulator/xplane/simulator_xplane.json @@ -0,0 +1,4 @@ +{ + "short_name" : "XP", + "full_name" : "X-Plane" +} \ No newline at end of file