Ticket #8795: plugins_version.patch
File plugins_version.patch, 3.7 KB (added by , 17 years ago) |
---|
-
base/plugins.h
33 33 #include "common/util.h" 34 34 #include "base/game.h" 35 35 36 #define PLUGIN_VERSION 1 37 38 enum PluginType { 39 PLUGIN_TYPE_ENGINE = 0, 40 PLUGIN_TYPE_SCALER, 41 PLUGIN_TYPE_MIDI, 42 43 PLUGIN_TYPE_MAX 44 }; 45 46 #define PLUGIN_TYPE_ENGINE_VERSION 1 47 #define PLUGIN_TYPE_SCALER_VERSION 1 48 #define PLUGIN_TYPE_MIDI_VERSION 1 49 50 extern int pluginTypeVersions[PLUGIN_TYPE_MAX]; 51 36 52 class Engine; 37 53 class FSList; 38 54 class MetaEngine; … … 52 68 53 69 virtual const char *getName() const = 0; 54 70 virtual const char *getCopyright() const = 0; 55 // virtual int getVersion() const { return 0; } // TODO!56 71 57 72 virtual GameList getSupportedGames() const = 0; 58 73 virtual GameDescriptor findGame(const char *gameid) const = 0; … … 72 87 */ 73 88 74 89 #ifndef DYNAMIC_MODULES 75 #define REGISTER_PLUGIN(ID,METAENGINE) \ 90 #define REGISTER_PLUGIN(ID,TYPE,METAENGINE) \ 91 int g_##ID##_type = TYPE; \ 76 92 MetaEngine *g_##ID##_MetaEngine_alloc() { \ 77 93 return new METAENGINE(); \ 78 94 } \ 79 95 void dummyFuncToAllowTrailingSemicolon() 80 96 #else 81 #define REGISTER_PLUGIN(ID, METAENGINE) \97 #define REGISTER_PLUGIN(ID,TYPE,METAENGINE) \ 82 98 extern "C" { \ 99 PLUGIN_EXPORT int PLUGIN_getVersion() { return PLUGIN_VERSION; } \ 100 PLUGIN_EXPORT int PLUGIN_getType() { return TYPE; } \ 101 PLUGIN_EXPORT int PLUGIN_getTypeVersion() { return TYPE##_VERSION; } \ 83 102 PLUGIN_EXPORT MetaEngine *PLUGIN_MetaEngine_alloc() { \ 84 103 return new METAENGINE(); \ 85 104 } \ -
base/plugins.cpp
27 27 #include "common/util.h" 28 28 #include "engines/metaengine.h" 29 29 30 int pluginTypeVersions[PLUGIN_TYPE_MAX] = { 31 PLUGIN_TYPE_ENGINE_VERSION, 32 PLUGIN_TYPE_SCALER_VERSION, 33 PLUGIN_TYPE_MIDI_VERSION 34 }; 30 35 31 36 #ifndef DYNAMIC_MODULES 32 37 class StaticPlugin : public Plugin { … … 81 86 PluginList pl; 82 87 83 88 #define LINK_PLUGIN(ID) \ 89 extern int *g_##ID##_type; \ 84 90 extern MetaEngine *g_##ID##_MetaEngine_alloc(); \ 85 91 pl.push_back(new StaticPlugin(g_##ID##_MetaEngine_alloc())); 86 92 -
backends/plugins/dynamic-plugin.h
32 32 33 33 class DynamicPlugin : public Plugin { 34 34 protected: 35 typedef int (*IntFunc)(); 36 35 37 typedef void (*VoidFunc)(); 36 38 37 39 typedef MetaEngine *(*MetaAllocFunc)(); … … 71 73 } 72 74 73 75 virtual bool loadPlugin() { 76 // Validate the plugin API version 77 IntFunc verFunc = (IntFunc)findSymbol("PLUGIN_getVersion"); 78 if (!verFunc) { 79 unloadPlugin(); 80 return false; 81 } 82 if (verFunc() != PLUGIN_VERSION) { 83 unloadPlugin(); 84 return false; 85 } 86 87 // Get the type of the plugin 88 IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType"); 89 if (!typeFunc) { 90 unloadPlugin(); 91 return false; 92 } 93 int type = typeFunc(); 94 if (type >= PLUGIN_TYPE_MAX) { 95 unloadPlugin(); 96 return false; 97 } 98 99 // Validate the plugin type API version 100 IntFunc typeVerFunc = (IntFunc)findSymbol("PLUGIN_getTypeVersion"); 101 if (!typeVerFunc) { 102 unloadPlugin(); 103 return false; 104 } 105 if (typeVerFunc() != pluginTypeVersions[type]) { 106 unloadPlugin(); 107 return false; 108 } 109 74 110 // Query the plugin's name 75 111 MetaAllocFunc metaAlloc = (MetaAllocFunc)findSymbol("PLUGIN_MetaEngine_alloc"); 76 112 if (!metaAlloc) { … … 78 114 return false; 79 115 } 80 116 117 // Allocate the metaengine 81 118 _metaengine = metaAlloc(); 82 119 if (!_metaengine) { 83 120 unloadPlugin();