diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-10 22:17:51 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-10 22:17:51 +0000 |
commit | 540fee57bf71abccaba38c0297b80f8001780c1d (patch) | |
tree | 0a02c41f92100925e5f6a3db709372322389517e /src/modules.cpp | |
parent | 5c0c0ec057e1f1bc9dd837c1654927b5b534e5c0 (diff) |
Add InspIRCd::UseInterface and InspIRCd::DoneWithInterface, and also InspIRCd::GetInterfaceUseCount().
These can be used for one module to lock other modules in memory that it depends on, this way they can
enforce an unload order so that you cant (for example) unload m_ssl_gnutls.so whilst m_spanningtree.so
is using it for ssl server to server sessions (in this case, youd have to unload spanningtree first,
THEN ssl_gnutls, to satisfy the dependencies and unload orders)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5924 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules.cpp')
-rw-r--r-- | src/modules.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/modules.cpp b/src/modules.cpp index 4ae033c8b..b670291ec 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -258,12 +258,12 @@ bool InspIRCd::PublishInterface(const std::string &InterfaceName, Module* Mod) { modulelist ml; ml.push_back(Mod); - Interfaces[InterfaceName] = ml; + Interfaces[InterfaceName] = std::make_pair(0, ml); return true; } else { - iter->second.push_back(Mod); + iter->second.second.push_back(Mod); return true; } return false; @@ -276,12 +276,12 @@ bool InspIRCd::UnpublishInterface(const std::string &InterfaceName, Module* Mod) if (iter == Interfaces.end()) return false; - for (modulelist::iterator x = iter->second.begin(); x != iter->second.end(); x++) + for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++) { if (*x == Mod) { - iter->second.erase(x); - if (iter->second.empty()) + iter->second.second.erase(x); + if (iter->second.second.empty()) Interfaces.erase(InterfaceName); return true; } @@ -295,7 +295,37 @@ modulelist* InspIRCd::FindInterface(const std::string &InterfaceName) if (iter == Interfaces.end()) return NULL; else - return &(iter->second); + return &(iter->second.second); +} + +void InspIRCd::UseInterface(const std::string &InterfaceName) +{ + interfacelist::iterator iter = Interfaces.find(InterfaceName); + if (iter != Interfaces.end()) + iter->second.first++; + +} + +void InspIRCd::DoneWithInterface(const std::string &InterfaceName) +{ + interfacelist::iterator iter = Interfaces.find(InterfaceName); + if (iter != Interfaces.end()) + iter->second.first--; +} + +std::pair<int,std::string> InspIRCd::GetInterfaceInstanceCount(Module* m) +{ + for (interfacelist::iterator iter = Interfaces.begin(); iter != Interfaces.end(); iter++) + { + for (modulelist::iterator x = iter->second.second.begin(); x != iter->second.second.end(); x++) + { + if (*x == m) + { + return std::make_pair(iter->second.first, iter->first); + } + } + } + return std::make_pair(0, ""); } const std::string& InspIRCd::GetModuleName(Module* m) |