diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-11-11 00:17:07 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-11-11 00:17:07 +0000 |
commit | 19487dbebc520450e457472b97d9e7bcd5160c00 (patch) | |
tree | 5ba36439139db77ff11c549228a3dbf69727e9cc /src/modmanager_static.cpp | |
parent | 316167b91713739d784cc4c640275ebe2a9f054a (diff) |
Allow static build of inspircd without module support
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12083 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modmanager_static.cpp')
-rw-r--r-- | src/modmanager_static.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp new file mode 100644 index 000000000..e09310a13 --- /dev/null +++ b/src/modmanager_static.cpp @@ -0,0 +1,127 @@ +#include "inspircd.h" + +#ifdef PURE_STATIC + +static std::vector<AllCommandList::fn>* cmdlist = NULL; +static std::vector<AllModuleList*>* modlist = NULL; + +AllCommandList::AllCommandList(fn cmd) +{ + if (!cmdlist) + cmdlist = new std::vector<AllCommandList::fn>(); + cmdlist->push_back(cmd); +} + +AllModuleList::AllModuleList(AllModuleList::fn mod, const std::string& Name) : init(mod), name(Name) +{ + if (!modlist) + modlist = new std::vector<AllModuleList*>(); + modlist->push_back(this); +} + +class AllModule : public Module +{ + std::vector<Command*> cmds; + public: + AllModule() + { + if (!cmdlist) + return; + try + { + cmds.reserve(cmdlist->size()); + for(std::vector<AllCommandList::fn>::iterator i = cmdlist->begin(); i != cmdlist->end(); ++i) + { + Command* c = (*i)(this); + cmds.push_back(c); + ServerInstance->AddCommand(c); + } + } + catch (...) + { + this->AllModule::~AllModule(); + throw; + } + } + + ~AllModule() + { + for(std::vector<Command*>::iterator i = cmds.begin(); i != cmds.end(); ++i) + delete *i; + } + + Version GetVersion() + { + return Version("All commands", VF_VENDOR|VF_CORE); + } +}; + +MODULE_INIT(AllModule) + +bool ModuleManager::Load(const char* filename) +{ + return false; +} + +bool ModuleManager::CanUnload(Module* mod) +{ + return false; +} + +void ModuleManager::DoSafeUnload(Module* mod) +{ +} + +bool ModuleManager::Unload(Module* mod) +{ + return false; +} + +void ModuleManager::Reload(Module* mod, HandlerBase1<void, bool>* callback) +{ + callback->Call(false); +} + +void ModuleManager::LoadAll() +{ + ModCount = 0; + for(std::vector<AllModuleList*>::iterator i = modlist->begin(); i != modlist->end(); ++i) + { + try + { + Module* c = (*(**i).init)(); + c->ModuleSourceFile = (**i).name; + Modules[(**i).name] = c; + FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); + } + catch (CoreException& modexcept) + { + ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); + } + } + + /* We give every module a chance to re-prioritize when we introduce a new one, + * not just the one thats loading, as the new module could affect the preference + * of others + */ + for(int tries = 0; tries < 20; tries++) + { + prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST; + for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n) + n->second->Prioritize(); + + if (prioritizationState == PRIO_STATE_LAST) + break; + if (tries == 19) + ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected"); + } + + ServerInstance->BuildISupport(); +} + +void ModuleManager::UnloadAll() +{ + // TODO don't really need this, who cares if we leak on exit? +} + +#endif |