diff options
author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-02-25 06:20:00 +0000 |
---|---|---|
committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-02-25 06:20:00 +0000 |
commit | 235c4ae95c1cf467ec47514c2226df675494c12c (patch) | |
tree | 68fac6b16edd8e0024a7edb9ca1294d59bd62bd3 /src | |
parent | 54a60add71fc584765b8e575fdc699e93ec2ba84 (diff) |
Rewrote part of the Timer and CallBack code for modules to be sane
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2795 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
-rw-r--r-- | src/core/os_defcon.c | 2 | ||||
-rw-r--r-- | src/module.cpp | 4 | ||||
-rw-r--r-- | src/modulemanager.cpp | 14 | ||||
-rw-r--r-- | src/modules.c | 42 | ||||
-rw-r--r-- | src/modules/cs_tban.c | 6 | ||||
-rw-r--r-- | src/nickserv.c | 14 | ||||
-rw-r--r-- | src/timers.cpp | 28 |
7 files changed, 19 insertions, 91 deletions
diff --git a/src/core/os_defcon.c b/src/core/os_defcon.c index c06cf8c62..a3c4c46fa 100644 --- a/src/core/os_defcon.c +++ b/src/core/os_defcon.c @@ -86,7 +86,7 @@ class CommandOSDEFCON : public Command if (timeout) { - TimerManager::DelTimer(timeout); + delete timeout; timeout = NULL; } diff --git a/src/module.cpp b/src/module.cpp index fa4e41cd8..6aebd8644 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -66,8 +66,8 @@ Module::~Module() Command *c; - /* Kill any active timers this module has */ - ModuleManager::ClearTimers(this); + /* Clear any active callbacks this module has */ + ModuleManager::ClearCallBacks(this); /** * ok, im going to walk every hash looking for commands we own, now, not exactly elegant or efficiant :) diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 90c76319c..0716e4503 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -467,16 +467,12 @@ bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Modul return true; } -/** Delete all timers attached to a module +/** Delete all callbacks attached to a module * @param m The module */ -void ModuleManager::ClearTimers(Module *m) +void ModuleManager::ClearCallBacks(Module *m) { - std::list<Timer *>::iterator it; - - for (it = m->CallBacks.begin(); it != m->CallBacks.end(); ++it) - { - TimerManager::DelTimer(*it); - } - m->CallBacks.clear(); + while (!m->CallBacks.empty()) + delete m->CallBacks.front(); } + diff --git a/src/modules.c b/src/modules.c index 3bc2e490f..d3453efad 100644 --- a/src/modules.c +++ b/src/modules.c @@ -596,48 +596,6 @@ int destroyMessage(Message * m) * Module Callback Functions *******************************************************************************/ -/** - * Adds a timer to the current module - * The timer handling will take care of everything for this timer, this is only here - * so we have a list of timers to destroy when this module is unloaded - * @param t A timer derived class - */ -void Module::AddCallBack(Timer *t) -{ - /* Remove no longer valid Timers from the modules internal list */ - std::list<Timer *>::iterator it, it2; - for (it = this->CallBacks.begin(); it != this->CallBacks.end(); it = it2) - { - it2 = it; - ++it2; - - if (!TimerManager::IsTimer(*it)) - { - this->CallBacks.erase(it); - } - } - - this->CallBacks.push_back(t); -} - -/** - * Deletes a timer for the current module - * @param t The timer - */ -bool Module::DelCallBack(Timer *t) -{ - std::list<Timer *>::iterator it = std::find(this->CallBacks.begin(), this->CallBacks.end(), t); - - if (it != this->CallBacks.end()) - { - TimerManager::DelTimer(*it); - this->CallBacks.erase(it); - return true; - } - - return false; -} - /* Check the current version of anope against a given version number * Specifiying -1 for minor,patch or build * @param major The major version of anope, the first part of the verison number diff --git a/src/modules/cs_tban.c b/src/modules/cs_tban.c index 07f7f6c0f..46c678522 100644 --- a/src/modules/cs_tban.c +++ b/src/modules/cs_tban.c @@ -168,14 +168,14 @@ void mySendResponse(User *u, const char *channel, char *mask, const char *time) me->NoticeLang(Config.s_ChanServ, u, TBAN_RESPONSE, mask, channel, time); } -class TempBan : public Timer +class TempBan : public CallBack { private: std::string chan; std::string mask; public: - TempBan(time_t seconds, const std::string &channel, const std::string &banmask) : Timer(seconds), chan(channel), mask(banmask) { } + TempBan(time_t seconds, const std::string &channel, const std::string &banmask) : CallBack(me, seconds), chan(channel), mask(banmask) { } void Tick(time_t ctime) { @@ -192,7 +192,7 @@ void addBan(Channel *c, time_t timeout, char *banmask) { c->SetMode(NULL, CMODE_BAN, banmask); - me->AddCallBack(new TempBan(timeout, c->name, banmask)); + new TempBan(timeout, c->name, banmask); } int canBanUser(Channel * c, User * u, User * u2) diff --git a/src/nickserv.c b/src/nickserv.c index a0994e07d..3fe43fde1 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -40,7 +40,7 @@ NickServCollide::NickServCollide(NickAlias *nickalias, time_t delay) : Timer(del std::map<NickAlias *, NickServCollide *>::iterator nit = NickServCollides.find(nickalias); if (nit != NickServCollides.end()) { - TimerManager::DelTimer(nit->second); + delete nit->second; } it = NickServCollides.insert(std::make_pair(nickalias, this)); @@ -70,13 +70,10 @@ void NickServCollide::Tick(time_t ctime) void NickServCollide::ClearTimers(NickAlias *na) { std::map<NickAlias *, NickServCollide *>::iterator i = NickServCollides.find(na); - NickServCollide *t; if (i != NickServCollides.end()) { - t = i->second; - - TimerManager::DelTimer(t); + delete i->second; } } @@ -86,7 +83,7 @@ NickServRelease::NickServRelease(NickAlias *nickalias, time_t delay) : Timer(del std::map<NickAlias *, NickServRelease *>::iterator nit = NickServReleases.find(nickalias); if (nit != NickServReleases.end()) { - TimerManager::DelTimer(nit->second); + delete nit->second; } it = NickServReleases.insert(std::make_pair(nickalias, this)); @@ -119,16 +116,13 @@ void NickServRelease::Tick(time_t ctime) void NickServRelease::ClearTimers(NickAlias *na, bool dorelease) { std::map<NickAlias *, NickServRelease *>::iterator i = NickServReleases.find(na); - NickServRelease *t; if (i != NickServReleases.end()) { - t = i->second; - if (dorelease) release(na, 1); - TimerManager::DelTimer(t); + delete i->second; } } diff --git a/src/timers.cpp b/src/timers.cpp index be4289a7c..cd7dbd1fd 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -34,6 +34,7 @@ Timer::Timer(long time_from_now, time_t now, bool repeating) */ Timer::~Timer() { + TimerManager::DelTimer(this); } /** Set the trigger time to a new value @@ -94,39 +95,18 @@ void TimerManager::DelTimer(Timer *T) if (i != Timers.end()) { - delete (*i); Timers.erase(i); } } -/** Check if something is a timer - * @param T A pointer - * @return true or false - */ -bool TimerManager::IsTimer(Timer *T) -{ - std::vector<Timer *>::iterator i = std::find(Timers.begin(), Timers.end(), T); - - if (i != Timers.end()) - { - return true; - } - - return false; -} - /** Tick all pending timers * @param ctime The current time */ void TimerManager::TickTimers(time_t ctime) { - std::vector<Timer *>::iterator i; - Timer *t; - - while ((Timers.size()) && (ctime > (*Timers.begin())->GetTimer())) + while (Timers.size() && (ctime > Timers.front()->GetTimer())) { - i = Timers.begin(); - t = *i; + Timer *t = Timers.front(); t->Tick(ctime); @@ -136,7 +116,7 @@ void TimerManager::TickTimers(time_t ctime) sort(Timers.begin(), Timers.end(), TimerManager::TimerComparison); } else - TimerManager::DelTimer(t); + delete t; } } |