* added missing plugin providers

This commit is contained in:
Pawel Kolodziejski 2009-10-04 10:21:50 +00:00
parent 3a9292a568
commit e3742c0b8b
9 changed files with 662 additions and 0 deletions

View file

@ -0,0 +1,101 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#if defined(DYNAMIC_MODULES) && defined(__DC__)
#include "backends/plugins/dc/dc-provider.h"
#include "backends/plugins/dynamic-plugin.h"
#include "common/fs.h"
#include "dcloader.h"
class DCPlugin : public DynamicPlugin {
protected:
void *_dlHandle;
Common::String _filename;
virtual VoidFunc findSymbol(const char *symbol) {
void *func = dlsym(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
// and data pointers, but dlsym always returns a void pointer. For details,
// see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
assert(sizeof(VoidFunc) == sizeof(func));
VoidFunc tmp;
memcpy(&tmp, &func, sizeof(VoidFunc));
return tmp;
}
public:
DCPlugin(const Common::String &filename)
: _dlHandle(0), _filename(filename) {}
bool loadPlugin() {
assert(!_dlHandle);
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
return false;
}
bool ret = DynamicPlugin::loadPlugin();
if (ret)
dlforgetsyms(_dlHandle);
return ret;
}
void unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
_dlHandle = 0;
}
}
};
Plugin* DCPluginProvider::createPlugin(const Common::FSNode &node) const {
return new DCPlugin(node.getPath());
}
bool DCPluginProvider::isPluginFilename(const Common::FSNode &node) const {
// Check the plugin suffix
Common::String filename = node.getName();
if (!filename.hasSuffix(".PLG"))
return false;
return true;
}
#endif // defined(DYNAMIC_MODULES) && defined(__DC__)

View file

@ -0,0 +1,46 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_PLUGINS_DC_H
#define BACKENDS_PLUGINS_DC_H
#include "base/plugins.h"
#if defined(DYNAMIC_MODULES) && defined(__DC__)
class DCPluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::FSNode &node) const;
bool isPluginFilename(const Common::FSNode &node) const;
virtual void addCustomDirectories(Common::StringList &dirs) const {
dirs.push_back("/");
}
};
#endif // defined(DYNAMIC_MODULES) && defined(__DC__)
#endif

View file

@ -0,0 +1,102 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_PLUGINS_DYNAMICPLUGIN_H
#define BACKENDS_PLUGINS_DYNAMICPLUGIN_H
#include "base/plugins.h"
class DynamicPlugin : public Plugin {
protected:
typedef int32 (*IntFunc)();
typedef void (*VoidFunc)();
typedef PluginObject *(*GetObjectFunc)();
virtual VoidFunc findSymbol(const char *symbol) = 0;
public:
virtual bool loadPlugin() {
// Validate the plugin API version
IntFunc verFunc = (IntFunc)findSymbol("PLUGIN_getVersion");
if (!verFunc) {
unloadPlugin();
return false;
}
if (verFunc() != PLUGIN_VERSION) {
warning("Plugin uses a different API version (you have: '%d', needed is: '%d')", verFunc(), PLUGIN_VERSION);
unloadPlugin();
return false;
}
// Get the type of the plugin
IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType");
if (!typeFunc) {
unloadPlugin();
return false;
}
_type = (PluginType)typeFunc();
if (_type >= PLUGIN_TYPE_MAX) {
warning("Plugin type unknown: %d", _type);
unloadPlugin();
return false;
}
// Validate the plugin type API version
IntFunc typeVerFunc = (IntFunc)findSymbol("PLUGIN_getTypeVersion");
if (!typeVerFunc) {
unloadPlugin();
return false;
}
if (typeVerFunc() != pluginTypeVersions[_type]) {
warning("Plugin uses a different type API version (you have: '%d', needed is: '%d')", typeVerFunc(), pluginTypeVersions[_type]);
unloadPlugin();
return false;
}
// Get the plugin's instantiator object
GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
if (!getObject) {
unloadPlugin();
return false;
}
// Get the plugin object
_pluginObject = getObject();
if (!_pluginObject) {
warning("Couldn't get the plugin object");
unloadPlugin();
return false;
}
return true;
}
virtual void unloadPlugin() {
delete _pluginObject;
}
};
#endif

View file

@ -0,0 +1,87 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#if defined(DYNAMIC_MODULES) && defined(UNIX)
#include "backends/plugins/posix/posix-provider.h"
#include "backends/plugins/dynamic-plugin.h"
#include "common/fs.h"
#include <dlfcn.h>
class POSIXPlugin : public DynamicPlugin {
protected:
void *_dlHandle;
Common::String _filename;
virtual VoidFunc findSymbol(const char *symbol) {
void *func = dlsym(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
// and data pointers, but dlsym always returns a void pointer. For details,
// see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
assert(sizeof(VoidFunc) == sizeof(func));
VoidFunc tmp;
memcpy(&tmp, &func, sizeof(VoidFunc));
return tmp;
}
public:
POSIXPlugin(const Common::String &filename)
: _dlHandle(0), _filename(filename) {}
bool loadPlugin() {
assert(!_dlHandle);
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
return false;
}
return DynamicPlugin::loadPlugin();
}
void unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
_dlHandle = 0;
}
}
};
Plugin* POSIXPluginProvider::createPlugin(const Common::FSNode &node) const {
return new POSIXPlugin(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(UNIX)

View file

@ -0,0 +1,40 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_PLUGINS_POSIX_H
#define BACKENDS_PLUGINS_POSIX_H
#include "base/plugins.h"
#if defined(DYNAMIC_MODULES) && defined(UNIX)
class POSIXPluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::FSNode &node) const;
};
#endif // defined(DYNAMIC_MODULES) && defined(UNIX)
#endif

