diff options
Diffstat (limited to 'include/modules.h')
-rw-r--r-- | include/modules.h | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/include/modules.h b/include/modules.h index 5daaed613..87051704b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -19,37 +19,62 @@ #include "logger.h" #include "extensible.h" +class ModuleDef; + +struct AnopeModule +{ + ModuleDef* (*init)(); + void (*fini)(ModuleDef *); +}; + +class ModuleDef +{ + std::vector<Anope::string> dependencies; + + public: + virtual ~ModuleDef() = default; + virtual Module *Create(const Anope::string &modname, const Anope::string &creator) anope_abstract; + virtual void Destroy(Module *) anope_abstract; + virtual void BuildModuleInfo() anope_abstract; + + void Depends(const Anope::string &modname); + const std::vector<Anope::string> &GetDependencies(); +}; + +template<class ModuleClass> void ModuleInfo(ModuleDef *moddef) { } + /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. - * It defines the class factory and external AnopeInit and AnopeFini functions. */ -#ifdef _WIN32 -# define MODULE_INIT(x) \ - extern "C" DllExport Module *AnopeInit(const Anope::string &, const Anope::string &); \ - extern "C" Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ +#define MODULE_INIT(ModuleClass) \ + class ModuleClass ## ModuleDef : public ModuleDef \ { \ - return new x(modname, creator); \ - } \ - BOOLEAN WINAPI DllMain(HINSTANCE, DWORD, LPVOID) \ + Module *Create(const Anope::string &modname, const Anope::string &creator) override \ + { \ + return new ModuleClass(modname, creator); \ + } \ + void Destroy(Module *module) override \ + { \ + delete module; \ + } \ + void BuildModuleInfo() override \ + { \ + ModuleInfo<ModuleClass>(this); \ + } \ + }; \ + static ModuleDef *CreateModuleDef() \ { \ - return TRUE; \ + return new ModuleClass ## ModuleDef(); \ } \ - extern "C" DllExport void AnopeFini(x *); \ - extern "C" void AnopeFini(x *m) \ - { \ - delete m; \ - } -#else -# define MODULE_INIT(x) \ - extern "C" DllExport Module *AnopeInit(const Anope::string &modname, const Anope::string &creator) \ + static void DeleteModuleDef(ModuleDef *def) \ { \ - return new x(modname, creator); \ + delete def; \ } \ - extern "C" DllExport void AnopeFini(x *m) \ + extern "C" DllExport struct AnopeModule AnopeMod = \ { \ - delete m; \ - } -#endif + CreateModuleDef, \ + DeleteModuleDef \ + }; enum ModuleReturn { @@ -145,6 +170,9 @@ class CoreExport Module : public Extensible */ void *handle; + ModuleDef *def = nullptr; + AnopeModule *module = nullptr; + /** Time this module was created */ time_t created; |