diff options
-rw-r--r-- | include/modules.h | 11 | ||||
-rw-r--r-- | src/modules.cpp | 30 |
2 files changed, 32 insertions, 9 deletions
diff --git a/include/modules.h b/include/modules.h index c938e6a9d..378aec1ee 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1215,6 +1215,17 @@ class CoreExport ModuleManager : public fakederef<ModuleManager> * @return A ModuleMap containing all loaded modules */ const ModuleMap& GetModules() const { return Modules; } + + /** Make a service referenceable by dynamic_references + * @param name Name that will be used by dynamic_references to find the object + * @param service Service to make referenceable by dynamic_references + */ + void AddReferent(const std::string& name, ServiceProvider* service); + + /** Make a service no longer referenceable by dynamic_references + * @param service Service to make no longer referenceable by dynamic_references + */ + void DelReferent(ServiceProvider* service); }; /** Do not mess with these functions unless you know the C preprocessor diff --git a/src/modules.cpp b/src/modules.cpp index 9e653a4ab..0223d12f1 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -564,8 +564,7 @@ void ModuleManager::AddService(ServiceProvider& item) { ModeHandler* mh = static_cast<ModeHandler*>(&item); ServerInstance->Modes->AddMode(mh); - DataProviders.insert(std::make_pair((mh->GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + item.name, &item)); - dynamic_reference_base::reset_all(); + AddReferent((mh->GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + item.name, &item); return; } case SERVICE_METADATA: @@ -604,13 +603,7 @@ void ModuleManager::DelService(ServiceProvider& item) case SERVICE_DATA: case SERVICE_IOHOOK: { - for(std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); ) - { - std::multimap<std::string, ServiceProvider*>::iterator curr = i++; - if (curr->second == &item) - DataProviders.erase(curr); - } - dynamic_reference_base::reset_all(); + DelReferent(&item); return; } default: @@ -702,3 +695,22 @@ Module* ModuleManager::Find(const std::string &name) else return modfind->second; } + +void ModuleManager::AddReferent(const std::string& name, ServiceProvider* service) +{ + DataProviders.insert(std::make_pair(name, service)); + dynamic_reference_base::reset_all(); +} + +void ModuleManager::DelReferent(ServiceProvider* service) +{ + for (std::multimap<std::string, ServiceProvider*>::iterator i = DataProviders.begin(); i != DataProviders.end(); ) + { + ServiceProvider* curr = i->second; + if (curr == service) + DataProviders.erase(i++); + else + ++i; + } + dynamic_reference_base::reset_all(); +} |