5 static std::vector<AllCommandList::fn>* cmdlist = NULL;
6 static std::vector<AllModuleList*>* modlist = NULL;
8 AllCommandList::AllCommandList(fn cmd)
11 cmdlist = new std::vector<AllCommandList::fn>();
12 cmdlist->push_back(cmd);
15 AllModuleList::AllModuleList(AllModuleList::fn mod, const std::string& Name) : init(mod), name(Name)
18 modlist = new std::vector<AllModuleList*>();
19 modlist->push_back(this);
22 class AllModule : public Module
24 std::vector<Command*> cmds;
32 cmds.reserve(cmdlist->size());
33 for(std::vector<AllCommandList::fn>::iterator i = cmdlist->begin(); i != cmdlist->end(); ++i)
35 Command* c = (*i)(this);
37 ServerInstance->AddCommand(c);
42 this->AllModule::~AllModule();
49 for(std::vector<Command*>::iterator i = cmds.begin(); i != cmds.end(); ++i)
55 return Version("All commands", VF_VENDOR|VF_CORE);
59 MODULE_INIT(AllModule)
61 bool ModuleManager::Load(const std::string& name, bool)
63 for(std::vector<AllModuleList*>::iterator i = modlist->begin(); i != modlist->end(); ++i)
65 if ((**i).name == name)
73 FOREACH_MOD(I_OnLoadModule,OnLoadModule(c));
76 catch (CoreException& modexcept)
81 ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason());
89 struct UnloadAction : public HandlerBase0<void>
92 UnloadAction(Module* m) : mod(m) {}
95 ServerInstance->Modules->DoSafeUnload(mod);
96 ServerInstance->GlobalCulls.Apply();
97 ServerInstance->GlobalCulls.AddItem(this);
101 struct ReloadAction : public HandlerBase0<void>
104 HandlerBase1<void, bool>* const callback;
105 ReloadAction(Module* m, HandlerBase1<void, bool>* c)
106 : mod(m), callback(c) {}
109 std::string name = mod->ModuleSourceFile;
110 ServerInstance->Modules->DoSafeUnload(mod);
111 ServerInstance->GlobalCulls.Apply();
112 bool rv = ServerInstance->Modules->Load(name.c_str());
114 ServerInstance->GlobalCulls.AddItem(this);
119 bool ModuleManager::Unload(Module* mod)
123 ServerInstance->AtomicActions.AddAction(new UnloadAction(mod));
127 void ModuleManager::Reload(Module* mod, HandlerBase1<void, bool>* callback)
130 ServerInstance->AtomicActions.AddAction(new ReloadAction(mod, callback));
132 callback->Call(false);
135 void ModuleManager::LoadAll()
138 for(std::vector<AllModuleList*>::iterator i = modlist->begin(); i != modlist->end(); ++i)
144 c->ModuleSourceFile = (**i).name;
145 c->ModuleDLLManager = NULL;
146 Modules[(**i).name] = c;
149 catch (CoreException& modexcept)
154 ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason());
158 /* We give every module a chance to re-prioritize when we introduce a new one,
159 * not just the one thats loading, as the new module could affect the preference
162 for(int tries = 0; tries < 20; tries++)
164 prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST;
165 for (std::map<std::string, Module*>::iterator n = Modules.begin(); n != Modules.end(); ++n)
166 n->second->Prioritize();
168 if (prioritizationState == PRIO_STATE_LAST)
171 ServerInstance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected");
174 ServerInstance->BuildISupport();
177 void ModuleManager::UnloadAll()