diff options
-rw-r--r-- | backends/plugins/dynamic-plugin.h | 16 | ||||
-rw-r--r-- | base/plugins.cpp | 27 | ||||
-rw-r--r-- | base/plugins.h | 32 | ||||
-rw-r--r-- | engines/metaengine.h | 7 | ||||
-rw-r--r-- | plugin.exp | 2 |
5 files changed, 48 insertions, 36 deletions
diff --git a/backends/plugins/dynamic-plugin.h b/backends/plugins/dynamic-plugin.h index 410e21c3a8..67d0b138c6 100644 --- a/backends/plugins/dynamic-plugin.h +++ b/backends/plugins/dynamic-plugin.h @@ -27,27 +27,27 @@ #define BACKENDS_PLUGINS_DYNAMICPLUGIN_H #include "base/plugins.h" -#include "engines/metaengine.h" class DynamicPlugin : public Plugin { protected: typedef void (*VoidFunc)(); - typedef MetaEngine *(*MetaAllocFunc)(); + typedef PluginObject *(*GetObjectFunc)(); virtual VoidFunc findSymbol(const char *symbol) = 0; public: virtual bool loadPlugin() { - // Query the plugin's name - MetaAllocFunc metaAlloc = (MetaAllocFunc)findSymbol("PLUGIN_MetaEngine_alloc"); - if (!metaAlloc) { + // Get the plugin's instantiator object + GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject"); + if (!getObject) { unloadPlugin(); return false; } - _metaengine = metaAlloc(); - if (!_metaengine) { + // Get the plugin object + _pluginObject = getObject(); + if (!_pluginObject) { unloadPlugin(); return false; } @@ -56,7 +56,7 @@ public: } virtual void unloadPlugin() { - delete _metaengine; + delete _pluginObject; } }; diff --git a/base/plugins.cpp b/base/plugins.cpp index 4364cd0215..3a53142438 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -25,48 +25,47 @@ #include "base/plugins.h" #include "common/util.h" -#include "engines/metaengine.h" const char *Plugin::getName() const { - return _metaengine->getName(); + return _pluginObject->getName(); } const char *Plugin::getCopyright() const { - return _metaengine->getCopyright(); + return ((MetaEngine*)_pluginObject)->getCopyright(); } PluginError Plugin::createInstance(OSystem *syst, Engine **engine) const { - return _metaengine->createInstance(syst, engine); + return ((MetaEngine*)_pluginObject)->createInstance(syst, engine); } GameList Plugin::getSupportedGames() const { - return _metaengine->getSupportedGames(); + return ((MetaEngine*)_pluginObject)->getSupportedGames(); } GameDescriptor Plugin::findGame(const char *gameid) const { - return _metaengine->findGame(gameid); + return ((MetaEngine*)_pluginObject)->findGame(gameid); } GameList Plugin::detectGames(const FSList &fslist) const { - return _metaengine->detectGames(fslist); + return ((MetaEngine*)_pluginObject)->detectGames(fslist); } SaveStateList Plugin::listSaves(const char *target) const { - return _metaengine->listSaves(target); + return ((MetaEngine*)_pluginObject)->listSaves(target); } #ifndef DYNAMIC_MODULES class StaticPlugin : public Plugin { public: - StaticPlugin(MetaEngine *metaengine) { - assert(metaengine); - _metaengine = metaengine; + StaticPlugin(PluginObject *pluginobject) { + assert(pluginobject); + _pluginObject = pluginobject; } ~StaticPlugin() { - delete _metaengine; + delete _pluginObject; } virtual bool loadPlugin() { return true; } @@ -85,8 +84,8 @@ public: PluginList pl; #define LINK_PLUGIN(ID) \ - extern MetaEngine *g_##ID##_MetaEngine_alloc(); \ - pl.push_back(new StaticPlugin(g_##ID##_MetaEngine_alloc())); + extern PluginObject *g_##ID##_getObject(); \ + pl.push_back(new StaticPlugin(g_##ID##_getObject())); // "Loader" for the static plugins. // Iterate over all registered (static) plugins and load them. diff --git a/base/plugins.h b/base/plugins.h index bc65a13644..e91ed80aa4 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -33,9 +33,23 @@ #include "common/util.h" #include "base/game.h" +/** + * Abstract base class for the plugin objects which handle plugins + * instantiation. Subclasses for this may be used for engine plugins + * and other types of plugins. + */ +class PluginObject { +public: + virtual ~PluginObject() {} + + /** Returns the name of the plugin. */ + virtual const char *getName() const = 0; +}; + +#include "engines/metaengine.h" + class Engine; class FSList; -class MetaEngine; class OSystem; /** @@ -45,10 +59,10 @@ class OSystem; */ class Plugin { protected: - MetaEngine *_metaengine; + PluginObject *_pluginObject; public: - Plugin() : _metaengine(0) {} + Plugin() : _pluginObject(0) {} virtual ~Plugin() { //if (isLoaded()) //unloadPlugin(); @@ -81,16 +95,16 @@ public: */ #ifndef DYNAMIC_MODULES -#define REGISTER_PLUGIN(ID,METAENGINE) \ - MetaEngine *g_##ID##_MetaEngine_alloc() { \ - return new METAENGINE(); \ +#define REGISTER_PLUGIN(ID,PLUGINCLASS) \ + PluginObject *g_##ID##_getObject() { \ + return new PLUGINCLASS(); \ } \ void dummyFuncToAllowTrailingSemicolon() #else -#define REGISTER_PLUGIN(ID,METAENGINE) \ +#define REGISTER_PLUGIN(ID,PLUGINCLASS) \ extern "C" { \ - PLUGIN_EXPORT MetaEngine *PLUGIN_MetaEngine_alloc() { \ - return new METAENGINE(); \ + PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \ + return new PLUGINCLASS(); \ } \ } \ void dummyFuncToAllowTrailingSemicolon() diff --git a/engines/metaengine.h b/engines/metaengine.h index df124c57c5..c07a4f6e88 100644 --- a/engines/metaengine.h +++ b/engines/metaengine.h @@ -28,8 +28,10 @@ #include "common/scummsys.h" #include "common/str.h" #include "common/error.h" +#include "common/fs.h" #include "base/game.h" +#include "base/plugins.h" class Engine; class OSystem; @@ -42,13 +44,10 @@ class OSystem; * This is then in turn used by the frontend code to detect games, * and instantiate actual Engine objects. */ -class MetaEngine { +class MetaEngine : public PluginObject { public: virtual ~MetaEngine() {} - /** Returns the name of the engine. */ - virtual const char *getName() const = 0; - /** Returns some copyright information about the engine. */ virtual const char *getCopyright() const = 0; diff --git a/plugin.exp b/plugin.exp index 48a06339a6..253a22c331 100644 --- a/plugin.exp +++ b/plugin.exp @@ -1 +1 @@ -_PLUGIN_MetaEngine_alloc +_PLUGIN_getObject |