diff options
author | Jordi Vilalta Prat | 2008-02-08 01:02:25 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2008-02-08 01:02:25 +0000 |
commit | 00987db3a97f37439cfc6e70991a08fde424d2b3 (patch) | |
tree | 5b537564da7280d60668bd947e31d7b4c6e1e087 | |
parent | c103290e2b123510e9d9eb4716ae0336a9e61ede (diff) | |
download | scummvm-rg350-00987db3a97f37439cfc6e70991a08fde424d2b3.tar.gz scummvm-rg350-00987db3a97f37439cfc6e70991a08fde424d2b3.tar.bz2 scummvm-rg350-00987db3a97f37439cfc6e70991a08fde424d2b3.zip |
Implemented plugin versioning
svn-id: r30826
-rw-r--r-- | backends/plugins/dynamic-plugin.h | 22 | ||||
-rw-r--r-- | base/plugins.cpp | 4 | ||||
-rw-r--r-- | base/plugins.h | 13 | ||||
-rw-r--r-- | plugin.exp | 2 |
4 files changed, 39 insertions, 2 deletions
diff --git a/backends/plugins/dynamic-plugin.h b/backends/plugins/dynamic-plugin.h index 4b46c31ace..3825f28c87 100644 --- a/backends/plugins/dynamic-plugin.h +++ b/backends/plugins/dynamic-plugin.h @@ -39,6 +39,17 @@ protected: public: virtual bool loadPlugin() { + // Validate the plugin API version + IntFunc verFunc = (IntFunc)findSymbol("PLUGIN_getVersion"); + if (!verFunc) { + unloadPlugin(); + return false; + } + if (verFunc() != PLUGIN_VERSION) { + unloadPlugin(); + return false; + } + // Get the type of the plugin IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType"); if (!typeFunc) { @@ -51,6 +62,17 @@ public: return false; } + // Validate the plugin type API version + IntFunc typeVerFunc = (IntFunc)findSymbol("PLUGIN_getTypeVersion"); + if (!typeVerFunc) { + unloadPlugin(); + return false; + } + if (typeVerFunc() != pluginTypeVersions[_type]) { + unloadPlugin(); + return false; + } + // Get the plugin's instantiator object GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject"); if (!getObject) { diff --git a/base/plugins.cpp b/base/plugins.cpp index bb4ef309ed..e7b1faff94 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -26,6 +26,10 @@ #include "base/plugins.h" #include "common/util.h" +int pluginTypeVersions[PLUGIN_TYPE_MAX] = { + PLUGIN_TYPE_ENGINE_VERSION, +}; + PluginType Plugin::getType() const { return _type; } diff --git a/base/plugins.h b/base/plugins.h index f3022e7010..6da8af0ab0 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -48,12 +48,21 @@ public: #include "engines/metaengine.h" +// Global Plugin API version +#define PLUGIN_VERSION 1 + enum PluginType { PLUGIN_TYPE_ENGINE = 0, PLUGIN_TYPE_MAX }; +// TODO: Make the engine API version depend on ScummVM's version +// because of the backlinking +#define PLUGIN_TYPE_ENGINE_VERSION 1 + +extern int pluginTypeVersions[PLUGIN_TYPE_MAX]; + class Engine; class FSList; class OSystem; @@ -83,8 +92,6 @@ public: const char *getName() const; const char *getCopyright() const; -// virtual int getVersion() const { return 0; } // TODO! - PluginError createInstance(OSystem *syst, Engine **engine) const; GameList getSupportedGames() const; GameDescriptor findGame(const char *gameid) const; @@ -112,7 +119,9 @@ public: #else #define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \ extern "C" { \ + PLUGIN_EXPORT int32 PLUGIN_getVersion() { return PLUGIN_VERSION; } \ PLUGIN_EXPORT int32 PLUGIN_getType() { return TYPE; } \ + PLUGIN_EXPORT int32 PLUGIN_getTypeVersion() { return TYPE##_VERSION; } \ PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \ return new PLUGINCLASS(); \ } \ diff --git a/plugin.exp b/plugin.exp index 890e46e473..56cfe9d97d 100644 --- a/plugin.exp +++ b/plugin.exp @@ -1,2 +1,4 @@ +_PLUGIN_getVersion _PLUGIN_getType +_PLUGIN_getTypeVersion _PLUGIN_getObject |