ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

plugins.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BASE_PLUGINS_H
00024 #define BASE_PLUGINS_H
00025 
00026 #include "common/array.h"
00027 #include "common/fs.h"
00028 #include "common/str.h"
00029 //#include "backends/plugins/elf/version.h" // ResidualVM specific
00030 
00031 #define INCLUDED_FROM_BASE_PLUGINS_H
00032 #include "base/internal_plugins.h"
00033 #undef INCLUDED_FROM_BASE_PLUGINS_H
00034 
00035 
00057 // Plugin versioning
00058 
00060 #define PLUGIN_VERSION 1
00061 
00062 enum PluginType {
00063     PLUGIN_TYPE_ENGINE = 0,
00064     PLUGIN_TYPE_MUSIC,
00065     /* PLUGIN_TYPE_SCALER, */   // TODO: Add graphics scaler plugins
00066 
00067     PLUGIN_TYPE_MAX
00068 };
00069 
00070 // TODO: Make the engine API version depend on ScummVM's version
00071 // because of the backlinking (posibly from the checkout revision)
00072 #define PLUGIN_TYPE_ENGINE_VERSION 1
00073 #define PLUGIN_TYPE_MUSIC_VERSION 1
00074 
00075 extern int pluginTypeVersions[PLUGIN_TYPE_MAX];
00076 
00077 
00078 // Plugin linking
00079 
00080 // see comments in backends/plugins/elf/elf-provider.cpp
00081 #if defined(USE_ELF_LOADER) && defined(ELF_LOADER_CXA_ATEXIT)
00082 #define PLUGIN_DYNAMIC_DSO_HANDLE \
00083     uint32 __dso_handle __attribute__((visibility("hidden"))) = 0;
00084 #else
00085 #define PLUGIN_DYNAMIC_DSO_HANDLE
00086 #endif
00087 
00088 #ifdef USE_ELF_LOADER
00089 #define PLUGIN_DYNAMIC_BUILD_DATE \
00090     PLUGIN_EXPORT const char *PLUGIN_getBuildDate() { return gScummVMPluginBuildDate; }
00091 #else
00092 #define PLUGIN_DYNAMIC_BUILD_DATE
00093 #endif
00094 
00104 #define REGISTER_PLUGIN_STATIC(ID,TYPE,PLUGINCLASS) \
00105     PluginType g_##ID##_type = TYPE; \
00106     PluginObject *g_##ID##_getObject() { \
00107         return new PLUGINCLASS(); \
00108     } \
00109     void dummyFuncToAllowTrailingSemicolon()
00110 
00111 #ifdef DYNAMIC_MODULES
00112 
00122 #define REGISTER_PLUGIN_DYNAMIC(ID,TYPE,PLUGINCLASS) \
00123     extern "C" { \
00124         PLUGIN_DYNAMIC_DSO_HANDLE \
00125         PLUGIN_DYNAMIC_BUILD_DATE \
00126         PLUGIN_EXPORT int32 PLUGIN_getVersion() { return PLUGIN_VERSION; } \
00127         PLUGIN_EXPORT int32 PLUGIN_getType() { return TYPE; } \
00128         PLUGIN_EXPORT int32 PLUGIN_getTypeVersion() { return TYPE##_VERSION; } \
00129         PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
00130             return new PLUGINCLASS(); \
00131         } \
00132     } \
00133     void dummyFuncToAllowTrailingSemicolon()
00134 
00135 #endif // DYNAMIC_MODULES
00136 
00137 
00138 // Abstract plugins
00139 
00147 class PluginObject {
00148 public:
00149     virtual ~PluginObject() {}
00150 
00152     virtual const char *getName() const = 0;
00153 };
00154 
00161 class Plugin {
00162 protected:
00163     PluginObject *_pluginObject;
00164     PluginType _type;
00165 
00166 public:
00167     Plugin() : _pluginObject(0), _type(PLUGIN_TYPE_MAX) {}
00168     virtual ~Plugin() {
00169         //if (isLoaded())
00170             //unloadPlugin();
00171     }
00172 
00173 //  virtual bool isLoaded() const = 0; // TODO
00174     virtual bool loadPlugin() = 0;     // TODO: Rename to load() ?
00175     virtual void unloadPlugin() = 0;   // TODO: Rename to unload() ?
00176 
00181     PluginType getType() const;
00182     const char *getName() const;
00183 
00184     template <class T>
00185     T &get() const {
00186         T *pluginObject = dynamic_cast<T *>(_pluginObject);
00187         if (!pluginObject) {
00188             error("Invalid cast of plugin %s", getName());
00189         }
00190         return *pluginObject;
00191     }
00192 
00198     virtual const char *getFileName() const { return 0; }
00199 };
00200 
00202 typedef Common::Array<Plugin *> PluginList;
00203 
00210 class PluginProvider {
00211 public:
00212     virtual ~PluginProvider() {}
00213 
00222     virtual PluginList getPlugins() = 0;
00223 
00227     virtual bool isFilePluginProvider() { return false; }
00228 };
00229 
00230 #ifdef DYNAMIC_MODULES
00231 
00237 class FilePluginProvider : public PluginProvider {
00238 public:
00248     virtual PluginList getPlugins();
00249 
00253     bool isFilePluginProvider() { return true; }
00254 
00255 protected:
00264     virtual Plugin *createPlugin(const Common::FSNode &node) const = 0;
00265 
00273     virtual bool isPluginFilename(const Common::FSNode &node) const;
00274 
00282     virtual void addCustomDirectories(Common::FSList &dirs) const;
00283 };
00284 
00285 #endif // DYNAMIC_MODULES
00286 
00287 #define PluginMan PluginManager::instance()
00288 
00293 class PluginManager {
00294 protected:
00295     typedef Common::Array<PluginProvider *> ProviderList;
00296 
00297     PluginList _pluginsInMem[PLUGIN_TYPE_MAX];
00298     ProviderList _providers;
00299 
00300     bool tryLoadPlugin(Plugin *plugin);
00301     void addToPluginsInMemList(Plugin *plugin);
00302 
00303     static PluginManager *_instance;
00304     PluginManager();
00305 
00306 public:
00307     virtual ~PluginManager();
00308 
00309     static void destroy() { delete _instance; _instance = 0; }
00310     static PluginManager &instance();
00311 
00312     void addPluginProvider(PluginProvider *pp);
00313 
00314     // Functions used by the uncached PluginManager
00315     virtual void init() {}
00316     virtual void loadFirstPlugin() {}
00317     virtual bool loadNextPlugin() { return false; }
00318     virtual bool loadPluginFromGameId(const Common::String &gameId) { return false; }
00319     virtual void updateConfigWithFileName(const Common::String &gameId) {}
00320 
00321     // Functions used only by the cached PluginManager
00322     virtual void loadAllPlugins();
00323     virtual void loadAllPluginsOfType(PluginType type);
00324     void unloadAllPlugins();
00325 
00326     void unloadPluginsExcept(PluginType type, const Plugin *plugin, bool deletePlugin = true);
00327 
00328     const PluginList &getPlugins(PluginType t) { return _pluginsInMem[t]; }
00329 };
00330 
00335 class PluginManagerUncached : public PluginManager {
00336 protected:
00337     friend class PluginManager;
00338     PluginList _allEnginePlugins;
00339     PluginList::iterator _currentPlugin;
00340 
00341     PluginManagerUncached() {}
00342     bool loadPluginByFileName(const Common::String &filename);
00343 
00344 public:
00345     virtual void init();
00346     virtual void loadFirstPlugin();
00347     virtual bool loadNextPlugin();
00348     virtual bool loadPluginFromGameId(const Common::String &gameId);
00349     virtual void updateConfigWithFileName(const Common::String &gameId);
00350 
00351     virtual void loadAllPlugins() {}    // we don't allow these
00352     virtual void loadAllPluginsOfType(PluginType type) {}
00353 };
00354 
00355 #endif


Generated on Sat Aug 24 2019 05:00:52 for ResidualVM by doxygen 1.7.1
curved edge   curved edge