ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

sdl-provider.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/scummsys.h"
00024 
00025 #if defined(DYNAMIC_MODULES) && defined(SDL_BACKEND) && !defined(_WIN32_WCE)
00026 
00027 #include "backends/plugins/sdl/sdl-provider.h"
00028 #include "backends/plugins/dynamic-plugin.h"
00029 #include "common/fs.h"
00030 
00031 #include "backends/platform/sdl/sdl-sys.h"
00032 
00033 class SDLPlugin : public DynamicPlugin {
00034 protected:
00035     void *_dlHandle;
00036 
00037     virtual VoidFunc findSymbol(const char *symbol) {
00038         void *func = SDL_LoadFunction(_dlHandle, symbol);
00039         if (!func)
00040             warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), SDL_GetError());
00041 
00042         // FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
00043         // standard and POSIX: ISO C++ disallows casting between function pointers
00044         // and data pointers, but dlsym always returns a void pointer. For details,
00045         // see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
00046         assert(sizeof(VoidFunc) == sizeof(func));
00047         VoidFunc tmp;
00048         memcpy(&tmp, &func, sizeof(VoidFunc));
00049         return tmp;
00050     }
00051 
00052 public:
00053     SDLPlugin(const Common::String &filename)
00054         : DynamicPlugin(filename), _dlHandle(0) {}
00055 
00056     bool loadPlugin() {
00057         assert(!_dlHandle);
00058         _dlHandle = SDL_LoadObject(_filename.c_str());
00059 
00060         if (!_dlHandle) {
00061             warning("Failed loading plugin '%s' (%s)", _filename.c_str(), SDL_GetError());
00062             return false;
00063         }
00064 
00065         return DynamicPlugin::loadPlugin();
00066     }
00067 
00068     void unloadPlugin() {
00069         DynamicPlugin::unloadPlugin();
00070         if (_dlHandle) {
00071             SDL_UnloadObject(_dlHandle);
00072             _dlHandle = 0;
00073         }
00074     }
00075 };
00076 
00077 
00078 Plugin* SDLPluginProvider::createPlugin(const Common::FSNode &node) const {
00079     return new SDLPlugin(node.getPath());
00080 }
00081 
00082 
00083 #endif // defined(DYNAMIC_MODULES) && defined(SDL_BACKEND)


Generated on Sat Mar 16 2019 05:01:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge