Skip to content

Commit

Permalink
Implemented plugin versioning
Browse files Browse the repository at this point in the history
svn-id: r30826
  • Loading branch information
jvprat committed Feb 8, 2008
1 parent c103290 commit 00987db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
22 changes: 22 additions & 0 deletions backends/plugins/dynamic-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class DynamicPlugin : public Plugin {

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) {
Expand All @@ -51,6 +62,17 @@ class DynamicPlugin : public Plugin {
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) {
Expand Down
4 changes: 4 additions & 0 deletions base/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 11 additions & 2 deletions base/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ class PluginObject {

#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;
Expand Down Expand Up @@ -83,8 +92,6 @@ class Plugin {
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;
Expand Down Expand Up @@ -112,7 +119,9 @@ class Plugin {
#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(); \
} \
Expand Down
2 changes: 2 additions & 0 deletions plugin.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
_PLUGIN_getVersion
_PLUGIN_getType
_PLUGIN_getTypeVersion
_PLUGIN_getObject

0 comments on commit 00987db

Please sign in to comment.