From 6a8894116613742755330fa731e5832dfa38a516 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 10 Jan 2019 13:59:28 -0800 Subject: [PATCH] put a plugin-interface version into the meta data of each plugin. don't load plugins that don't match the current version. --- .../plugins/src/plugins/PluginManager.cpp | 24 ++++++++++++++++++- libraries/plugins/src/plugins/PluginManager.h | 2 ++ plugins/hifiCodec/src/plugin.json | 5 +++- plugins/hifiKinect/src/plugin.json | 5 +++- plugins/hifiLeapMotion/src/plugin.json | 5 +++- plugins/hifiNeuron/src/plugin.json | 5 +++- plugins/hifiSdl2/src/plugin.json | 5 +++- plugins/hifiSixense/src/plugin.json | 5 +++- plugins/hifiSpacemouse/src/plugin.json | 5 +++- plugins/oculus/src/oculus.json | 5 +++- plugins/oculusLegacy/src/oculus.json | 5 +++- plugins/openvr/src/plugin.json | 5 +++- plugins/pcmCodec/src/plugin.json | 5 +++- plugins/steamClient/src/plugin.json | 5 +++- 14 files changed, 73 insertions(+), 13 deletions(-) diff --git a/libraries/plugins/src/plugins/PluginManager.cpp b/libraries/plugins/src/plugins/PluginManager.cpp index 32d8486e7a..ece8ccd528 100644 --- a/libraries/plugins/src/plugins/PluginManager.cpp +++ b/libraries/plugins/src/plugins/PluginManager.cpp @@ -71,6 +71,24 @@ QString getPluginIIDFromMetaData(QJsonObject object) { return object[IID_KEY].toString(); } +int getPluginInterfaceVersionFromMetaData(QJsonObject object) { + static const char* METADATA_KEY = "MetaData"; + static const char* NAME_KEY = "version"; + + if (!object.contains(METADATA_KEY) || !object[METADATA_KEY].isObject()) { + return 0; + } + + auto metaDataObject = object[METADATA_KEY].toObject(); + + if (!metaDataObject.contains(NAME_KEY) || !metaDataObject[NAME_KEY].isDouble()) { + return 0; + } + + return (int)(metaDataObject[NAME_KEY].toDouble()); +} + + QStringList preferredDisplayPlugins; QStringList disabledDisplays; QStringList disabledInputs; @@ -122,7 +140,11 @@ const LoaderList& getLoadedPlugins() { continue; } - if (loader->load()) { + if (getPluginInterfaceVersionFromMetaData(loader->metaData()) != HIFI_PLUGIN_INTERFACE_VERSION) { + qCDebug(plugins) << "Plugin" << qPrintable(plugin) << "interface version doesn't match, not loading:" + << getPluginInterfaceVersionFromMetaData(loader->metaData()) + << "doesn't match" << HIFI_PLUGIN_INTERFACE_VERSION; + } else if (loader->load()) { qCDebug(plugins) << "Plugin" << qPrintable(plugin) << "loaded successfully"; loadedPlugins.push_back(loader); } else { diff --git a/libraries/plugins/src/plugins/PluginManager.h b/libraries/plugins/src/plugins/PluginManager.h index c7489fd7e4..a3305d8ee7 100644 --- a/libraries/plugins/src/plugins/PluginManager.h +++ b/libraries/plugins/src/plugins/PluginManager.h @@ -61,3 +61,5 @@ private: DisplayPluginList _displayPlugins; InputPluginList _inputPlugins; }; + +static const int HIFI_PLUGIN_INTERFACE_VERSION = 1; diff --git a/plugins/hifiCodec/src/plugin.json b/plugins/hifiCodec/src/plugin.json index df26a67ea8..27391a484d 100644 --- a/plugins/hifiCodec/src/plugin.json +++ b/plugins/hifiCodec/src/plugin.json @@ -1 +1,4 @@ -{"name":"HiFi 4:1 Audio Codec"} +{ + "name":"HiFi 4:1 Audio Codec", + "version":1 +} diff --git a/plugins/hifiKinect/src/plugin.json b/plugins/hifiKinect/src/plugin.json index daa3a668dd..b401bb8c83 100644 --- a/plugins/hifiKinect/src/plugin.json +++ b/plugins/hifiKinect/src/plugin.json @@ -1 +1,4 @@ -{"name":"Kinect"} +{ + "name":"Kinect", + "version":1 +} diff --git a/plugins/hifiLeapMotion/src/plugin.json b/plugins/hifiLeapMotion/src/plugin.json index 2e867d96e4..92e410ef11 100644 --- a/plugins/hifiLeapMotion/src/plugin.json +++ b/plugins/hifiLeapMotion/src/plugin.json @@ -1 +1,4 @@ -{"name":"Leap Motion"} +{ + "name":"Leap Motion", + "version":1 +} diff --git a/plugins/hifiNeuron/src/plugin.json b/plugins/hifiNeuron/src/plugin.json index d153b5cebd..7059248934 100644 --- a/plugins/hifiNeuron/src/plugin.json +++ b/plugins/hifiNeuron/src/plugin.json @@ -1 +1,4 @@ -{"name":"Neuron"} +{ + "name":"Neuron", + "version":1 +} diff --git a/plugins/hifiSdl2/src/plugin.json b/plugins/hifiSdl2/src/plugin.json index a65846ecab..e1963f9995 100644 --- a/plugins/hifiSdl2/src/plugin.json +++ b/plugins/hifiSdl2/src/plugin.json @@ -1 +1,4 @@ -{"name":"SDL2"} +{ + "name":"SDL2", + "version":1 +} diff --git a/plugins/hifiSixense/src/plugin.json b/plugins/hifiSixense/src/plugin.json index 9e6e15a354..a56a1ba384 100644 --- a/plugins/hifiSixense/src/plugin.json +++ b/plugins/hifiSixense/src/plugin.json @@ -1 +1,4 @@ -{"name":"Sixense"} +{ + "name":"Sixense", + "version":1 +} diff --git a/plugins/hifiSpacemouse/src/plugin.json b/plugins/hifiSpacemouse/src/plugin.json index 294f436039..6eac13ac66 100644 --- a/plugins/hifiSpacemouse/src/plugin.json +++ b/plugins/hifiSpacemouse/src/plugin.json @@ -1 +1,4 @@ -{"name":"Spacemouse"} +{ + "name":"Spacemouse", + "version":1 +} diff --git a/plugins/oculus/src/oculus.json b/plugins/oculus/src/oculus.json index 86546c8dd5..0043a8b50f 100644 --- a/plugins/oculus/src/oculus.json +++ b/plugins/oculus/src/oculus.json @@ -1 +1,4 @@ -{"name":"Oculus Rift"} +{ + "name":"Oculus Rift", + "version":1 +} diff --git a/plugins/oculusLegacy/src/oculus.json b/plugins/oculusLegacy/src/oculus.json index 86546c8dd5..0043a8b50f 100644 --- a/plugins/oculusLegacy/src/oculus.json +++ b/plugins/oculusLegacy/src/oculus.json @@ -1 +1,4 @@ -{"name":"Oculus Rift"} +{ + "name":"Oculus Rift", + "version":1 +} diff --git a/plugins/openvr/src/plugin.json b/plugins/openvr/src/plugin.json index d68c8e68d3..763414cd8b 100644 --- a/plugins/openvr/src/plugin.json +++ b/plugins/openvr/src/plugin.json @@ -1 +1,4 @@ -{"name":"OpenVR (Vive)"} +{ + "name":"OpenVR (Vive)", + "version":1 +} diff --git a/plugins/pcmCodec/src/plugin.json b/plugins/pcmCodec/src/plugin.json index 2d86251845..525124592b 100644 --- a/plugins/pcmCodec/src/plugin.json +++ b/plugins/pcmCodec/src/plugin.json @@ -1 +1,4 @@ -{"name":"PCM Codec"} +{ + "name":"PCM Codec", + "version":1 +} diff --git a/plugins/steamClient/src/plugin.json b/plugins/steamClient/src/plugin.json index dfe37917d2..ce4647188f 100644 --- a/plugins/steamClient/src/plugin.json +++ b/plugins/steamClient/src/plugin.json @@ -1 +1,4 @@ -{"name":"Steam Client"} +{ + "name":"Steam Client", + "version":1 +}