diff options
author | Jordi Vilalta Prat | 2008-05-14 17:26:05 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2008-05-14 17:26:05 +0000 |
commit | b35941c3c2da0b1c184390ee601689cedebdb32c (patch) | |
tree | 3ab8b9ca06d5e4ed0f7039fd24c863fa5d83751f /base/plugins.cpp | |
parent | c834bbba0698a8d7671c1bfc16ce8b3d65eab85a (diff) | |
download | scummvm-rg350-b35941c3c2da0b1c184390ee601689cedebdb32c.tar.gz scummvm-rg350-b35941c3c2da0b1c184390ee601689cedebdb32c.tar.bz2 scummvm-rg350-b35941c3c2da0b1c184390ee601689cedebdb32c.zip |
Added plugin priority so there's just one plugin that provides a module functionality.
svn-id: r32121
Diffstat (limited to 'base/plugins.cpp')
-rw-r--r-- | base/plugins.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/base/plugins.cpp b/base/plugins.cpp index 7dae94e006..ac8e498469 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -317,16 +317,26 @@ bool PluginManager::tryLoadPlugin(Plugin *plugin) { assert(plugin); // Try to load the plugin if (plugin->loadPlugin()) { - // If successful, add it to the list of known plugins and return. - _plugins[plugin->getType()].push_back(plugin); - - // 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... :-) + // The plugin is valid, see if it provides the same module as an + // already loaded one and should replace it. + bool found = false; + + PluginList::iterator pl = _plugins[plugin->getType()].begin(); + while (!found && pl != _plugins[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. + _plugins[plugin->getType()].push_back(plugin); + } return true; } else { |