X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodmanager_static.cpp;h=d9ee07a257a7190754c299a76e4986b9da42da6e;hb=9d4004e8d477232c143830508a7a6e41fd2d31b7;hp=e09310a13bf66fde0823082094565e38540baa39;hpb=19487dbebc520450e457472b97d9e7bcd5160c00;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index e09310a13..d9ee07a25 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -58,28 +58,78 @@ class AllModule : public Module MODULE_INIT(AllModule) -bool ModuleManager::Load(const char* filename) +bool ModuleManager::Load(const char* name) { + for(std::vector::iterator i = modlist->begin(); i != modlist->end(); ++i) + { + if ((**i).name == name) + { + Module* c = NULL; + try + { + c = (*(**i).init)(); + Modules[name] = c; + c->init(); + FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); + return true; + } + catch (CoreException& modexcept) + { + if (c) + DoSafeUnload(c); + delete c; + ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); + } + } + } return false; } -bool ModuleManager::CanUnload(Module* mod) -{ - return false; -} +namespace { + struct UnloadAction : public HandlerBase0 + { + Module* const mod; + UnloadAction(Module* m) : mod(m) {} + void Call() + { + ServerInstance->Modules->DoSafeUnload(mod); + ServerInstance->GlobalCulls.Apply(); + ServerInstance->GlobalCulls.AddItem(this); + } + }; -void ModuleManager::DoSafeUnload(Module* mod) -{ + struct ReloadAction : public HandlerBase0 + { + Module* const mod; + HandlerBase1* const callback; + ReloadAction(Module* m, HandlerBase1* c) + : mod(m), callback(c) {} + void Call() + { + std::string name = mod->ModuleSourceFile; + ServerInstance->Modules->DoSafeUnload(mod); + ServerInstance->GlobalCulls.Apply(); + bool rv = ServerInstance->Modules->Load(name.c_str()); + callback->Call(rv); + ServerInstance->GlobalCulls.AddItem(this); + } + }; } bool ModuleManager::Unload(Module* mod) { - return false; + if (!CanUnload(mod)) + return false; + ServerInstance->AtomicActions.AddAction(new UnloadAction(mod)); + return true; } void ModuleManager::Reload(Module* mod, HandlerBase1* callback) { - callback->Call(false); + if (CanUnload(mod)) + ServerInstance->AtomicActions.AddAction(new ReloadAction(mod, callback)); + else + callback->Call(false); } void ModuleManager::LoadAll() @@ -87,15 +137,21 @@ void ModuleManager::LoadAll() ModCount = 0; for(std::vector::iterator i = modlist->begin(); i != modlist->end(); ++i) { + Module* c = NULL; try { - Module* c = (*(**i).init)(); + c = (*(**i).init)(); c->ModuleSourceFile = (**i).name; + c->ModuleDLLManager = NULL; Modules[(**i).name] = c; + c->init(); FOREACH_MOD(I_OnLoadModule,OnLoadModule(c)); } catch (CoreException& modexcept) { + if (c) + DoSafeUnload(c); + delete c; ServerInstance->Logs->Log("MODULE", DEFAULT, "Unable to load " + (**i).name + ": " + modexcept.GetReason()); } }