Skip to content

Commit e4ab5dd

Browse files
committed
Change MetaEngine references to PluginObject where possible to make its semantics more generic.
svn-id: r30789
1 parent 468e9cb commit e4ab5dd

File tree

5 files changed

+48
-36
lines changed

5 files changed

+48
-36
lines changed

backends/plugins/dynamic-plugin.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@
2727
#define BACKENDS_PLUGINS_DYNAMICPLUGIN_H
2828

2929
#include "base/plugins.h"
30-
#include "engines/metaengine.h"
3130

3231

3332
class DynamicPlugin : public Plugin {
3433
protected:
3534
typedef void (*VoidFunc)();
36-
typedef MetaEngine *(*MetaAllocFunc)();
35+
typedef PluginObject *(*GetObjectFunc)();
3736

3837
virtual VoidFunc findSymbol(const char *symbol) = 0;
3938

4039
public:
4140
virtual bool loadPlugin() {
42-
// Query the plugin's name
43-
MetaAllocFunc metaAlloc = (MetaAllocFunc)findSymbol("PLUGIN_MetaEngine_alloc");
44-
if (!metaAlloc) {
41+
// Get the plugin's instantiator object
42+
GetObjectFunc getObject = (GetObjectFunc)findSymbol("PLUGIN_getObject");
43+
if (!getObject) {
4544
unloadPlugin();
4645
return false;
4746
}
4847

49-
_metaengine = metaAlloc();
50-
if (!_metaengine) {
48+
// Get the plugin object
49+
_pluginObject = getObject();
50+
if (!_pluginObject) {
5151
unloadPlugin();
5252
return false;
5353
}
@@ -56,7 +56,7 @@ class DynamicPlugin : public Plugin {
5656
}
5757

5858
virtual void unloadPlugin() {
59-
delete _metaengine;
59+
delete _pluginObject;
6060
}
6161
};
6262

base/plugins.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,47 @@
2525

2626
#include "base/plugins.h"
2727
#include "common/util.h"
28-
#include "engines/metaengine.h"
2928

3029

3130
const char *Plugin::getName() const {
32-
return _metaengine->getName();
31+
return _pluginObject->getName();
3332
}
3433

3534
const char *Plugin::getCopyright() const {
36-
return _metaengine->getCopyright();
35+
return ((MetaEngine*)_pluginObject)->getCopyright();
3736
}
3837

3938
PluginError Plugin::createInstance(OSystem *syst, Engine **engine) const {
40-
return _metaengine->createInstance(syst, engine);
39+
return ((MetaEngine*)_pluginObject)->createInstance(syst, engine);
4140
}
4241

4342
GameList Plugin::getSupportedGames() const {
44-
return _metaengine->getSupportedGames();
43+
return ((MetaEngine*)_pluginObject)->getSupportedGames();
4544
}
4645

4746
GameDescriptor Plugin::findGame(const char *gameid) const {
48-
return _metaengine->findGame(gameid);
47+
return ((MetaEngine*)_pluginObject)->findGame(gameid);
4948
}
5049

5150
GameList Plugin::detectGames(const FSList &fslist) const {
52-
return _metaengine->detectGames(fslist);
51+
return ((MetaEngine*)_pluginObject)->detectGames(fslist);
5352
}
5453

5554
SaveStateList Plugin::listSaves(const char *target) const {
56-
return _metaengine->listSaves(target);
55+
return ((MetaEngine*)_pluginObject)->listSaves(target);
5756
}
5857

5958

6059
#ifndef DYNAMIC_MODULES
6160
class StaticPlugin : public Plugin {
6261
public:
63-
StaticPlugin(MetaEngine *metaengine) {
64-
assert(metaengine);
65-
_metaengine = metaengine;
62+
StaticPlugin(PluginObject *pluginobject) {
63+
assert(pluginobject);
64+
_pluginObject = pluginobject;
6665
}
6766

6867
~StaticPlugin() {
69-
delete _metaengine;
68+
delete _pluginObject;
7069
}
7170

7271
virtual bool loadPlugin() { return true; }
@@ -85,8 +84,8 @@ class StaticPluginProvider : public PluginProvider {
8584
PluginList pl;
8685

8786
#define LINK_PLUGIN(ID) \
88-
extern MetaEngine *g_##ID##_MetaEngine_alloc(); \
89-
pl.push_back(new StaticPlugin(g_##ID##_MetaEngine_alloc()));
87+
extern PluginObject *g_##ID##_getObject(); \
88+
pl.push_back(new StaticPlugin(g_##ID##_getObject()));
9089

9190
// "Loader" for the static plugins.
9291
// Iterate over all registered (static) plugins and load them.

base/plugins.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,23 @@
3333
#include "common/util.h"
3434
#include "base/game.h"
3535

36+
/**
37+
* Abstract base class for the plugin objects which handle plugins
38+
* instantiation. Subclasses for this may be used for engine plugins
39+
* and other types of plugins.
40+
*/
41+
class PluginObject {
42+
public:
43+
virtual ~PluginObject() {}
44+
45+
/** Returns the name of the plugin. */
46+
virtual const char *getName() const = 0;
47+
};
48+
49+
#include "engines/metaengine.h"
50+
3651
class Engine;
3752
class FSList;
38-
class MetaEngine;
3953
class OSystem;
4054

4155
/**
@@ -45,10 +59,10 @@ class OSystem;
4559
*/
4660
class Plugin {
4761
protected:
48-
MetaEngine *_metaengine;
62+
PluginObject *_pluginObject;
4963

5064
public:
51-
Plugin() : _metaengine(0) {}
65+
Plugin() : _pluginObject(0) {}
5266
virtual ~Plugin() {
5367
//if (isLoaded())
5468
//unloadPlugin();
@@ -81,16 +95,16 @@ class Plugin {
8195
*/
8296

8397
#ifndef DYNAMIC_MODULES
84-
#define REGISTER_PLUGIN(ID,METAENGINE) \
85-
MetaEngine *g_##ID##_MetaEngine_alloc() { \
86-
return new METAENGINE(); \
98+
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
99+
PluginObject *g_##ID##_getObject() { \
100+
return new PLUGINCLASS(); \
87101
} \
88102
void dummyFuncToAllowTrailingSemicolon()
89103
#else
90-
#define REGISTER_PLUGIN(ID,METAENGINE) \
104+
#define REGISTER_PLUGIN(ID,PLUGINCLASS) \
91105
extern "C" { \
92-
PLUGIN_EXPORT MetaEngine *PLUGIN_MetaEngine_alloc() { \
93-
return new METAENGINE(); \
106+
PLUGIN_EXPORT PluginObject *PLUGIN_getObject() { \
107+
return new PLUGINCLASS(); \
94108
} \
95109
} \
96110
void dummyFuncToAllowTrailingSemicolon()

engines/metaengine.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
#include "common/scummsys.h"
2929
#include "common/str.h"
3030
#include "common/error.h"
31+
#include "common/fs.h"
3132

3233
#include "base/game.h"
34+
#include "base/plugins.h"
3335

3436
class Engine;
3537
class OSystem;
@@ -42,13 +44,10 @@ class OSystem;
4244
* This is then in turn used by the frontend code to detect games,
4345
* and instantiate actual Engine objects.
4446
*/
45-
class MetaEngine {
47+
class MetaEngine : public PluginObject {
4648
public:
4749
virtual ~MetaEngine() {}
4850

49-
/** Returns the name of the engine. */
50-
virtual const char *getName() const = 0;
51-
5251
/** Returns some copyright information about the engine. */
5352
virtual const char *getCopyright() const = 0;
5453

plugin.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
_PLUGIN_MetaEngine_alloc
1+
_PLUGIN_getObject

0 commit comments

Comments
 (0)