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.
|
2006-10-07 00:22:48 +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.
|
2014-02-18 01:34:23 +00:00
|
|
|
*
|
2006-10-07 00:22:48 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:23 +00:00
|
|
|
*
|
2006-10-07 00:22:48 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2011-05-05 13:38:54 +00:00
|
|
|
#if defined(DYNAMIC_MODULES) && defined(POSIX)
|
2006-10-07 00:22:48 +00:00
|
|
|
|
|
|
|
#include "backends/plugins/posix/posix-provider.h"
|
|
|
|
#include "backends/plugins/dynamic-plugin.h"
|
2008-09-30 16:34:38 +00:00
|
|
|
#include "common/fs.h"
|
2006-10-07 00:22:48 +00:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
|
|
|
|
class POSIXPlugin : public DynamicPlugin {
|
|
|
|
protected:
|
|
|
|
void *_dlHandle;
|
|
|
|
|
|
|
|
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());
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
// 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)
|
2010-12-29 15:25:21 +00:00
|
|
|
: DynamicPlugin(filename), _dlHandle(0) {}
|
2006-10-07 00:22:48 +00:00
|
|
|
|
|
|
|
bool loadPlugin() {
|
|
|
|
assert(!_dlHandle);
|
|
|
|
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
if (!_dlHandle) {
|
|
|
|
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
return DynamicPlugin::loadPlugin();
|
2006-10-07 00:22:48 +00:00
|
|
|
}
|
2008-05-02 14:30:06 +00:00
|
|
|
|
2006-10-07 00:22:48 +00:00
|
|
|
void unloadPlugin() {
|
2008-02-04 07:38:42 +00:00
|
|
|
DynamicPlugin::unloadPlugin();
|
2006-10-07 00:22:48 +00:00
|
|
|
if (_dlHandle) {
|
|
|
|
if (dlclose(_dlHandle) != 0)
|
|
|
|
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
|
2006-10-07 01:05:12 +00:00
|
|
|
_dlHandle = 0;
|
2006-10-07 00:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-05 13:38:54 +00:00
|
|
|
Plugin *POSIXPluginProvider::createPlugin(const Common::FSNode &node) const {
|
2008-09-30 16:34:38 +00:00
|
|
|
return new POSIXPlugin(node.getPath());
|
2006-10-07 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 13:38:54 +00:00
|
|
|
#endif // defined(DYNAMIC_MODULES) && defined(POSIX)
|