Initial support for plugin types

svn-id: r30825
This commit is contained in:
Jordi Vilalta Prat 2008-02-08 00:02:23 +00:00
parent 49d0b1f91e
commit c103290e2b
21 changed files with 53 additions and 24 deletions

View File

@ -31,6 +31,7 @@
class DynamicPlugin : public Plugin {
protected:
typedef int32 (*IntFunc)();
typedef void (*VoidFunc)();
typedef PluginObject *(*GetObjectFunc)();
@ -38,6 +39,18 @@ protected:
public:
virtual bool loadPlugin() {
// Get the type of the plugin
IntFunc typeFunc = (IntFunc)findSymbol("PLUGIN_getType");
if (!typeFunc) {
unloadPlugin();
return false;
}
_type = (PluginType)typeFunc();
if (_type >= PLUGIN_TYPE_MAX) {
unloadPlugin();
return false;
}
// Get the plugin's instantiator object
GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
if (!getObject) {
@ -54,7 +67,7 @@ public:
return true;
}
virtual void unloadPlugin() {
delete _pluginObject;
}

View File

@ -26,6 +26,9 @@
#include "base/plugins.h"
#include "common/util.h"
PluginType Plugin::getType() const {
return _type;
}
const char *Plugin::getName() const {
return _pluginObject->getName();
@ -59,9 +62,11 @@ SaveStateList Plugin::listSaves(const char *target) const {
#ifndef DYNAMIC_MODULES
class StaticPlugin : public Plugin {
public:
StaticPlugin(PluginObject *pluginobject) {
StaticPlugin(PluginObject *pluginobject, PluginType type) {
assert(pluginobject);
assert(type < PLUGIN_TYPE_MAX);
_pluginObject = pluginobject;
_type = type;
}
~StaticPlugin() {
@ -84,8 +89,9 @@ public:
PluginList pl;
#define LINK_PLUGIN(ID) \
extern PluginType g_##ID##_type; \
extern PluginObject *g_##ID##_getObject(); \
pl.push_back(new StaticPlugin(g_##ID##_getObject()));
pl.push_back(new StaticPlugin(g_##ID##_getObject(), g_##ID##_type));
// "Loader" for the static plugins.
// Iterate over all registered (static) plugins and load them.

View File

@ -48,6 +48,12 @@ public:
#include "engines/metaengine.h"
enum PluginType {
PLUGIN_TYPE_ENGINE = 0,
PLUGIN_TYPE_MAX
};
class Engine;
class FSList;
class OSystem;
@ -60,6 +66,7 @@ class OSystem;
class Plugin {
protected:
PluginObject *_pluginObject;
PluginType _type;
public:
Plugin() : _pluginObject(0) {}
@ -72,6 +79,7 @@ public:
virtual bool loadPlugin() = 0; // TODO: Rename to load() ?
virtual void unloadPlugin() = 0; // TODO: Rename to unload() ?
PluginType getType() const;
const char *getName() const;
const char *getCopyright() const;
@ -95,14 +103,16 @@ public:
*/
#ifndef DYNAMIC_MODULES
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
#define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \
PluginType g_##ID##_type = TYPE; \
PluginObject *g_##ID##_getObject() { \
return new PLUGINCLASS(); \
} \
void dummyFuncToAllowTrailingSemicolon()
#else
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
#define REGISTER_PLUGIN(ID,TYPE,PLUGINCLASS) \
extern "C" { \
PLUGIN_EXPORT int32 PLUGIN_getType() { return TYPE; } \
PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
return new PLUGINCLASS(); \
} \

View File

@ -2284,5 +2284,4 @@ bool AgiMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common:
return res;
}
REGISTER_PLUGIN(AGI, AgiMetaEngine);
REGISTER_PLUGIN(AGI, PLUGIN_TYPE_ENGINE, AgiMetaEngine);

View File

@ -151,7 +151,7 @@ bool AgosMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return res;
}
REGISTER_PLUGIN(AGOS, AgosMetaEngine);
REGISTER_PLUGIN(AGOS, PLUGIN_TYPE_ENGINE, AgosMetaEngine);
namespace AGOS {

View File

@ -511,4 +511,4 @@ bool CineMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return gd != 0;
}
REGISTER_PLUGIN(CINE, CineMetaEngine);
REGISTER_PLUGIN(CINE, PLUGIN_TYPE_ENGINE, CineMetaEngine);

View File

@ -146,4 +146,4 @@ bool CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm
return gd != 0;
}
REGISTER_PLUGIN(CRUISE, CruiseMetaEngine);
REGISTER_PLUGIN(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine);

View File

@ -186,4 +186,4 @@ bool DrasculaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Co
return gd != 0;
}
REGISTER_PLUGIN(DRASCULA, DrasculaMetaEngine);
REGISTER_PLUGIN(DRASCULA, PLUGIN_TYPE_ENGINE, DrasculaMetaEngine);

View File

@ -1779,7 +1779,7 @@ bool GobMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common:
return gd != 0;
}
REGISTER_PLUGIN(GOB, GobMetaEngine);
REGISTER_PLUGIN(GOB, PLUGIN_TYPE_ENGINE, GobMetaEngine);
namespace Gob {

View File

@ -134,4 +134,4 @@ bool IgorMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return gd != 0;
}
REGISTER_PLUGIN(IGOR, IgorMetaEngine);
REGISTER_PLUGIN(IGOR, PLUGIN_TYPE_ENGINE, IgorMetaEngine);

View File

@ -484,4 +484,4 @@ bool KyraMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return res;
}
REGISTER_PLUGIN(KYRA, KyraMetaEngine);
REGISTER_PLUGIN(KYRA, PLUGIN_TYPE_ENGINE, KyraMetaEngine);

View File

@ -197,4 +197,4 @@ bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return gd != 0;
}
REGISTER_PLUGIN(LURE, LureMetaEngine);
REGISTER_PLUGIN(LURE, PLUGIN_TYPE_ENGINE, LureMetaEngine);

View File

@ -218,4 +218,4 @@ bool ParallactionMetaEngine::createInstance(OSystem *syst, Engine **engine, cons
return res;
}
REGISTER_PLUGIN(PARALLACTION, ParallactionMetaEngine);
REGISTER_PLUGIN(PARALLACTION, PLUGIN_TYPE_ENGINE, ParallactionMetaEngine);

View File

@ -127,7 +127,7 @@ PluginError QueenMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
return kNoError;
}
REGISTER_PLUGIN(QUEEN, QueenMetaEngine);
REGISTER_PLUGIN(QUEEN, PLUGIN_TYPE_ENGINE, QueenMetaEngine);
namespace Queen {

View File

@ -164,7 +164,7 @@ bool SagaMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common
return gd != 0;
}
REGISTER_PLUGIN(SAGA, SagaMetaEngine);
REGISTER_PLUGIN(SAGA, PLUGIN_TYPE_ENGINE, SagaMetaEngine);
namespace Saga {

View File

@ -964,4 +964,4 @@ SaveStateList ScummMetaEngine::listSaves(const char *target) const {
return saveList;
}
REGISTER_PLUGIN(SCUMM, ScummMetaEngine);
REGISTER_PLUGIN(SCUMM, PLUGIN_TYPE_ENGINE, ScummMetaEngine);

View File

@ -194,7 +194,7 @@ PluginError SkyMetaEngine::createInstance(OSystem *syst, Engine **engine) const
return kNoError;
}
REGISTER_PLUGIN(SKY, SkyMetaEngine);
REGISTER_PLUGIN(SKY, PLUGIN_TYPE_ENGINE, SkyMetaEngine);
namespace Sky {

View File

@ -187,7 +187,7 @@ PluginError SwordMetaEngine::createInstance(OSystem *syst, Engine **engine) cons
return kNoError;
}
REGISTER_PLUGIN(SWORD1, SwordMetaEngine);
REGISTER_PLUGIN(SWORD1, PLUGIN_TYPE_ENGINE, SwordMetaEngine);
namespace Sword1 {

View File

@ -180,7 +180,7 @@ PluginError Sword2MetaEngine::createInstance(OSystem *syst, Engine **engine) con
return kNoGameDataFoundError;
}
REGISTER_PLUGIN(SWORD2, Sword2MetaEngine);
REGISTER_PLUGIN(SWORD2, PLUGIN_TYPE_ENGINE, Sword2MetaEngine);
namespace Sword2 {

View File

@ -131,6 +131,7 @@ public:
virtual const char *getName() const {
return "Touche Engine";
}
virtual const char *getCopyright() const {
return "Touche: The Adventures of the 5th Musketeer (C) Clipper Software";
}
@ -138,7 +139,6 @@ public:
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const;
};
bool ToucheMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::EncapsulatedADGameDesc &encapsulatedDesc) const {
const Common::ADGameDescription *gd = encapsulatedDesc.realDesc;
if (gd) {
@ -147,4 +147,4 @@ bool ToucheMetaEngine::createInstance(OSystem *syst, Engine **engine, const Comm
return gd != 0;
}
REGISTER_PLUGIN(TOUCHE, ToucheMetaEngine);
REGISTER_PLUGIN(TOUCHE, PLUGIN_TYPE_ENGINE, ToucheMetaEngine);

View File

@ -1 +1,2 @@
_PLUGIN_getType
_PLUGIN_getObject