From 2c9968fe80c4ba78f895c9bac757dd6b1604ccce Mon Sep 17 00:00:00 2001 From: Jordi Vilalta Prat Date: Mon, 12 May 2008 00:26:29 +0000 Subject: - Added an engine plugin manager and moved engine specific functionality into it - base/plugins.* reorganization svn-id: r32045 --- base/plugins.h | 124 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 52 deletions(-) (limited to 'base/plugins.h') diff --git a/base/plugins.h b/base/plugins.h index ec947ee6ad..14ce2a3aa4 100644 --- a/base/plugins.h +++ b/base/plugins.h @@ -26,27 +26,12 @@ #ifndef BASE_PLUGINS_H #define BASE_PLUGINS_H -#include "common/array.h" #include "common/error.h" #include "common/list.h" #include "common/singleton.h" -#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" +// Plugin versioning // Global Plugin API version #define PLUGIN_VERSION 1 @@ -63,42 +48,8 @@ enum PluginType { extern int pluginTypeVersions[PLUGIN_TYPE_MAX]; -class Engine; -class FSList; -class OSystem; - -/** - * Abstract base class for the plugin system. - * Subclasses for this can be used to wrap both static and dynamic - * plugins. - */ -class Plugin { -protected: - PluginObject *_pluginObject; - PluginType _type; - -public: - Plugin() : _pluginObject(0) {} - virtual ~Plugin() { - //if (isLoaded()) - //unloadPlugin(); - } - -// virtual bool isLoaded() const = 0; // TODO - virtual bool loadPlugin() = 0; // TODO: Rename to load() ? - virtual void unloadPlugin() = 0; // TODO: Rename to unload() ? - - PluginType getType() const; - const char *getName() const; - const char *getCopyright() const; - - PluginError createInstance(OSystem *syst, Engine **engine) const; - GameList getSupportedGames() const; - GameDescriptor findGame(const char *gameid) const; - GameList detectGames(const FSList &fslist) const; - SaveStateList listSaves(const char *target) const; -}; +// Plugin linking #define STATIC_PLUGIN 1 #define DYNAMIC_PLUGIN 2 @@ -147,10 +98,49 @@ public: #endif // DYNAMIC_MODULES +// Abstract plugins + +/** + * 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; +}; + +/** + * Abstract base class for the plugin system. + * Subclasses for this can be used to wrap both static and dynamic + * plugins. + */ +class Plugin { +protected: + PluginObject *_pluginObject; + PluginType _type; + +public: + Plugin() : _pluginObject(0) {} + virtual ~Plugin() { + //if (isLoaded()) + //unloadPlugin(); + } + +// virtual bool isLoaded() const = 0; // TODO + virtual bool loadPlugin() = 0; // TODO: Rename to load() ? + virtual void unloadPlugin() = 0; // TODO: Rename to unload() ? + + PluginType getType() const; + const char *getName() const; +}; + /** List of plugins. */ typedef Common::Array PluginList; - class PluginProvider { public: virtual ~PluginProvider() {} @@ -202,8 +192,38 @@ public: void unloadPluginsExcept(const Plugin *plugin); const PluginList &getPlugins() { return _plugins; } +}; + +// Engine plugins + +class Engine; +class FSList; +class OSystem; + +class EnginePlugin : public Plugin { +public: + const char *getCopyright() const; + PluginError createInstance(OSystem *syst, Engine **engine) const; + GameList getSupportedGames() const; + GameDescriptor findGame(const char *gameid) const; GameList detectGames(const FSList &fslist) const; + SaveStateList listSaves(const char *target) const; }; +typedef Common::Array EnginePluginList; + +class EngineManager : public Common::Singleton { +private: + friend class Common::Singleton; + +public: + GameDescriptor findGame(const Common::String &gameName, const EnginePlugin **plugin = NULL) const; + GameList detectGames(const FSList &fslist) const; + const EnginePluginList &getPlugins() const; +}; + +/** Shortcut for accessing the engine manager. */ +#define EngineMan EngineManager::instance() + #endif -- cgit v1.2.3