RCS file: /cvsroot/scummvm/scummvm/common.rules,v
retrieving revision 1.16
diff -u -d -r1.16 common.rules
|
|
|
10 | 10 | # TODO: Right now, for Mac OS X only. We either will have to generate this |
11 | 11 | # via the configure script, or put in some 'if' statements to choose from |
12 | 12 | # one of several build rules |
13 | | PLUGIN-$(MODULE) := $(MODULE)/$(PLUGIN_PREFIX)$(MODULE)$(PLUGIN_SUFFIX) |
| 13 | PLUGIN-$(MODULE) := plugins/$(PLUGIN_PREFIX)$(MODULE)$(PLUGIN_SUFFIX) |
14 | 14 | $(PLUGIN-$(MODULE)): $(MODULE_OBJS) $(PLUGIN_EXTRA_DEPS) |
| 15 | $(MKDIR) plugins |
15 | 16 | $(CXX) $(PLUGIN_LDFLAGS) $(filter-out $(PLUGIN_EXTRA_DEPS),$+) -o $@ |
16 | 17 | PLUGIN:= |
17 | 18 | plugins: $(PLUGIN-$(MODULE)) |
RCS file: /cvsroot/scummvm/scummvm/base/plugins.cpp,v
retrieving revision 1.38
diff -u -d -r1.38 plugins.cpp
|
|
|
39 | 39 | |
40 | 40 | #ifdef UNIX |
41 | 41 | #include <dlfcn.h> |
42 | | #define DYNAMIC_PLUGIN_PATH(name) (name "/" PLUGIN_PREFIX name PLUGIN_SUFFIX) |
| 42 | #define PLUGIN_DIRECTORY "plugins/" |
43 | 43 | #else |
44 | 44 | #ifdef __DC__ |
45 | 45 | #include "dcloader.h" |
46 | | #define DYNAMIC_PLUGIN_PATH(name) (name ".plg") |
| 46 | #define PLUGIN_DIRECTORY "" |
| 47 | #define PLUGIN_PREFIX "" |
| 48 | #define PLUGIN_SUFFIX ".plg" |
47 | 49 | #else |
48 | 50 | #error No support for loading plugins on non-unix systems at this point! |
49 | 51 | #endif |
50 | 52 | #endif |
51 | 53 | |
| 54 | |
| 55 | #else |
| 56 | |
| 57 | PluginRegistrator *PluginRegistrator::_head = 0; |
| 58 | |
| 59 | PluginRegistrator::PluginRegistrator(const char *name, GameList games, EngineFactory ef, DetectFunc df) |
| 60 | : _name(name), _ef(ef), _df(df), _games(games) { |
| 61 | printf("Automatically registered plugin '%s'\n", name); |
| 62 | _next = _head; |
| 63 | _head = this; |
| 64 | } |
| 65 | |
52 | 66 | #endif |
53 | 67 | |
54 | 68 | |
… |
… |
|
108 | 122 | void *findSymbol(const char *symbol); |
109 | 123 | |
110 | 124 | public: |
111 | | DynamicPlugin(const char *filename) |
| 125 | DynamicPlugin(const Common::String &filename) |
112 | 126 | : _dlHandle(0), _filename(filename), _ef(0), _df(0), _games() {} |
113 | 127 | |
114 | 128 | const char *getName() const { return _name.c_str(); } |
… |
… |
|
222 | 236 | // Hence one more symbol should be exported by plugins which returns |
223 | 237 | // the "ABI" version the plugin was built for, and we can compare that |
224 | 238 | // to the ABI version of the executable. |
225 | | #define LOAD_MODULE(name, NAME) \ |
226 | | tryLoadPlugin(new DynamicPlugin(DYNAMIC_PLUGIN_PATH(name))); |
227 | | #else |
228 | | // "Loader" for the static plugins |
229 | | #define LOAD_MODULE(name, NAME) \ |
230 | | tryLoadPlugin(new StaticPlugin(name, Engine_##NAME##_gameList(), Engine_##NAME##_create, Engine_##NAME##_detectGames)); |
231 | | #endif |
232 | 239 | |
233 | 240 | // Load all plugins. |
234 | 241 | // Right now the list is hardcoded. On the long run, of course it should |
235 | 242 | // automatically be determined. |
| 243 | #if 0 |
| 244 | static const char *plugin_names[] = { |
236 | 245 | #ifndef DISABLE_SCUMM |
237 | | LOAD_MODULE("scumm", SCUMM); |
| 246 | "scumm", |
238 | 247 | #endif |
239 | | |
240 | 248 | #ifndef DISABLE_SIMON |
241 | | LOAD_MODULE("simon", SIMON); |
| 249 | "simon", |
242 | 250 | #endif |
243 | | |
244 | 251 | #ifndef DISABLE_SKY |
245 | | LOAD_MODULE("sky", SKY); |
| 252 | "sky", |
246 | 253 | #endif |
247 | | |
248 | 254 | #ifndef DISABLE_SWORD1 |
249 | | LOAD_MODULE("sword1", SWORD1); |
| 255 | "sword1", |
250 | 256 | #endif |
251 | | |
252 | 257 | #ifndef DISABLE_SWORD2 |
253 | | LOAD_MODULE("sword2", SWORD2); |
| 258 | "sword2", |
254 | 259 | #endif |
255 | | |
256 | 260 | #ifndef DISABLE_QUEEN |
257 | | LOAD_MODULE("queen", QUEEN); |
| 261 | "queen", |
258 | 262 | #endif |
259 | | |
260 | 263 | #ifndef DISABLE_KYRA |
261 | | LOAD_MODULE("kyra", KYRA); |
| 264 | "kyra", |
262 | 265 | #endif |
263 | | |
264 | 266 | #ifndef DISABLE_SAGA |
265 | | LOAD_MODULE("saga", SAGA); |
| 267 | "saga", |
| 268 | #endif |
| 269 | 0 |
| 270 | }; |
| 271 | const char **plugin; |
| 272 | for (plugin = plugin_names; *plugin != 0; plugin++) { |
| 273 | Common::String path(PLUGIN_DIRECTORY); |
| 274 | path += PLUGIN_PREFIX; |
| 275 | path += *plugin; |
| 276 | path += PLUGIN_SUFFIX; |
| 277 | tryLoadPlugin(new DynamicPlugin(path)); |
| 278 | } |
| 279 | #else |
| 280 | // Scan for all plugins in this directory |
| 281 | FilesystemNode dir(PLUGIN_DIRECTORY); |
| 282 | FSList files(dir.listDir(FilesystemNode::kListFilesOnly)); |
| 283 | |
| 284 | for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { |
| 285 | Common::String name(i->displayName()); |
| 286 | if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { |
| 287 | tryLoadPlugin(new DynamicPlugin(i->path())); |
| 288 | } |
| 289 | } |
| 290 | |
266 | 291 | #endif |
| 292 | |
| 293 | #else |
| 294 | // "Loader" for the static plugins. |
| 295 | // Iterate over all registered (static) plugins and load them. |
| 296 | PluginRegistrator *plugin = PluginRegistrator::_head; |
| 297 | for (; plugin != 0; plugin = plugin->_next) { |
| 298 | tryLoadPlugin(new StaticPlugin(plugin->_name, plugin->_games, plugin->_ef, plugin->_df)); |
| 299 | } |
| 300 | #endif |
| 301 | |
267 | 302 | } |
268 | 303 | |
269 | 304 | void PluginManager::unloadPlugins() { |
RCS file: /cvsroot/scummvm/scummvm/base/plugins.h,v
retrieving revision 1.25
diff -u -d -r1.25 plugins.h
|
|
|
78 | 78 | |
79 | 79 | |
80 | 80 | /** |
81 | | * The REGISTER_PLUGIN is a convenience macro meant to ease writing |
| 81 | * REGISTER_PLUGIN is a convenience macro meant to ease writing |
82 | 82 | * the plugin interface for our modules. In particular, using it |
83 | 83 | * makes it possible to compile the very same code in a module |
84 | 84 | * both as a static and a dynamic plugin. |
… |
… |
|
87 | 87 | * @todo on Windows, we might need __declspec(dllexport) ? |
88 | 88 | */ |
89 | 89 | #ifndef DYNAMIC_MODULES |
90 | | #define REGISTER_PLUGIN(name,gameListFactory,engineFactory,detectGames) |
| 90 | #define REGISTER_PLUGIN(name,gameListFactory,engineFactory,detectGames) \ |
| 91 | static PluginRegistrator pluginReg(name, gameListFactory(), engineFactory, detectGames); |
91 | 92 | #else |
92 | 93 | #define REGISTER_PLUGIN(name,gameListFactory,engineFactory,detectGames) \ |
93 | 94 | extern "C" { \ |
… |
… |
|
98 | 99 | } |
99 | 100 | #endif |
100 | 101 | |
| 102 | #ifndef DYNAMIC_MODULES |
| 103 | /** |
| 104 | * The PluginRegistrator class is used by the static version of REGISTER_PLUGIN |
| 105 | * to allow static 'plugins' to automatically register with the PluginManager. |
| 106 | * The trick is to put a global instance of PluginRegistrator into each engine. |
| 107 | * Then when the application is started, the constructor of each of these |
| 108 | * objects is run. They then hook themselves into a linked list, and store |
| 109 | * all data passed to them, which the PluginManager then can use to load |
| 110 | * and initialize the static plugins. |
| 111 | * Neat, isn't it ? ;-) |
| 112 | * |
| 113 | * Caveat: there may be systems / linkers where this trick doesn't work because |
| 114 | * the linker doesn't invoke the object constructors. This system has currently |
| 115 | * been tested on Mac OS X only. |
| 116 | */ |
| 117 | class PluginRegistrator { |
| 118 | friend class PluginManager; |
| 119 | public: |
| 120 | typedef Engine *(*EngineFactory)(GameDetector *detector, OSystem *syst); |
| 121 | typedef DetectedGameList (*DetectFunc)(const FSList &fslist); |
| 122 | |
| 123 | protected: |
| 124 | static PluginRegistrator *_head; |
| 125 | |
| 126 | PluginRegistrator *_next; |
| 127 | |
| 128 | const char *_name; |
| 129 | EngineFactory _ef; |
| 130 | DetectFunc _df; |
| 131 | GameList _games; |
| 132 | |
| 133 | public: |
| 134 | PluginRegistrator(const char *name, GameList games, EngineFactory ef, DetectFunc df); |
| 135 | }; |
| 136 | #endif |
| 137 | |
101 | 138 | |
102 | 139 | /** List of plugins. */ |
103 | 140 | typedef Common::Array<Plugin *> PluginList; |