[Scummvm-cvs-logs] SF.net SVN: scummvm: [30826] scummvm/trunk

jvprat at users.sourceforge.net jvprat at users.sourceforge.net
Fri Feb 8 02:02:25 CET 2008


Revision: 30826
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30826&view=rev
Author:   jvprat
Date:     2008-02-07 17:02:25 -0800 (Thu, 07 Feb 2008)

Log Message:
-----------
Implemented plugin versioning

Modified Paths:
--------------
    scummvm/trunk/backends/plugins/dynamic-plugin.h
    scummvm/trunk/base/plugins.cpp
    scummvm/trunk/base/plugins.h
    scummvm/trunk/plugin.exp

Modified: scummvm/trunk/backends/plugins/dynamic-plugin.h
===================================================================
--- scummvm/trunk/backends/plugins/dynamic-plugin.h	2008-02-08 00:02:23 UTC (rev 30825)
+++ scummvm/trunk/backends/plugins/dynamic-plugin.h	2008-02-08 01:02:25 UTC (rev 30826)
@@ -39,6 +39,17 @@
 
 public:
 	virtual bool loadPlugin() {
+ 		// Validate the plugin API version
+ 		IntFunc verFunc = (IntFunc)findSymbol("PLUGIN_getVersion");
+ 		if (!verFunc) {
+ 			unloadPlugin();
+ 			return false;
+ 		}
+ 		if (verFunc() != PLUGIN_VERSION) {
+ 			unloadPlugin();
+ 			return false;
+ 		}
+
  		// Get the type of the plugin
  		IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType");
  		if (!typeFunc) {
@@ -51,6 +62,17 @@
  			return false;
  		}
 
+ 		// Validate the plugin type API version
+ 		IntFunc typeVerFunc = (IntFunc)findSymbol("PLUGIN_getTypeVersion");
+ 		if (!typeVerFunc) {
+ 			unloadPlugin();
+ 			return false;
+ 		}
+ 		if (typeVerFunc() != pluginTypeVersions[_type]) {
+ 			unloadPlugin();
+ 			return false;
+ 		}
+
 		// Get the plugin's instantiator object
 		GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
 		if (!getObject) {

Modified: scummvm/trunk/base/plugins.cpp
===================================================================
--- scummvm/trunk/base/plugins.cpp	2008-02-08 00:02:23 UTC (rev 30825)
+++ scummvm/trunk/base/plugins.cpp	2008-02-08 01:02:25 UTC (rev 30826)
@@ -26,6 +26,10 @@
 #include "base/plugins.h"
 #include "common/util.h"
 
+int pluginTypeVersions[PLUGIN_TYPE_MAX] = {
+	PLUGIN_TYPE_ENGINE_VERSION,
+};
+
 PluginType Plugin::getType() const {
 	return _type;
 }

Modified: scummvm/trunk/base/plugins.h
===================================================================
--- scummvm/trunk/base/plugins.h	2008-02-08 00:02:23 UTC (rev 30825)
+++ scummvm/trunk/base/plugins.h	2008-02-08 01:02:25 UTC (rev 30826)
@@ -48,12 +48,21 @@
 
 #include "engines/metaengine.h"
 
+// Global Plugin API version
+#define PLUGIN_VERSION 1
+
 enum PluginType {
 	PLUGIN_TYPE_ENGINE = 0,
 
 	PLUGIN_TYPE_MAX
 };
 
+// TODO: Make the engine API version depend on ScummVM's version
+// because of the backlinking
+#define PLUGIN_TYPE_ENGINE_VERSION 1
+
+extern int pluginTypeVersions[PLUGIN_TYPE_MAX];
+
 class Engine;
 class FSList;
 class OSystem;
@@ -83,8 +92,6 @@
 	const char *getName() const;
 	const char *getCopyright() const;
 
-//	virtual int getVersion() const	{ return 0; }	// TODO!
-
 	PluginError createInstance(OSystem *syst, Engine **engine) const;
 	GameList getSupportedGames() const;
 	GameDescriptor findGame(const char *gameid) const;
@@ -112,7 +119,9 @@
 #else
 #define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \
 	extern "C" { \
+ 		PLUGIN_EXPORT int32 PLUGIN_getVersion() { return PLUGIN_VERSION; } \
  		PLUGIN_EXPORT int32 PLUGIN_getType() { return TYPE; } \
+ 		PLUGIN_EXPORT int32 PLUGIN_getTypeVersion() { return TYPE##_VERSION; } \
 		PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
 			return new PLUGINCLASS(); \
 		} \

Modified: scummvm/trunk/plugin.exp
===================================================================
--- scummvm/trunk/plugin.exp	2008-02-08 00:02:23 UTC (rev 30825)
+++ scummvm/trunk/plugin.exp	2008-02-08 01:02:25 UTC (rev 30826)
@@ -1,2 +1,4 @@
+_PLUGIN_getVersion
 _PLUGIN_getType
+_PLUGIN_getTypeVersion
 _PLUGIN_getObject


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list