From 6a4663824e573777c512e0ca21a5c5f61865b83c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 18 Sep 2003 18:23:53 +0000 Subject: added initial support for building our 4 adventure engines as loadable modules; right now only work on OS X; once we add more build rules, other systems with dlopen() should work, too (e.g. Linux); Windows support may come later. This is still very much WIP svn-id: r10304 --- base/plugins.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'base/plugins.h') diff --git a/base/plugins.h b/base/plugins.h index 8257bf1a53..d79ff0c5d9 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -37,11 +37,13 @@ struct TargetSettings; */ class Plugin { public: - virtual void loadPlugin() {} + virtual ~Plugin() {} + + virtual bool loadPlugin() { return true; } virtual void unloadPlugin() {} virtual const char *getName() const = 0; - virtual int getVersion() const = 0; + virtual int getVersion() const { return 0; } // TODO! virtual int countTargets() const; virtual const TargetSettings *getTargets() const = 0; @@ -51,6 +53,27 @@ public: }; +/** + * The REGISTER_PLUGIN is a convenience macro meant to ease writing + * the plugin interface for our modules. In particular, using it + * makes it possible to compile the very same code in a module + * both as a static and a dynamic plugin. + * + * @todo add some means to query the plugin API version etc. + * @todo on Windows, we might need __declspec(dllexport) ? + */ +#ifndef DYNAMIC_MODULES +#define REGISTER_PLUGIN(name,targetListFactory,engineFactory) +#else +#define REGISTER_PLUGIN(name,targetListFactory,engineFactory) \ + extern "C" { \ + const char *PLUGIN_name() { return name; } \ + const TargetSettings *PLUGIN_getTargetList() { return targetListFactory(); } \ + Engine *PLUGIN_createEngine(GameDetector *detector, OSystem *syst) { return engineFactory(detector, syst); } \ + } +#endif + + /** List of plugins. */ typedef ScummVM::List PluginList; @@ -65,6 +88,8 @@ class PluginManager { protected: PluginList _plugins; + bool tryLoadPlugin(Plugin *plugin); + public: PluginManager(); ~PluginManager(); -- cgit v1.2.3