diff options
author | Adam <Adam@anope.org> | 2013-03-30 23:38:40 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-03-30 23:39:43 -0500 |
commit | 7e7556f06445d4d8e607ef514c9fb5009899db73 (patch) | |
tree | fde8e4e7c59f40183e215cd69ce0d042670b24b9 /src | |
parent | 111d6a917806fd3ce2269436d08d68bd7eb1d5ea (diff) |
Merge usefulness of Timer and CallBack classes into Timer, and fix it to really work
Diffstat (limited to 'src')
-rw-r--r-- | src/module.cpp | 15 | ||||
-rw-r--r-- | src/modulemanager.cpp | 6 | ||||
-rw-r--r-- | src/timers.cpp | 28 |
3 files changed, 30 insertions, 19 deletions
diff --git a/src/module.cpp b/src/module.cpp index 4b13d7e94..91a7ed350 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -57,9 +57,9 @@ Module::~Module() { /* Detach all event hooks for this module */ ModuleManager::DetachAll(this); - /* Clear any active callbacks this module has */ - ModuleManager::ClearCallBacks(this); IdentifyRequest::ModuleUnload(this); + /* Clear any active timers this module has */ + TimerManager::DeleteTimersFor(this); std::list<Module *>::iterator it = std::find(ModuleManager::Modules.begin(), ModuleManager::Modules.end(), this); if (it != ModuleManager::Modules.end()) @@ -111,14 +111,3 @@ int ModuleVersion::GetPatch() const return this->version_patch; } -CallBack::CallBack(Module *mod, long time_from_now, time_t now, bool repeating) : Timer(time_from_now, now, repeating), m(mod) -{ -} - -CallBack::~CallBack() -{ - std::list<CallBack *>::iterator it = std::find(m->callbacks.begin(), m->callbacks.end(), this); - if (it != m->callbacks.end()) - m->callbacks.erase(it); -} - diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 6c54058b7..823fda868 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -449,12 +449,6 @@ bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Modul return true; } -void ModuleManager::ClearCallBacks(Module *m) -{ - while (!m->callbacks.empty()) - delete m->callbacks.front(); -} - void ModuleManager::UnloadAll() { std::vector<Anope::string> modules[MT_END]; diff --git a/src/timers.cpp b/src/timers.cpp index 94a6fbb3d..827d81df7 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -14,6 +14,18 @@ std::multimap<time_t, Timer *> TimerManager::Timers; Timer::Timer(long time_from_now, time_t now, bool repeating) { + owner = NULL; + trigger = now + time_from_now; + secs = time_from_now; + repeat = repeating; + settime = now; + + TimerManager::AddTimer(this); +} + +Timer::Timer(Module *creator, long time_from_now, time_t now, bool repeating) +{ + owner = creator; trigger = now + time_from_now; secs = time_from_now; repeat = repeating; @@ -62,6 +74,11 @@ long Timer::GetSecs() const return secs; } +Module *Timer::GetOwner() const +{ + return owner; +} + void TimerManager::AddTimer(Timer *t) { Timers.insert(std::make_pair(t->GetTimer(), t)); @@ -98,3 +115,14 @@ void TimerManager::TickTimers(time_t ctime) delete t; } } + +void TimerManager::DeleteTimersFor(Module *m) +{ + for (std::multimap<time_t, Timer *>::iterator it = Timers.begin(), it_next = it; it != Timers.end(); it = it_next) + { + ++it_next; + if (it->second->GetOwner() == m) + delete it->second; + } +} + |