diff options
author | Adam <Adam@anope.org> | 2010-08-22 00:34:02 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-08-22 00:34:02 -0400 |
commit | ada65a3bafd3ae6738a80972cf0d2f31ad19a7ae (patch) | |
tree | afde8d7594adc78beec8feb8090f4a990bd6a56b /src | |
parent | 8a4c6ae618f767d2a9335da40f507ddccfc77b4b (diff) |
Added a classbase for the major classes, makes dynamic_reference invalidation really work.
This also cleans up a bit of the code in the modestacker.
Diffstat (limited to 'src')
-rw-r--r-- | src/base.cpp | 25 | ||||
-rw-r--r-- | src/modes.cpp | 114 | ||||
-rw-r--r-- | src/module.cpp | 12 | ||||
-rw-r--r-- | src/modulemanager.cpp | 1 | ||||
-rw-r--r-- | src/modules.cpp | 13 |
5 files changed, 52 insertions, 113 deletions
diff --git a/src/base.cpp b/src/base.cpp new file mode 100644 index 000000000..0aec072a1 --- /dev/null +++ b/src/base.cpp @@ -0,0 +1,25 @@ +#include "services.h" +#include "modules.h" + +Base::Base() +{ +} + +Base::~Base() +{ + for (std::set<dynamic_reference_base *>::iterator it = this->References.begin(), it_end = this->References.end(); it != it_end; ++it) + { + (*it)->Invalidate(); + } +} + +void Base::AddReference(dynamic_reference_base *r) +{ + this->References.insert(r); +} + +void Base::DelReference(dynamic_reference_base *r) +{ + this->References.erase(r); +} + diff --git a/src/modes.cpp b/src/modes.cpp index ce34e461c..6c060aed8 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -10,7 +10,7 @@ #include "modules.h" /* List of pairs of user/channels and their stacker info */ -std::list<std::pair<void *, StackerInfo *> > ModeManager::StackerObjects; +std::list<std::pair<Base *, StackerInfo *> > ModeManager::StackerObjects; /* List of all modes Anope knows about */ std::map<Anope::string, Mode *> ModeManager::Modes; @@ -420,7 +420,7 @@ void ChannelModeInvex::DelMask(Channel *chan, const Anope::string &mask) } } -void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param) +void StackerInfo::AddMode(Base *Mode, bool Set, const Anope::string &Param) { ChannelMode *cm = NULL; UserMode *um = NULL; @@ -428,17 +428,17 @@ void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param) if (Type == ST_CHANNEL) { - cm = static_cast<ChannelMode *>(Mode); + cm = debug_cast<ChannelMode *>(Mode); if (cm->Type == MODE_PARAM) IsParam = true; } else if (Type == ST_USER) { - um = static_cast<UserMode *>(Mode); + um = debug_cast<UserMode *>(Mode); if (um->Type == MODE_PARAM) IsParam = true; } - std::list<std::pair<void *, Anope::string> > *list, *otherlist; + std::list<std::pair<Base *, Anope::string> > *list, *otherlist; if (Set) { list = &AddModes; @@ -451,7 +451,7 @@ void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param) } /* Loop through the list and find if this mode is already on here */ - std::list<std::pair<void *, Anope::string > >::iterator it, it_end; + std::list<std::pair<Base *, Anope::string > >::iterator it, it_end; for (it = list->begin(), it_end = list->end(); it != it_end; ++it) { /* The param must match too (can have multiple status or list modes), but @@ -489,11 +489,11 @@ void StackerInfo::AddMode(void *Mode, bool Set, const Anope::string &Param) * @param Item The user/channel etc * @return The stacker info */ -StackerInfo *ModeManager::GetInfo(void *Item) +StackerInfo *ModeManager::GetInfo(Base *Item) { - for (std::list<std::pair<void *, StackerInfo *> >::const_iterator it = StackerObjects.begin(), it_end = StackerObjects.end(); it != it_end; ++it) + for (std::list<std::pair<Base *, StackerInfo *> >::const_iterator it = StackerObjects.begin(), it_end = StackerObjects.end(); it != it_end; ++it) { - const std::pair<void *, StackerInfo *> &PItem = *it; + const std::pair<Base *, StackerInfo *> &PItem = *it; if (PItem.first == Item) return PItem.second; } @@ -510,7 +510,7 @@ StackerInfo *ModeManager::GetInfo(void *Item) std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info) { std::list<Anope::string> ret; - std::list<std::pair<void *, Anope::string> >::iterator it, it_end; + std::list<std::pair<Base *, Anope::string> >::iterator it, it_end; Anope::string buf = "+", parambuf; ChannelMode *cm = NULL; UserMode *um = NULL; @@ -528,12 +528,12 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info) if (info->Type == ST_CHANNEL) { - cm = static_cast<ChannelMode *>(it->first); + cm = debug_cast<ChannelMode *>(it->first); buf += cm->ModeChar; } else if (info->Type == ST_USER) { - um = static_cast<UserMode *>(it->first); + um = debug_cast<UserMode *>(it->first); buf += um->ModeChar; } @@ -557,12 +557,12 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info) if (info->Type == ST_CHANNEL) { - cm = static_cast<ChannelMode *>(it->first); + cm = debug_cast<ChannelMode *>(it->first); buf += cm->ModeChar; } else if (info->Type == ST_USER) { - um = static_cast<UserMode *>(it->first); + um = debug_cast<UserMode *>(it->first); buf += um->ModeChar; } @@ -579,30 +579,6 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info) return ret; } -/** Add a mode to the stacker, internal use only - * @param bi The client to set the modes from - * @param u The user - * @param um The user mode - * @param Set Adding or removing? - * @param Param A param, if there is one - */ -void ModeManager::StackerAddInternal(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) -{ - StackerAddInternal(bi, u, um, Set, Param, ST_USER); -} - -/** Add a mode to the stacker, internal use only - * @param bi The client to set the modes from - * @param c The channel - * @param cm The channel mode - * @param Set Adding or removing? - * @param Param A param, if there is one - */ -void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) -{ - StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL); -} - /** Really add a mode to the stacker, internal use only * @param bi The client to set the modes from * @param Object The object, user/channel @@ -611,7 +587,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, Channel *c, ChannelMode *cm, b * @param Param A param, if there is one * @param Type The type this is, user or channel */ -void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool Set, const Anope::string &Param, StackerType Type) +void ModeManager::StackerAddInternal(BotInfo *bi, Base *Object, Base *Mode, bool Set, const Anope::string &Param, StackerType Type) { StackerInfo *s = GetInfo(Object); s->Type = Type; @@ -619,7 +595,7 @@ void ModeManager::StackerAddInternal(BotInfo *bi, void *Object, void *Mode, bool if (bi) s->bi = bi; else if (Type == ST_CHANNEL) - s->bi = whosends(static_cast<Channel *>(Object)->ci); + s->bi = whosends(debug_cast<Channel *>(Object)->ci); else if (Type == ST_USER) s->bi = NULL; } @@ -778,31 +754,7 @@ char ModeManager::GetStatusChar(char Value) */ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { - StackerAddInternal(bi, c, cm, Set, Param); -} - -/** Add a mode to the stacker to be set on a channel - * @param bi The client to set the modes from - * @param c The channel - * @param Name The channel mode name - * @param Set true for setting, false for removing - * @param Param The param, if there is one - */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelModeName Name, bool Set, const Anope::string &Param) -{ - StackerAdd(bi, c, FindChannelModeByName(Name), Set, Param); -} - -/** Add a mode to the stacker to be set on a channel - * @param bi The client to set the modes from - * @param c The channel - * @param Mode The mode char - * @param Set true for setting, false for removing - * @param Param The param, if there is one - */ -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, const Anope::string &Param) -{ - StackerAdd(bi, c, FindChannelModeByChar(Mode), Set, Param); + StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL); } /** Add a mode to the stacker to be set on a user @@ -814,31 +766,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, const char Mode, bool Set, */ void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { - StackerAddInternal(bi, u, um, Set, Param); -} - -/** Add a mode to the stacker to be set on a user - * @param bi The client to set the modes from - * @param u The user - * @param Name The user mode name - * @param Set true for setting, false for removing - * @param Param The param, if there is one - */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserModeName Name, bool Set, const Anope::string &Param) -{ - StackerAdd(bi, u, FindUserModeByName(Name), Set, Param); -} - -/** Add a mode to the stacker to be set on a user - * @param bi The client to set the modes from - * @param u The user - * @param Mode The mode to be set - * @param Set true for setting, false for removing - * @param Param The param, if there is one - */ -void ModeManager::StackerAdd(BotInfo *bi, User *u, const char Mode, bool Set, const Anope::string &Param) -{ - StackerAdd(bi, u, FindUserModeByChar(Mode), Set, Param); + StackerAddInternal(bi, u, um, Set, Param, ST_USER); } /** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users @@ -847,16 +775,16 @@ void ModeManager::ProcessModes() { if (!StackerObjects.empty()) { - for (std::list<std::pair<void *, StackerInfo *> >::const_iterator it = StackerObjects.begin(), it_end = StackerObjects.end(); it != it_end; ++it) + for (std::list<std::pair<Base *, StackerInfo *> >::const_iterator it = StackerObjects.begin(), it_end = StackerObjects.end(); it != it_end; ++it) { StackerInfo *s = it->second; User *u = NULL; Channel *c = NULL; if (s->Type == ST_USER) - u = static_cast<User *>(it->first); + u = debug_cast<User *>(it->first); else if (s->Type == ST_CHANNEL) - c = static_cast<Channel *>(it->first); + c = debug_cast<Channel *>(it->first); else throw CoreException("ModeManager::ProcessModes got invalid Stacker Info type"); diff --git a/src/module.cpp b/src/module.cpp index 9431137b7..98eb9b4fd 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -37,6 +37,8 @@ Module::~Module() for (i = 0; i < NUM_LANGS; ++i) this->DeleteLanguage(i); + /* Detach all event hooks for this module */ + ModuleManager::DetachAll(this); /* Clear any active callbacks this module has */ ModuleManager::ClearCallBacks(this); @@ -93,13 +95,3 @@ unsigned Version::GetBuild() const return this->Build; } -Service::Service(Module *o, const Anope::string &n) : owner(o), name(n) -{ - ModuleManager::RegisterService(this); -} - -Service::~Service() -{ - ModuleManager::UnregisterService(this); -} - diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index f539f273d..49b90ca41 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -249,7 +249,6 @@ void ModuleManager::DeleteModule(Module *m) if (!m || !m->handle) return; - DetachAll(m); ano_module_t handle = m->handle; Anope::string filename = m->filename; diff --git a/src/modules.cpp b/src/modules.cpp index 0a7d813c5..8f9b6b944 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -382,18 +382,13 @@ Version Module::GetVersion() const return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); } -std::list<dynamic_reference_base *> dyn_references; - -dynamic_reference_base::dynamic_reference_base() +Service::Service(Module *o, const Anope::string &n) : owner(o), name(n) { - dyn_references.push_back(this); + ModuleManager::RegisterService(this); } -dynamic_reference_base::~dynamic_reference_base() +Service::~Service() { - std::list<dynamic_reference_base *>::iterator it = std::find(dyn_references.begin(), dyn_references.end(), this); - - if (it != dyn_references.end()) - dyn_references.erase(it); + ModuleManager::UnregisterService(this); } |