diff options
| author | Petr Mrázek | 2012-02-21 18:19:17 +0100 |
|---|---|---|
| committer | Petr Mrázek | 2012-02-21 18:19:17 +0100 |
| commit | 2cd2ee9b0cc10b79f264c3a9a4597f59835fd419 (patch) | |
| tree | 7d95cbe0b7abd5d42990a15ed8b8d801a08a48ad /library/PluginManager.cpp | |
| parent | 0b9e849096c95d68c6235c266560a2fb58908151 (diff) | |
| download | dfhack-2cd2ee9b0cc10b79f264c3a9a4597f59835fd419.tar.gz dfhack-2cd2ee9b0cc10b79f264c3a9a4597f59835fd419.tar.bz2 dfhack-2cd2ee9b0cc10b79f264c3a9a4597f59835fd419.tar.xz | |
New plugin interface
Diffstat (limited to 'library/PluginManager.cpp')
| -rw-r--r-- | library/PluginManager.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 84f052ba..492c4be6 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -120,6 +120,14 @@ struct Plugin::RefLock mutex * mut; int refcount; }; + +struct Plugin::RefAutolock +{ + RefLock * lock; + RefAutolock(RefLock * lck):lock(lck){ lock->lock(); }; + ~RefAutolock(){ lock->unlock(); }; +}; + Plugin::Plugin(Core * core, const std::string & filepath, const std::string & _filename, PluginManager * pm) { filename = filepath; @@ -154,15 +162,13 @@ Plugin::~Plugin() bool Plugin::load() { - access->lock(); + RefAutolock lock(access); if(state == PS_BROKEN) { - access->unlock(); return false; } else if(state == PS_LOADED) { - access->unlock(); return true; } Core & c = Core::getInstance(); @@ -172,16 +178,23 @@ bool Plugin::load() { con.printerr("Can't load plugin %s\n", filename.c_str()); state = PS_BROKEN; - access->unlock(); return false; } - const char * (*_PlugName)() =(const char * (*)()) LookupPlugin(plug, "plugin_name"); - if(!_PlugName) + const char ** plug_name =(const char ** ) LookupPlugin(plug, "name"); + if(!plug_name) { con.printerr("Plugin %s has no name.\n", filename.c_str()); ClosePlugin(plug); state = PS_BROKEN; - access->unlock(); + return false; + } + const char ** plug_version =(const char ** ) LookupPlugin(plug, "version"); + if(!plug_version || strcmp(DFHACK_VERSION, *plug_version) != 0) + { + con.printerr("Plugin sx was not built for this version of DFHack.\n" + "Plugin: %s, DFHack: %s\n", *plug_name, *plug_version, DFHACK_VERSION); + ClosePlugin(plug); + state = PS_BROKEN; return false; } plugin_init = (command_result (*)(Core *, std::vector <PluginCommand> &)) LookupPlugin(plug, "plugin_init"); @@ -190,20 +203,18 @@ bool Plugin::load() con.printerr("Plugin %s has no init function.\n", filename.c_str()); ClosePlugin(plug); state = PS_BROKEN; - access->unlock(); return false; } plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate"); plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown"); plugin_onstatechange = (command_result (*)(Core *, state_change_event)) LookupPlugin(plug, "plugin_onstatechange"); - //name = _PlugName(); + this->name = *plug_name; plugin_lib = plug; if(plugin_init(&c,commands) == CR_OK) { state = PS_LOADED; parent->registerCommands(this); - access->unlock(); return true; } else @@ -211,10 +222,8 @@ bool Plugin::load() con.printerr("Plugin %s has failed to initialize properly.\n", filename.c_str()); ClosePlugin(plugin_lib); state = PS_BROKEN; - access->unlock(); return false; } - // not reachable } bool Plugin::unload() |