View file

@ -0,0 +1,87 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#if defined(DYNAMIC_MODULES) && defined(SDL_BACKEND)
#include "backends/plugins/sdl/sdl-provider.h"
#include "backends/plugins/dynamic-plugin.h"
#include "common/fs.h"
#include "SDL.h"
#include "SDL_loadso.h"
class SDLPlugin : public DynamicPlugin {
protected:
void *_dlHandle;
Common::String _filename;
virtual VoidFunc findSymbol(const char *symbol) {
void *func = SDL_LoadFunction(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), SDL_GetError());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
// and data pointers, but dlsym always returns a void pointer. For details,
// see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
assert(sizeof(VoidFunc) == sizeof(func));
VoidFunc tmp;
memcpy(&tmp, &func, sizeof(VoidFunc));
return tmp;
}
public:
SDLPlugin(const Common::String &filename)
: _dlHandle(0), _filename(filename) {}
bool loadPlugin() {
assert(!_dlHandle);
_dlHandle = SDL_LoadObject(_filename.c_str());
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), SDL_GetError());
return false;
}
return DynamicPlugin::loadPlugin();
}
void unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
SDL_UnloadObject(_dlHandle);
_dlHandle = 0;
}
}
};
Plugin* SDLPluginProvider::createPlugin(const Common::FSNode &node) const {
return new SDLPlugin(node.getPath());
}
#endif // defined(DYNAMIC_MODULES) && defined(SDL_BACKEND)

View file

@ -0,0 +1,40 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_PLUGINS_SDL_H
#define BACKENDS_PLUGINS_SDL_H
#include "base/plugins.h"
#if defined(DYNAMIC_MODULES) && defined(SDL_BACKEND)
class SDLPluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::FSNode &node) const;
};
#endif // defined(DYNAMIC_MODULES) && defined(UNIX)
#endif

View file

@ -0,0 +1,115 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#if defined(DYNAMIC_MODULES) && defined(_WIN32)
#include "backends/plugins/win32/win32-provider.h"
#include "backends/plugins/dynamic-plugin.h"
#include "common/debug.h"
#include "common/fs.h"
#include <windows.h>
class Win32Plugin : public DynamicPlugin {
private:
static const TCHAR* toUnicode(const char *x) {
#ifndef _WIN32_WCE
return (const TCHAR *)x;
#else
static TCHAR unicodeString[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, x, strlen(x) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR));
return unicodeString;
#endif
}
protected:
void *_dlHandle;
Common::String _filename;
virtual VoidFunc findSymbol(const char *symbol) {
#ifndef _WIN32_WCE
FARPROC func = GetProcAddress((HMODULE)_dlHandle, symbol);
#else
FARPROC func = GetProcAddress((HMODULE)_dlHandle, toUnicode(symbol));
#endif
if (!func)
debug("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
return (void (*)())func;
}
public:
Win32Plugin(const Common::String &filename)
: _dlHandle(0), _filename(filename) {}
bool loadPlugin() {
assert(!_dlHandle);
#ifndef _WIN32_WCE
_dlHandle = LoadLibrary(_filename.c_str());
#else
if (!_filename.hasSuffix("scummvm.dll")) // skip loading the core scummvm module
_dlHandle = LoadLibrary(toUnicode(_filename.c_str()));
#endif
if (!_dlHandle) {
debug("Failed loading plugin '%s' (error code %d)", _filename.c_str(), (int32) GetLastError());
return false;
} else {
debug(1, "Success loading plugin '%s', handle %08X", _filename.c_str(), (uint32) _dlHandle);
}
return DynamicPlugin::loadPlugin();
}
void unloadPlugin() {
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (!FreeLibrary((HMODULE)_dlHandle))
debug("Failed unloading plugin '%s'", _filename.c_str());
else
debug(1, "Success unloading plugin '%s'", _filename.c_str());
_dlHandle = 0;
}
}
};
Plugin* Win32PluginProvider::createPlugin(const Common::FSNode &node) const {
return new Win32Plugin(node.getPath());
}
bool Win32PluginProvider::isPluginFilename(const Common::FSNode &node) const {
// Check the plugin suffix
Common::String filename = node.getName();
if (!filename.hasSuffix(".dll"))
return false;
return true;
}
#endif // defined(DYNAMIC_MODULES) && defined(_WIN32)

View file

@ -0,0 +1,44 @@
/* Residual - A 3D game interpreter
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef BACKENDS_PLUGINS_WIN32_H
#define BACKENDS_PLUGINS_WIN32_H
#include "base/plugins.h"
#if defined(DYNAMIC_MODULES) && defined(_WIN32)
class Win32PluginProvider : public FilePluginProvider {
protected:
Plugin* createPlugin(const Common::FSNode &node) const;
bool isPluginFilename(const Common::FSNode &node) const;
virtual void addCustomDirectories(Common::StringList &dirs) const {}
};
#endif // defined(DYNAMIC_MODULES) && defined(_WIN32)
#endif