X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodmanager_static.cpp;h=76f16fa92fd140e2594a0ab9062c70b46c99f2b2;hb=1e8389b27ff99ad9f48c890486ebef936acafc41;hp=e09310a13bf66fde0823082094565e38540baa39;hpb=19487dbebc520450e457472b97d9e7bcd5160c00;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index e09310a13..76f16fa92 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -1,9 +1,33 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009-2010 Daniel De Graaf + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#define MODNAME "cmd_all" + #include "inspircd.h" +#include "exitcodes.h" +#include #ifdef PURE_STATIC +typedef std::map modmap; static std::vector* cmdlist = NULL; -static std::vector* modlist = NULL; +static modmap* modlist = NULL; AllCommandList::AllCommandList(fn cmd) { @@ -15,8 +39,8 @@ AllCommandList::AllCommandList(fn cmd) AllModuleList::AllModuleList(AllModuleList::fn mod, const std::string& Name) : init(mod), name(Name) { if (!modlist) - modlist = new std::vector(); - modlist->push_back(this); + modlist = new modmap(); + modlist->insert(std::make_pair(Name, this)); } class AllModule : public Module @@ -34,7 +58,6 @@ class AllModule : public Module { Command* c = (*i)(this); cmds.push_back(c); - ServerInstance->AddCommand(c); } } catch (...) @@ -58,70 +81,68 @@ class AllModule : public Module MODULE_INIT(AllModule) -bool ModuleManager::Load(const char* filename) -{ - return false; -} - -bool ModuleManager::CanUnload(Module* mod) +bool ModuleManager::Load(const std::string& name, bool defer) { - return false; -} - -void ModuleManager::DoSafeUnload(Module* mod) -{ -} - -bool ModuleManager::Unload(Module* mod) -{ - return false; -} + modmap::iterator it = modlist->find(name); + if (it == modlist->end()) + return false; + Module* mod = NULL; -void ModuleManager::Reload(Module* mod, HandlerBase1* callback) -{ - callback->Call(false); -} + ServiceList newservices; + if (!defer) + this->NewServices = &newservices; -void ModuleManager::LoadAll() -{ - ModCount = 0; - for(std::vector::iterator i = modlist->begin(); i != modlist->end(); ++i) + try { - try + mod = (*it->second->init)(); + mod->ModuleSourceFile = name; + mod->ModuleDLLManager = NULL; + mod->dying = false; + Modules[name] = mod; + this->NewServices = NULL; + if (defer) { - Module* c = (*(**i).init)(); - c->ModuleSourceFile = (**i).name; - Modules[(**i).name] = c; - FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "New module introduced: %s", name.c_str()); + return true; } - catch (CoreException& modexcept) + else { - ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); + ConfigStatus confstatus; + + AttachAll(mod); + AddServices(newservices); + mod->init(); + mod->ReadConfig(confstatus); } } - - /* 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++) + catch (CoreException& modexcept) { - prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST; - for (std::map::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"); + this->NewServices = NULL; + + if (mod) + DoSafeUnload(mod); + ServerInstance->Logs->Log("MODULE", LOG_DEFAULT, "Unable to load " + name + ": " + modexcept.GetReason()); + return false; } - ServerInstance->BuildISupport(); + FOREACH_MOD(OnLoadModule, (mod)); + PrioritizeHooks(); + ServerInstance->ISupport.Build(); + return true; } -void ModuleManager::UnloadAll() +void ModuleManager::LoadCoreModules(std::map& servicemap) { - // TODO don't really need this, who cares if we leak on exit? + for (modmap::const_iterator i = modlist->begin(); i != modlist->end(); ++i) + { + const std::string modname = i->first; + if (modname[0] == 'c') + { + this->NewServices = &servicemap[modname]; + Load(modname, true); + } + } + this->NewServices = NULL; } #endif