Instantiate and hook up the plugin providers in the main() function of the corresponding backends (porters may have to update their ports if they were using the POSIX or Win32 module loading code implicitly); some cleanup

svn-id: r24153
This commit is contained in:
Max Horn 2006-10-07 01:05:12 +00:00
parent c8a21d19d1
commit df5be19409
8 changed files with 36 additions and 34 deletions

View File

@ -31,6 +31,8 @@
#include "DCLauncherDialog.h"
#include <common/config-manager.h>
#include "backends/plugins/dc/dc-provider.h"
Icon icon;
const char *gGameName;
@ -205,6 +207,10 @@ int main()
g_system = new OSystem_Dreamcast();
assert(g_system);
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new DCPluginProvider());
#endif
int res = scummvm_main(argc, argv);
exit(0);

View File

@ -22,6 +22,7 @@
*/
#include "backends/platform/sdl/sdl-common.h"
#include "backends/plugins/sdl/sdl-provider.h"
#include "common/config-manager.h"
#include "common/util.h"
#include "base/main.h"
@ -95,6 +96,10 @@ int main(int argc, char *argv[]) {
#endif
assert(g_system);
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new SDLPluginProvider());
#endif
// Invoke the actual ScummVM main entry point:
int res = scummvm_main(argc, argv);
g_system->quit(); // TODO: Consider removing / replacing this!

View File

@ -30,6 +30,7 @@
#include "base/main.h"
#include "backends/intern.h"
#include "backends/platform/x11/x11.h"
#include "backends/plugins/posix/posix-provider.h"
#include <stdio.h>
#include <assert.h>
@ -62,6 +63,10 @@ int main(int argc, char *argv[]) {
g_system = OSystem_X11::create(0, 0);
assert(g_system);
#ifdef DYNAMIC_MODULES
PluginManager::instance().addPluginProvider(new POSIXPluginProvider());
#endif
// Invoke the actual ScummVM main entry point:
int res = scummvm_main(argc, argv);
g_system->quit(); // TODO: Consider removing / replacing this!

View File

@ -77,6 +77,7 @@ public:
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
_dlHandle = 0;
}
}
};

View File

@ -70,6 +70,7 @@ public:
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
_dlHandle = 0;
}
}
};

View File

@ -71,6 +71,7 @@ public:
if (_dlHandle) {
if (!FreeLibrary((HMODULE)_dlHandle))
warning("Failed unloading plugin '%s'", _filename.c_str());
_dlHandle = 0;
}
}
};

View File

@ -21,20 +21,8 @@
*
*/
#include "common/stdafx.h"
#include "base/plugins.h"
#include "common/util.h"
#include "common/fs.h"
#ifdef DYNAMIC_MODULES
#if defined(UNIX)
#include "backends/plugins/posix/posix-provider.h"
#elif defined(__DC__)
#include "backends/plugins/dc/dc-provider.h"
#elif defined(_WIN32)
#include "backends/plugins/win32/win32-provider.h"
#endif
#endif
void DetectedGame::updateDesc(const char *extra) {
@ -162,8 +150,7 @@ public:
#ifndef DISABLE_AGI
LINK_PLUGIN(AGI)
#endif
return pl;
}
};
@ -176,22 +163,9 @@ public:
DECLARE_SINGLETON(PluginManager);
PluginManager::PluginManager() {
// FIXME: The following code should be moved to the backend specific code,
// usually into the main() function just before scummvm_main is called
#ifdef DYNAMIC_MODULES
#if defined(UNIX)
addPluginProvider(new POSIXPluginProvider());
#elif defined(__DC__)
addPluginProvider(new DCPluginProvider());
#elif defined(_WIN32)
addPluginProvider(new Win32PluginProvider());
#else
#error No support for loading plugins on non-unix systems at this point!
#endif
#else
#ifndef DYNAMIC_MODULES
// Add the static plugin provider if we do not build with dynamic
// plugins.
addPluginProvider(new StaticPluginProvider());
#endif
}
@ -199,6 +173,13 @@ PluginManager::PluginManager() {
PluginManager::~PluginManager() {
// Explicitly unload all loaded plugins
unloadPlugins();
// Delete the plugin providers
for (ProviderList::iterator pp = _providers.begin();
pp != _providers.end();
++pp) {
delete *pp;
}
}
void PluginManager::addPluginProvider(PluginProvider *pp) {
@ -224,12 +205,13 @@ void PluginManager::unloadPlugins() {
void PluginManager::unloadPluginsExcept(const Plugin *plugin) {
Plugin *found = NULL;
uint i;
for (PluginList::iterator p = _plugins.begin(); p != _plugins.end(); ++p)
for (i = 0; i < _plugins.size(); i++) {
if (_plugins[i] == plugin) {
found = _plugins[i];
if (*p == plugin) {
found = *p;
} else {
_plugins[i]->unloadPlugin();
delete _plugins[i];
(**p).unloadPlugin();
delete *p;
}
}
_plugins.clear();

View File

@ -24,6 +24,7 @@
#ifndef BASE_PLUGINS_H
#define BASE_PLUGINS_H
#include "common/stdafx.h"
#include "common/array.h"
#include "common/list.h"
#include "common/singleton.h"