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

dynamic-plugin.h

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 #ifndef BACKENDS_PLUGINS_DYNAMICPLUGIN_H
00024 #define BACKENDS_PLUGINS_DYNAMICPLUGIN_H
00025 
00026 #include "base/plugins.h"
00027 #include "common/textconsole.h"
00028 
00029 
00030 class DynamicPlugin : public Plugin {
00031 protected:
00032     typedef int32 (*IntFunc)();
00033     typedef void (*VoidFunc)();
00034     typedef PluginObject *(*GetObjectFunc)();
00035 
00036     virtual VoidFunc findSymbol(const char *symbol) = 0;
00037 
00038     const Common::String _filename;
00039 
00040 public:
00041     DynamicPlugin(const Common::String &filename) :
00042         _filename(filename) {}
00043 
00044     virtual bool loadPlugin() {
00045         // Validate the plugin API version
00046         IntFunc verFunc = (IntFunc)findSymbol("PLUGIN_getVersion");
00047         if (!verFunc) {
00048             unloadPlugin();
00049             return false;
00050         }
00051         if (verFunc() != PLUGIN_VERSION) {
00052             warning("Plugin uses a different API version (you have: '%d', needed is: '%d')", verFunc(), PLUGIN_VERSION);
00053             unloadPlugin();
00054             return false;
00055         }
00056 
00057         // Get the type of the plugin
00058         IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType");
00059         if (!typeFunc) {
00060             unloadPlugin();
00061             return false;
00062         }
00063         _type = (PluginType)typeFunc();
00064         if (_type >= PLUGIN_TYPE_MAX) {
00065             warning("Plugin type unknown: %d", _type);
00066             unloadPlugin();
00067             return false;
00068         }
00069 
00070         // Validate the plugin type API version
00071         IntFunc typeVerFunc = (IntFunc)findSymbol("PLUGIN_getTypeVersion");
00072         if (!typeVerFunc) {
00073             unloadPlugin();
00074             return false;
00075         }
00076         if (typeVerFunc() != pluginTypeVersions[_type]) {
00077             warning("Plugin uses a different type API version (you have: '%d', needed is: '%d')", typeVerFunc(), pluginTypeVersions[_type]);
00078             unloadPlugin();
00079             return false;
00080         }
00081 
00082         // Get the plugin's instantiator object
00083         GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
00084         if (!getObject) {
00085             unloadPlugin();
00086             return false;
00087         }
00088 
00089         // Get the plugin object
00090         _pluginObject = getObject();
00091         if (!_pluginObject) {
00092             warning("Couldn't get the plugin object");
00093             unloadPlugin();
00094             return false;
00095         }
00096 
00097         return true;
00098     }
00099 
00100     virtual void unloadPlugin() {
00101         delete _pluginObject;
00102     }
00103 
00104     virtual const char *getFileName() const {
00105         return _filename.c_str();
00106     }
00107 };
00108 
00109 #endif


Generated on Sat May 25 2019 05:00:43 for ResidualVM by doxygen 1.7.1
curved edge   curved edge