2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
2006-02-11 09:53:21 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-09-08 15:38:34 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-17 22:41:01 +00:00
|
|
|
#include "base/plugins.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-03-09 12:52:10 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
const char *Plugin::getName() const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return _pluginObject->getName();
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
const char *Plugin::getCopyright() const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->getCopyright();
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2003-09-08 17:13:40 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
PluginError Plugin::createInstance(OSystem *syst, Engine **engine) const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->createInstance(syst, engine);
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2006-10-07 00:22:48 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
GameList Plugin::getSupportedGames() const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->getSupportedGames();
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2008-02-03 18:56:47 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
GameDescriptor Plugin::findGame(const char *gameid) const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->findGame(gameid);
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2003-09-08 17:13:40 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
GameList Plugin::detectGames(const FSList &fslist) const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->detectGames(fslist);
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
SaveStateList Plugin::listSaves(const char *target) const {
|
2008-02-04 18:38:22 +00:00
|
|
|
return ((MetaEngine*)_pluginObject)->listSaves(target);
|
2008-02-04 13:14:52 +00:00
|
|
|
}
|
2006-02-18 11:15:37 +00:00
|
|
|
|
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
#ifndef DYNAMIC_MODULES
|
|
|
|
class StaticPlugin : public Plugin {
|
|
|
|
public:
|
2008-02-04 18:38:22 +00:00
|
|
|
StaticPlugin(PluginObject *pluginobject) {
|
|
|
|
assert(pluginobject);
|
|
|
|
_pluginObject = pluginobject;
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
2008-02-04 10:15:21 +00:00
|
|
|
|
2008-02-04 13:14:52 +00:00
|
|
|
~StaticPlugin() {
|
2008-02-04 18:38:22 +00:00
|
|
|
delete _pluginObject;
|
2008-02-04 10:15:21 +00:00
|
|
|
}
|
2008-02-04 13:14:52 +00:00
|
|
|
|
|
|
|
virtual bool loadPlugin() { return true; }
|
|
|
|
virtual void unloadPlugin() {}
|
2003-09-08 17:13:40 +00:00
|
|
|
};
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
class StaticPluginProvider : public PluginProvider {
|
2003-09-18 18:23:53 +00:00
|
|
|
public:
|
2006-10-07 00:22:48 +00:00
|
|
|
StaticPluginProvider() {
|
2003-09-18 18:23:53 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
~StaticPluginProvider() {
|
2006-02-18 11:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
virtual PluginList getPlugins() {
|
|
|
|
PluginList pl;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
#define LINK_PLUGIN(ID) \
|
2008-02-04 18:38:22 +00:00
|
|
|
extern PluginObject *g_##ID##_getObject(); \
|
|
|
|
pl.push_back(new StaticPlugin(g_##ID##_getObject()));
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
// "Loader" for the static plugins.
|
|
|
|
// Iterate over all registered (static) plugins and load them.
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
#ifndef DISABLE_SCUMM
|
|
|
|
LINK_PLUGIN(SCUMM)
|
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_AGI
|
|
|
|
LINK_PLUGIN(AGI)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_AGOS
|
|
|
|
LINK_PLUGIN(AGOS)
|
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_CINE
|
|
|
|
LINK_PLUGIN(CINE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_CRUISE
|
|
|
|
LINK_PLUGIN(CRUISE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_DRASCULA
|
|
|
|
LINK_PLUGIN(DRASCULA)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_GOB
|
|
|
|
LINK_PLUGIN(GOB)
|
|
|
|
#endif
|
2007-10-29 23:35:50 +00:00
|
|
|
#ifndef DISABLE_IGOR
|
|
|
|
LINK_PLUGIN(IGOR)
|
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_KYRA
|
|
|
|
LINK_PLUGIN(KYRA)
|
|
|
|
#endif
|
2006-10-07 00:22:48 +00:00
|
|
|
#ifndef DISABLE_LURE
|
|
|
|
LINK_PLUGIN(LURE)
|
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_PARALLACTION
|
|
|
|
LINK_PLUGIN(PARALLACTION)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_QUEEN
|
|
|
|
LINK_PLUGIN(QUEEN)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_SAGA
|
|
|
|
LINK_PLUGIN(SAGA)
|
2006-11-03 21:23:07 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_SKY
|
|
|
|
LINK_PLUGIN(SKY)
|
2007-01-14 21:29:12 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_SWORD1
|
|
|
|
LINK_PLUGIN(SWORD1)
|
2007-04-27 14:50:27 +00:00
|
|
|
#endif
|
2007-09-24 17:44:47 +00:00
|
|
|
#ifndef DISABLE_SWORD2
|
|
|
|
LINK_PLUGIN(SWORD2)
|
|
|
|
#endif
|
|
|
|
#ifndef DISABLE_TOUCHE
|
|
|
|
LINK_PLUGIN(TOUCHE)
|
2007-07-17 21:35:01 +00:00
|
|
|
#endif
|
2006-10-07 01:05:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
return pl;
|
2003-10-17 23:16:53 +00:00
|
|
|
}
|
2003-09-18 18:23:53 +00:00
|
|
|
};
|
|
|
|
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2005-06-05 12:55:33 +00:00
|
|
|
#endif
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
#pragma mark -
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2007-05-27 11:40:03 +00:00
|
|
|
DECLARE_SINGLETON(PluginManager);
|
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
PluginManager::PluginManager() {
|
2006-10-07 01:05:12 +00:00
|
|
|
#ifndef DYNAMIC_MODULES
|
|
|
|
// Add the static plugin provider if we do not build with dynamic
|
|
|
|
// plugins.
|
2006-10-07 00:22:48 +00:00
|
|
|
addPluginProvider(new StaticPluginProvider());
|
|
|
|
#endif
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager::~PluginManager() {
|
|
|
|
// Explicitly unload all loaded plugins
|
|
|
|
unloadPlugins();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 01:05:12 +00:00
|
|
|
// Delete the plugin providers
|
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
|
|
|
delete *pp;
|
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2006-11-03 21:23:07 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
void PluginManager::addPluginProvider(PluginProvider *pp) {
|
|
|
|
_providers.push_back(pp);
|
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
|
|
|
|
void PluginManager::loadPlugins() {
|
2006-10-07 00:22:48 +00:00
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
|
|
|
PluginList pl((**pp).getPlugins());
|
|
|
|
for (PluginList::iterator plugin = pl.begin(); plugin != pl.end(); ++plugin) {
|
|
|
|
tryLoadPlugin(*plugin);
|
2005-03-25 17:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-17 23:16:53 +00:00
|
|
|
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::unloadPlugins() {
|
2004-08-29 19:08:08 +00:00
|
|
|
unloadPluginsExcept(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
|
|
|
|
Plugin *found = NULL;
|
2006-10-07 01:56:31 +00:00
|
|
|
for (PluginList::iterator p = _plugins.begin(); p != _plugins.end(); ++p) {
|
2006-10-07 01:05:12 +00:00
|
|
|
if (*p == plugin) {
|
|
|
|
found = *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
} else {
|
2006-10-07 01:05:12 +00:00
|
|
|
(**p).unloadPlugin();
|
|
|
|
delete *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
_plugins.clear();
|
2004-08-29 19:08:08 +00:00
|
|
|
if (found != NULL) {
|
|
|
|
_plugins.push_back(found);
|
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2003-09-18 18:23:53 +00:00
|
|
|
|
|
|
|
bool PluginManager::tryLoadPlugin(Plugin *plugin) {
|
|
|
|
assert(plugin);
|
|
|
|
// Try to load the plugin
|
|
|
|
if (plugin->loadPlugin()) {
|
2003-11-07 02:31:44 +00:00
|
|
|
// If successful, add it to the list of known plugins and return.
|
2003-09-18 18:23:53 +00:00
|
|
|
_plugins.push_back(plugin);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
// TODO/FIXME: We should perform some additional checks here:
|
|
|
|
// * Check for some kind of "API version" (possibly derived from the
|
|
|
|
// SVN tree revision?)
|
|
|
|
// * If two plugins provide the same engine, we should only load one.
|
|
|
|
// To detect this situation, we could just compare the plugin name.
|
|
|
|
// To handle it, simply prefer modules loaded earlier to those coming.
|
|
|
|
// Or vice versa... to be determined... :-)
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-09-18 18:23:53 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// Failed to load the plugin
|
|
|
|
delete plugin;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-12-21 15:29:52 +00:00
|
|
|
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList PluginManager::detectGames(const FSList &fslist) const {
|
|
|
|
GameList candidates;
|
2003-12-21 15:29:52 +00:00
|
|
|
|
|
|
|
// Iterate over all known games and for each check if it might be
|
|
|
|
// the game in the presented directory.
|
2004-02-05 00:19:57 +00:00
|
|
|
PluginList::const_iterator iter;
|
2003-12-21 15:29:52 +00:00
|
|
|
for (iter = _plugins.begin(); iter != _plugins.end(); ++iter) {
|
|
|
|
candidates.push_back((*iter)->detectGames(fslist));
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-21 15:29:52 +00:00
|
|
|
return candidates;
|
|
|
|
}
|