summaryrefslogtreecommitdiff
path: root/include/modules.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2015-10-27 13:21:24 -0400
committerAdam <Adam@anope.org>2015-10-27 13:21:24 -0400
commit162fdbe5815bbdf187f549fefac94ff476d72e62 (patch)
tree1c58968fd29dd90ef8ab6dc0f3013d88b313ce4e /include/modules.h
parentc6a92296d4175a2d2276c2d5a46894af3d9085f4 (diff)
Beginning of new module dependency stuff, seems to compile and link. Move some of the madness in chanserv.h to the module.
Diffstat (limited to 'include/modules.h')
-rw-r--r--include/modules.h72
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;