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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-17 22:41:01 +00:00
|
|
|
#include "base/plugins.h"
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2008-05-26 12:43:01 +00:00
|
|
|
#include "common/func.h"
|
2009-01-30 05:25:17 +00:00
|
|
|
#include "common/debug.h"
|
2010-12-29 15:37:57 +00:00
|
|
|
#include "common/config-manager.h"
|
2008-05-26 12:43:01 +00:00
|
|
|
|
2008-05-09 01:58:12 +00:00
|
|
|
#ifdef DYNAMIC_MODULES
|
2008-09-03 11:22:51 +00:00
|
|
|
#include "common/fs.h"
|
2008-05-09 01:58:12 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
// Plugin versioning
|
|
|
|
|
2008-02-08 01:02:25 +00:00
|
|
|
int pluginTypeVersions[PLUGIN_TYPE_MAX] = {
|
|
|
|
PLUGIN_TYPE_ENGINE_VERSION,
|
2008-06-13 14:30:47 +00:00
|
|
|
PLUGIN_TYPE_MUSIC_VERSION,
|
2008-02-08 01:02:25 +00:00
|
|
|
};
|
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
|
|
|
|
// Abstract plugins
|
|
|
|
|
2008-02-08 00:02:23 +00:00
|
|
|
PluginType Plugin::getType() const {
|
|
|
|
return _type;
|
|
|
|
}
|
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
|
|
|
class StaticPlugin : public Plugin {
|
|
|
|
public:
|
2008-02-08 00:02:23 +00:00
|
|
|
StaticPlugin(PluginObject *pluginobject, PluginType type) {
|
2008-02-04 18:38:22 +00:00
|
|
|
assert(pluginobject);
|
2008-02-08 00:02:23 +00:00
|
|
|
assert(type < PLUGIN_TYPE_MAX);
|
2008-02-04 18:38:22 +00:00
|
|
|
_pluginObject = pluginobject;
|
2008-02-08 00:02:23 +00:00
|
|
|
_type = type;
|
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-08 01:45:46 +00:00
|
|
|
extern PluginType g_##ID##_type; \
|
2008-02-04 18:38:22 +00:00
|
|
|
extern PluginObject *g_##ID##_getObject(); \
|
2008-02-08 00:02:23 +00:00
|
|
|
pl.push_back(new StaticPlugin(g_##ID##_getObject(), g_##ID##_type));
|
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
|
|
|
|
2008-05-14 14:56:29 +00:00
|
|
|
// Engine plugins
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SCUMM)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(SCUMM)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(AGI)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(AGI)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(AGOS)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(AGOS)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(CINE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(CINE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2011-07-14 18:08:06 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(COMPOSER)
|
|
|
|
LINK_PLUGIN(COMPOSER)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(CRUISE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(CRUISE)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2009-10-20 10:35:49 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(DRACI)
|
|
|
|
LINK_PLUGIN(DRACI)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(DRASCULA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(DRASCULA)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2011-06-05 09:38:05 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(DREAMWEB)
|
|
|
|
LINK_PLUGIN(DREAMWEB)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(GOB)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(GOB)
|
|
|
|
#endif
|
2008-11-14 21:32:20 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(GROOVIE)
|
|
|
|
LINK_PLUGIN(GROOVIE)
|
|
|
|
#endif
|
2010-08-17 09:28:20 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(HUGO)
|
|
|
|
LINK_PLUGIN(HUGO)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(KYRA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(KYRA)
|
|
|
|
#endif
|
2010-10-18 19:18:06 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(LASTEXPRESS)
|
|
|
|
LINK_PLUGIN(LASTEXPRESS)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(LURE)
|
2006-10-07 00:22:48 +00:00
|
|
|
LINK_PLUGIN(LURE)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(M4)
|
2008-04-20 14:55:41 +00:00
|
|
|
LINK_PLUGIN(M4)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(MADE)
|
2008-04-20 14:55:41 +00:00
|
|
|
LINK_PLUGIN(MADE)
|
2008-12-22 11:22:15 +00:00
|
|
|
#endif
|
2009-12-29 23:20:23 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(MOHAWK)
|
|
|
|
LINK_PLUGIN(MOHAWK)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(PARALLACTION)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(PARALLACTION)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(QUEEN)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(QUEEN)
|
2006-10-07 00:22:48 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SAGA)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SAGA)
|
2006-11-03 21:23:07 +00:00
|
|
|
#endif
|
2009-02-15 06:10:59 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SCI)
|
|
|
|
LINK_PLUGIN(SCI)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SKY)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SKY)
|
2007-01-14 21:29:12 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SWORD1)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SWORD1)
|
2007-04-27 14:50:27 +00:00
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SWORD2)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(SWORD2)
|
|
|
|
#endif
|
2010-10-12 21:12:50 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(SWORD25)
|
|
|
|
LINK_PLUGIN(SWORD25)
|
|
|
|
#endif
|
2009-09-03 21:20:13 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TEENAGENT)
|
|
|
|
LINK_PLUGIN(TEENAGENT)
|
|
|
|
#endif
|
2010-09-12 08:08:37 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TESTBED)
|
|
|
|
LINK_PLUGIN(TESTBED)
|
|
|
|
#endif
|
2008-07-23 09:02:47 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TINSEL)
|
|
|
|
LINK_PLUGIN(TINSEL)
|
|
|
|
#endif
|
2010-10-08 22:30:39 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TOON)
|
|
|
|
LINK_PLUGIN(TOON)
|
|
|
|
#endif
|
2011-02-14 09:37:27 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TSAGE)
|
|
|
|
LINK_PLUGIN(TSAGE)
|
|
|
|
#endif
|
2008-05-06 03:00:26 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TOUCHE)
|
2007-09-24 17:44:47 +00:00
|
|
|
LINK_PLUGIN(TOUCHE)
|
2007-07-17 21:35:01 +00:00
|
|
|
#endif
|
2008-11-10 20:38:54 +00:00
|
|
|
#if PLUGIN_ENABLED_STATIC(TUCKER)
|
|
|
|
LINK_PLUGIN(TUCKER)
|
|
|
|
#endif
|
2006-10-07 01:05:12 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
// Music plugins
|
2008-05-14 14:56:29 +00:00
|
|
|
// TODO: Use defines to disable or enable each MIDI driver as a
|
|
|
|
// static/dynamic plugin, like it's done for the engines
|
2010-06-21 21:36:36 +00:00
|
|
|
LINK_PLUGIN(AUTO)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(NULL)
|
|
|
|
#if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
|
|
|
|
LINK_PLUGIN(WINDOWS)
|
|
|
|
#endif
|
2010-07-20 08:24:34 +00:00
|
|
|
#if defined(USE_ALSA)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(ALSA)
|
|
|
|
#endif
|
2010-07-20 08:25:13 +00:00
|
|
|
#if defined(USE_SEQ_MIDI)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(SEQ)
|
|
|
|
#endif
|
2008-08-27 18:52:21 +00:00
|
|
|
#if defined(__MINT__)
|
|
|
|
LINK_PLUGIN(STMIDI)
|
|
|
|
#endif
|
2008-05-14 14:56:29 +00:00
|
|
|
#if defined(IRIX)
|
|
|
|
LINK_PLUGIN(DMEDIA)
|
|
|
|
#endif
|
|
|
|
#if defined(__amigaos4__)
|
|
|
|
LINK_PLUGIN(CAMD)
|
|
|
|
#endif
|
|
|
|
#if defined(MACOSX)
|
|
|
|
LINK_PLUGIN(COREAUDIO)
|
|
|
|
LINK_PLUGIN(COREMIDI)
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FLUIDSYNTH
|
|
|
|
LINK_PLUGIN(FLUIDSYNTH)
|
|
|
|
#endif
|
|
|
|
#ifdef USE_MT32EMU
|
|
|
|
LINK_PLUGIN(MT32)
|
|
|
|
#endif
|
2011-03-20 20:54:59 +00:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
LINK_PLUGIN(EAS)
|
|
|
|
#endif
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(ADLIB)
|
2010-06-22 15:30:41 +00:00
|
|
|
LINK_PLUGIN(PCSPK)
|
|
|
|
LINK_PLUGIN(PCJR)
|
2010-09-17 20:02:29 +00:00
|
|
|
LINK_PLUGIN(CMS)
|
2010-08-11 19:32:07 +00:00
|
|
|
#ifndef DISABLE_SID
|
|
|
|
LINK_PLUGIN(C64)
|
|
|
|
#endif
|
|
|
|
LINK_PLUGIN(AMIGA)
|
2010-08-11 18:54:56 +00:00
|
|
|
LINK_PLUGIN(APPLEIIGS)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(TOWNS)
|
2011-04-29 20:16:02 +00:00
|
|
|
LINK_PLUGIN(PC98)
|
2010-10-13 00:48:40 +00:00
|
|
|
#if defined(USE_TIMIDITY)
|
2008-05-14 14:56:29 +00:00
|
|
|
LINK_PLUGIN(TIMIDITY)
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef DYNAMIC_MODULES
|
2008-05-02 14:30:06 +00:00
|
|
|
|
|
|
|
PluginList FilePluginProvider::getPlugins() {
|
|
|
|
PluginList pl;
|
|
|
|
|
|
|
|
// Prepare the list of directories to search
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList pluginDirs;
|
2008-05-09 01:58:12 +00:00
|
|
|
|
|
|
|
// Add the default directories
|
2008-10-02 16:58:59 +00:00
|
|
|
pluginDirs.push_back(Common::FSNode("."));
|
|
|
|
pluginDirs.push_back(Common::FSNode("plugins"));
|
2008-05-02 14:30:06 +00:00
|
|
|
|
|
|
|
// Add the provider's custom directories
|
|
|
|
addCustomDirectories(pluginDirs);
|
|
|
|
|
2008-05-09 01:58:12 +00:00
|
|
|
// Add the user specified directory
|
|
|
|
Common::String pluginsPath(ConfMan.get("pluginspath"));
|
2008-05-13 13:24:49 +00:00
|
|
|
if (!pluginsPath.empty())
|
2008-10-02 16:58:59 +00:00
|
|
|
pluginDirs.push_back(Common::FSNode(pluginsPath));
|
2008-05-09 01:58:12 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList::const_iterator dir;
|
2010-01-21 23:05:33 +00:00
|
|
|
for (dir = pluginDirs.begin(); dir != pluginDirs.end(); ++dir) {
|
2008-05-02 14:30:06 +00:00
|
|
|
// Load all plugins.
|
|
|
|
// Scan for all plugins in this directory
|
2008-09-03 11:22:51 +00:00
|
|
|
Common::FSList files;
|
2008-10-02 16:58:59 +00:00
|
|
|
if (!dir->getChildren(files, Common::FSNode::kListFilesOnly)) {
|
2008-05-13 13:24:49 +00:00
|
|
|
debug(1, "Couldn't open plugin directory '%s'", dir->getPath().c_str());
|
2008-05-02 14:30:06 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2008-05-13 13:24:49 +00:00
|
|
|
debug(1, "Reading plugins from plugin directory '%s'", dir->getPath().c_str());
|
2008-05-02 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
for (Common::FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
|
2008-09-30 16:34:38 +00:00
|
|
|
if (isPluginFilename(*i)) {
|
|
|
|
pl.push_back(createPlugin(*i));
|
2008-05-02 14:30:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pl;
|
|
|
|
}
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
bool FilePluginProvider::isPluginFilename(const Common::FSNode &node) const {
|
2008-09-30 16:34:38 +00:00
|
|
|
Common::String filename = node.getName();
|
|
|
|
|
2008-05-02 14:30:06 +00:00
|
|
|
#ifdef PLUGIN_PREFIX
|
2008-05-13 13:24:49 +00:00
|
|
|
// Check the plugin prefix
|
|
|
|
if (!filename.hasPrefix(PLUGIN_PREFIX))
|
|
|
|
return false;
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PLUGIN_SUFFIX
|
2008-05-13 13:24:49 +00:00
|
|
|
// Check the plugin suffix
|
|
|
|
if (!filename.hasSuffix(PLUGIN_SUFFIX))
|
|
|
|
return false;
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
2008-05-13 13:24:49 +00:00
|
|
|
|
|
|
|
return true;
|
2008-05-02 14:30:06 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
void FilePluginProvider::addCustomDirectories(Common::FSList &dirs) const {
|
2008-05-02 14:30:06 +00:00
|
|
|
#ifdef PLUGIN_DIRECTORY
|
2008-10-02 16:58:59 +00:00
|
|
|
dirs.push_back(Common::FSNode(PLUGIN_DIRECTORY));
|
2008-05-02 14:30:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
2003-11-08 22:05:58 +00:00
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#endif // DYNAMIC_MODULES
|
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
|
|
|
|
2010-12-23 13:38:37 +00:00
|
|
|
PluginManager *PluginManager::_instance = NULL;
|
|
|
|
|
|
|
|
PluginManager &PluginManager::instance() {
|
|
|
|
if (_instance)
|
|
|
|
return *_instance;
|
|
|
|
|
2011-06-19 22:59:48 +00:00
|
|
|
#if defined(UNCACHED_PLUGINS) && defined(DYNAMIC_MODULES)
|
2010-12-23 13:38:37 +00:00
|
|
|
_instance = new PluginManagerUncached();
|
|
|
|
#else
|
|
|
|
_instance = new PluginManager();
|
|
|
|
#endif
|
|
|
|
return *_instance;
|
|
|
|
}
|
2007-05-27 11:40:03 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
PluginManager::PluginManager() {
|
2008-05-06 03:00:26 +00:00
|
|
|
// Always add the static plugin provider.
|
2006-10-07 00:22:48 +00:00
|
|
|
addPluginProvider(new StaticPluginProvider());
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginManager::~PluginManager() {
|
|
|
|
// Explicitly unload all loaded plugins
|
2010-12-23 13:38:37 +00:00
|
|
|
unloadAllPlugins();
|
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
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
/**
|
|
|
|
* This should only be called once by main()
|
|
|
|
**/
|
2010-12-23 13:38:37 +00:00
|
|
|
void PluginManagerUncached::init() {
|
|
|
|
unloadAllPlugins();
|
2010-11-05 13:24:57 +00:00
|
|
|
_allEnginePlugins.clear();
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
// Resize our pluginsInMem list to prevent fragmentation
|
|
|
|
_pluginsInMem[PLUGIN_TYPE_ENGINE].resize(2);
|
2011-01-02 10:08:02 +00:00
|
|
|
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false); // empty the engine plugins
|
2010-11-05 13:24:57 +00:00
|
|
|
|
2010-07-30 09:32:45 +00:00
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
2010-11-05 13:24:57 +00:00
|
|
|
PluginList pl((*pp)->getPlugins());
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
for (PluginList::iterator p = pl.begin(); p != pl.end(); ++p) {
|
2010-12-23 07:54:54 +00:00
|
|
|
// This is a 'hack' based on the assumption that we have no sound
|
|
|
|
// file plugins. Currently this is the case. If it changes, we
|
|
|
|
// should find a fast way of detecting whether a plugin is a
|
|
|
|
// music or an engine plugin.
|
|
|
|
if ((*pp)->isFilePluginProvider()) {
|
|
|
|
_allEnginePlugins.push_back(*p);
|
2011-06-19 22:59:48 +00:00
|
|
|
} else if ((*p)->loadPlugin()) { // and this is the proper method
|
2010-11-05 13:24:57 +00:00
|
|
|
if ((*p)->getType() == PLUGIN_TYPE_ENGINE) {
|
2010-12-23 07:54:54 +00:00
|
|
|
(*p)->unloadPlugin();
|
2010-11-05 13:24:57 +00:00
|
|
|
_allEnginePlugins.push_back(*p);
|
|
|
|
} else { // add non-engine plugins to the 'in-memory' list
|
2010-12-23 07:54:54 +00:00
|
|
|
// these won't ever get unloaded
|
2011-06-19 22:59:48 +00:00
|
|
|
addToPluginsInMemList(*p);
|
2010-11-05 13:24:57 +00:00
|
|
|
}
|
2011-06-19 22:59:48 +00:00
|
|
|
}
|
2010-11-05 13:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-12 06:00:19 +00:00
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
/**
|
|
|
|
* Try to load the plugin by searching in the ConfigManager for a matching
|
|
|
|
* gameId under the domain 'plugin_files'.
|
|
|
|
**/
|
|
|
|
bool PluginManagerUncached::loadPluginFromGameId(const Common::String &gameId) {
|
|
|
|
Common::ConfigManager::Domain *domain = ConfMan.getDomain("plugin_files");
|
|
|
|
|
|
|
|
if (domain) {
|
|
|
|
if (domain->contains(gameId)) {
|
|
|
|
Common::String filename = (*domain)[gameId];
|
|
|
|
|
|
|
|
if (loadPluginByFileName(filename)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a plugin with a filename taken from ConfigManager.
|
|
|
|
**/
|
|
|
|
bool PluginManagerUncached::loadPluginByFileName(const Common::String &filename) {
|
|
|
|
if (filename.empty())
|
|
|
|
return false;
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
|
|
|
|
|
|
|
|
PluginList::iterator i;
|
|
|
|
for (i = _allEnginePlugins.begin(); i != _allEnginePlugins.end(); ++i) {
|
|
|
|
if (Common::String((*i)->getFileName()) == filename && (*i)->loadPlugin()) {
|
|
|
|
addToPluginsInMemList(*i);
|
|
|
|
_currentPlugin = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-19 22:59:48 +00:00
|
|
|
/**
|
2010-12-29 15:25:21 +00:00
|
|
|
* Update the config manager with a plugin file name that we found can handle
|
|
|
|
* the game.
|
|
|
|
**/
|
|
|
|
void PluginManagerUncached::updateConfigWithFileName(const Common::String &gameId) {
|
|
|
|
// Check if we have a filename for the current plugin
|
|
|
|
if ((*_currentPlugin)->getFileName()) {
|
|
|
|
if (!ConfMan.hasMiscDomain("plugin_files"))
|
|
|
|
ConfMan.addMiscDomain("plugin_files");
|
|
|
|
|
|
|
|
Common::ConfigManager::Domain *domain = ConfMan.getDomain("plugin_files");
|
|
|
|
assert(domain);
|
|
|
|
(*domain)[gameId] = (*_currentPlugin)->getFileName();
|
|
|
|
|
|
|
|
ConfMan.flushToDisk();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-19 22:59:48 +00:00
|
|
|
void PluginManagerUncached::loadFirstPlugin() {
|
2010-11-05 13:24:57 +00:00
|
|
|
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
|
2010-09-15 07:43:34 +00:00
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
// let's try to find one we can load
|
|
|
|
for (_currentPlugin = _allEnginePlugins.begin(); _currentPlugin != _allEnginePlugins.end(); ++_currentPlugin) {
|
|
|
|
if ((*_currentPlugin)->loadPlugin()) {
|
|
|
|
addToPluginsInMemList(*_currentPlugin);
|
2010-08-12 06:00:19 +00:00
|
|
|
break;
|
2010-11-05 13:24:57 +00:00
|
|
|
}
|
2010-07-30 09:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-23 13:38:37 +00:00
|
|
|
bool PluginManagerUncached::loadNextPlugin() {
|
2010-11-05 13:24:57 +00:00
|
|
|
unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
|
2010-09-15 07:43:34 +00:00
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
for (++_currentPlugin; _currentPlugin != _allEnginePlugins.end(); ++_currentPlugin) {
|
|
|
|
if ((*_currentPlugin)->loadPlugin()) {
|
|
|
|
addToPluginsInMemList(*_currentPlugin);
|
2010-09-15 07:43:34 +00:00
|
|
|
return true;
|
2010-11-05 13:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; // no more in list
|
2010-07-30 09:32:45 +00:00
|
|
|
}
|
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
/**
|
|
|
|
* Used by only the cached plugin manager. The uncached manager can only have
|
|
|
|
* one plugin in memory at a time.
|
|
|
|
**/
|
2010-12-23 13:38:37 +00:00
|
|
|
void PluginManager::loadAllPlugins() {
|
2006-10-07 00:22:48 +00:00
|
|
|
for (ProviderList::iterator pp = _providers.begin();
|
|
|
|
pp != _providers.end();
|
|
|
|
++pp) {
|
2008-05-26 00:28:48 +00:00
|
|
|
PluginList pl((*pp)->getPlugins());
|
2008-05-26 12:12:51 +00:00
|
|
|
Common::for_each(pl.begin(), pl.end(), Common::bind1st(Common::mem_fun(&PluginManager::tryLoadPlugin), this));
|
2005-03-25 17:55:57 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
|
|
|
|
2010-12-23 13:38:37 +00:00
|
|
|
void PluginManager::unloadAllPlugins() {
|
2008-05-12 01:26:43 +00:00
|
|
|
for (int i = 0; i < PLUGIN_TYPE_MAX; i++)
|
|
|
|
unloadPluginsExcept((PluginType)i, NULL);
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
void PluginManager::unloadPluginsExcept(PluginType type, const Plugin *plugin, bool deletePlugin /*=true*/) {
|
2004-08-29 19:08:08 +00:00
|
|
|
Plugin *found = NULL;
|
2010-11-05 13:24:57 +00:00
|
|
|
for (PluginList::iterator p = _pluginsInMem[type].begin(); p != _pluginsInMem[type].end(); ++p) {
|
2006-10-07 01:05:12 +00:00
|
|
|
if (*p == plugin) {
|
|
|
|
found = *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
} else {
|
2008-05-26 00:28:48 +00:00
|
|
|
(*p)->unloadPlugin();
|
2010-11-05 13:24:57 +00:00
|
|
|
if (deletePlugin)
|
|
|
|
delete *p;
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2010-11-05 13:24:57 +00:00
|
|
|
_pluginsInMem[type].clear();
|
2004-08-29 19:08:08 +00:00
|
|
|
if (found != NULL) {
|
2010-11-05 13:24:57 +00:00
|
|
|
_pluginsInMem[type].push_back(found);
|
2004-08-29 19:08:08 +00:00
|
|
|
}
|
2003-09-08 15:38:34 +00:00
|
|
|
}
|
2003-09-18 18:23:53 +00:00
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
/*
|
|
|
|
* Used only by the cached plugin manager since it deletes the plugin.
|
|
|
|
*/
|
2003-09-18 18:23:53 +00:00
|
|
|
bool PluginManager::tryLoadPlugin(Plugin *plugin) {
|
|
|
|
assert(plugin);
|
|
|
|
// Try to load the plugin
|
|
|
|
if (plugin->loadPlugin()) {
|
2010-11-05 13:24:57 +00:00
|
|
|
addToPluginsInMemList(plugin);
|
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
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
/**
|
|
|
|
* Add to the list of plugins loaded in memory.
|
|
|
|
*/
|
2010-11-05 13:24:57 +00:00
|
|
|
void PluginManager::addToPluginsInMemList(Plugin *plugin) {
|
|
|
|
bool found = false;
|
|
|
|
// The plugin is valid, see if it provides the same module as an
|
|
|
|
// already loaded one and should replace it.
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
PluginList::iterator pl = _pluginsInMem[plugin->getType()].begin();
|
|
|
|
while (!found && pl != _pluginsInMem[plugin->getType()].end()) {
|
|
|
|
if (!strcmp(plugin->getName(), (*pl)->getName())) {
|
|
|
|
// Found a duplicated module. Replace the old one.
|
|
|
|
found = true;
|
|
|
|
delete *pl;
|
|
|
|
*pl = plugin;
|
|
|
|
debug(1, "Replaced the duplicated plugin: '%s'", plugin->getName());
|
|
|
|
}
|
|
|
|
pl++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
// If it provides a new module, just add it to the list of known plugins in memory.
|
|
|
|
_pluginsInMem[plugin->getType()].push_back(plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-12 00:26:29 +00:00
|
|
|
// Engine plugins
|
|
|
|
|
|
|
|
#include "engines/metaengine.h"
|
|
|
|
|
2011-06-27 23:06:23 +00:00
|
|
|
namespace Common {
|
2010-11-16 08:23:13 +00:00
|
|
|
DECLARE_SINGLETON(EngineManager);
|
2011-06-27 23:06:23 +00:00
|
|
|
}
|
2008-05-12 00:26:29 +00:00
|
|
|
|
2011-06-19 22:59:48 +00:00
|
|
|
/**
|
2010-12-29 15:25:21 +00:00
|
|
|
* This function works for both cached and uncached PluginManagers.
|
|
|
|
* For the cached version, most of the logic here will short circuit.
|
|
|
|
*
|
|
|
|
* For the uncached version, we first try to find the plugin using the gameId
|
|
|
|
* and only if we can't find it there, we loop through the plugins.
|
|
|
|
**/
|
2010-12-23 13:38:37 +00:00
|
|
|
GameDescriptor EngineManager::findGame(const Common::String &gameName, const EnginePlugin **plugin) const {
|
2010-08-05 00:26:46 +00:00
|
|
|
GameDescriptor result;
|
2011-01-02 10:08:02 +00:00
|
|
|
|
|
|
|
// First look for the game using the plugins in memory. This is critical
|
|
|
|
// for calls coming from inside games
|
2011-06-19 22:59:48 +00:00
|
|
|
result = findGameInLoadedPlugins(gameName, plugin);
|
2011-01-02 10:08:02 +00:00
|
|
|
if (!result.gameid().empty()) {
|
|
|
|
return result;
|
|
|
|
}
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2011-01-02 10:08:02 +00:00
|
|
|
// Now look for the game using the gameId. This is much faster than scanning plugin
|
|
|
|
// by plugin
|
2010-12-29 15:25:21 +00:00
|
|
|
if (PluginMan.loadPluginFromGameId(gameName)) {
|
2011-06-19 22:59:48 +00:00
|
|
|
result = findGameInLoadedPlugins(gameName, plugin);
|
2010-12-29 15:25:21 +00:00
|
|
|
if (!result.gameid().empty()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-12-29 15:25:21 +00:00
|
|
|
// We failed to find it using the gameid. Scan the list of plugins
|
|
|
|
PluginMan.loadFirstPlugin();
|
2010-08-05 00:26:46 +00:00
|
|
|
do {
|
2011-06-19 22:59:48 +00:00
|
|
|
result = findGameInLoadedPlugins(gameName, plugin);
|
2010-08-05 00:26:46 +00:00
|
|
|
if (!result.gameid().empty()) {
|
2010-12-29 15:25:21 +00:00
|
|
|
// Update with new plugin file name
|
|
|
|
PluginMan.updateConfigWithFileName(gameName);
|
2010-08-05 00:26:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-29 15:25:21 +00:00
|
|
|
} while (PluginMan.loadNextPlugin());
|
|
|
|
|
2010-08-05 00:26:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-06-19 22:59:48 +00:00
|
|
|
/**
|
2010-12-23 13:38:37 +00:00
|
|
|
* Find the game within the plugins loaded in memory
|
|
|
|
**/
|
|
|
|
GameDescriptor EngineManager::findGameInLoadedPlugins(const Common::String &gameName, const EnginePlugin **plugin) const {
|
2008-05-12 00:26:29 +00:00
|
|
|
// Find the GameDescriptor for this target
|
2008-05-26 00:28:48 +00:00
|
|
|
const EnginePlugin::List &plugins = getPlugins();
|
2008-05-12 00:26:29 +00:00
|
|
|
GameDescriptor result;
|
|
|
|
|
|
|
|
if (plugin)
|
|
|
|
*plugin = 0;
|
|
|
|
|
2010-07-30 09:32:45 +00:00
|
|
|
EnginePlugin::List::const_iterator iter;
|
2011-06-19 22:59:48 +00:00
|
|
|
|
2010-11-05 13:24:57 +00:00
|
|
|
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
|
|
|
result = (**iter)->findGame(gameName.c_str());
|
|
|
|
if (!result.gameid().empty()) {
|
|
|
|
if (plugin)
|
|
|
|
*plugin = *iter;
|
|
|
|
return result;
|
2008-05-12 00:26:29 +00:00
|
|
|
}
|
2010-11-05 13:24:57 +00:00
|
|
|
}
|
2008-05-12 00:26:29 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
GameList EngineManager::detectGames(const Common::FSList &fslist) const {
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList candidates;
|
2010-08-02 08:43:47 +00:00
|
|
|
EnginePlugin::List plugins;
|
2010-08-03 01:10:36 +00:00
|
|
|
EnginePlugin::List::const_iterator iter;
|
2010-11-05 13:24:57 +00:00
|
|
|
PluginManager::instance().loadFirstPlugin();
|
2010-08-02 08:43:47 +00:00
|
|
|
do {
|
|
|
|
plugins = getPlugins();
|
|
|
|
// Iterate over all known games and for each check if it might be
|
|
|
|
// the game in the presented directory.
|
|
|
|
for (iter = plugins.begin(); iter != plugins.end(); ++iter) {
|
|
|
|
candidates.push_back((**iter)->detectGames(fslist));
|
|
|
|
}
|
|
|
|
} while (PluginManager::instance().loadNextPlugin());
|
2003-12-21 15:29:52 +00:00
|
|
|
return candidates;
|
|
|
|
}
|
2008-05-12 00:26:29 +00:00
|
|
|
|
2008-05-26 00:28:48 +00:00
|
|
|
const EnginePlugin::List &EngineManager::getPlugins() const {
|
|
|
|
return (const EnginePlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_ENGINE);
|
2008-05-12 00:26:29 +00:00
|
|
|
}
|
2008-05-14 14:56:29 +00:00
|
|
|
|
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
// Music plugins
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/musicplugin.h"
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2011-06-27 23:06:23 +00:00
|
|
|
namespace Common {
|
2010-11-16 08:23:13 +00:00
|
|
|
DECLARE_SINGLETON(MusicManager);
|
2011-06-27 23:06:23 +00:00
|
|
|
}
|
2008-05-14 14:56:29 +00:00
|
|
|
|
2008-06-13 14:30:47 +00:00
|
|
|
const MusicPlugin::List &MusicManager::getPlugins() const {
|
|
|
|
return (const MusicPlugin::List &)PluginManager::instance().getPlugins(PLUGIN_TYPE_MUSIC);
|
2008-05-14 14:56:29 +00:00
|
|
|
}
|