summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-03-30 23:38:40 -0500
committerAdam <Adam@anope.org>2013-03-30 23:39:43 -0500
commit7e7556f06445d4d8e607ef514c9fb5009899db73 (patch)
treefde8e4e7c59f40183e215cd69ce0d042670b24b9
parent111d6a917806fd3ce2269436d08d68bd7eb1d5ea (diff)
Merge usefulness of Timer and CallBack classes into Timer, and fix it to really work
-rw-r--r--include/modules.h22
-rw-r--r--include/timers.h21
-rw-r--r--modules/commands/bs_kick.cpp4
-rw-r--r--modules/commands/bs_set.cpp8
-rw-r--r--modules/commands/cs_ban.cpp4
-rw-r--r--modules/commands/cs_seen.cpp4
-rw-r--r--modules/commands/os_defcon.cpp4
-rw-r--r--modules/extra/m_httpd.cpp4
-rw-r--r--modules/extra/m_proxyscan.cpp4
-rw-r--r--modules/pseudoclients/chanserv.cpp4
-rw-r--r--modules/pseudoclients/nickserv.cpp4
-rw-r--r--src/module.cpp15
-rw-r--r--src/modulemanager.cpp6
-rw-r--r--src/timers.cpp28
14 files changed, 71 insertions, 61 deletions
diff --git a/include/modules.h b/include/modules.h
index 53f723898..10b9ed8aa 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -195,10 +195,6 @@ class CoreExport Module : public Extensible
*/
Anope::string filename;
- /** Callbacks used in this module
- */
- std::list<CallBack *> callbacks;
-
/** Handle for this module, obtained from dlopen()
*/
void *handle;
@@ -1126,11 +1122,6 @@ class CoreExport ModuleManager
*/
static void Attach(Implementation *i, Module *mod, size_t sz);
- /** Delete all callbacks attached to a module
- * @param m The module
- */
- static void ClearCallBacks(Module *m);
-
/** Unloading all modules except the protocol module.
*/
static void UnloadAll();
@@ -1143,17 +1134,4 @@ class CoreExport ModuleManager
static ModuleReturn DeleteModule(Module *m);
};
-/** Class used for callbacks within modules. These are identical to Timers hwoever
- * they will be cleaned up automatically when a module is unloaded, and Timers will not.
- */
-class CoreExport CallBack : public Timer
-{
- private:
- Module *m;
- public:
- CallBack(Module *mod, long time_from_now, time_t now = Anope::CurTime, bool repeating = false);
-
- virtual ~CallBack();
-};
-
#endif // MODULES_H
diff --git a/include/timers.h b/include/timers.h
index 229333596..a0b04efa2 100644
--- a/include/timers.h
+++ b/include/timers.h
@@ -18,6 +18,10 @@
class CoreExport Timer
{
private:
+ /** The owner of the timer, if any
+ */
+ Module *owner;
+
/** The time this was created
*/
time_t settime;
@@ -42,6 +46,14 @@ class CoreExport Timer
*/
Timer(long time_from_now, time_t now = Anope::CurTime, bool repeating = false);
+ /** Constructor, initializes the triggering time
+ * @param creator The creator of the timer
+ * @param time_from_now The number of seconds from now to trigger the timer
+ * @param now The time now
+ * @param repeating Repeat this timer every time_from_now if this is true
+ */
+ Timer(Module *creator, long time_from_now, time_t now = Anope::CurTime, bool repeating = false);
+
/** Destructor, removes the timer from the list
*/
virtual ~Timer();
@@ -76,6 +88,11 @@ class CoreExport Timer
*/
time_t GetSetTime() const;
+ /** Returns the owner of this timer, if any
+ * @return The owner of the timer
+ */
+ Module *GetOwner() const;
+
/** Called when the timer ticks
* This should be overridden with something useful
*/
@@ -106,6 +123,10 @@ class CoreExport TimerManager
* @param ctime The current time
*/
static void TickTimers(time_t ctime = Anope::CurTime);
+
+ /** Deletes all timers owned by the given module
+ */
+ static void DeleteTimersFor(Module *m);
};
#endif // TIMERS_H
diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp
index 252220d09..3f7cc16c2 100644
--- a/modules/commands/bs_kick.cpp
+++ b/modules/commands/bs_kick.cpp
@@ -680,10 +680,10 @@ struct UserData : ExtensibleItem
};
-class BanDataPurger : public CallBack
+class BanDataPurger : public Timer
{
public:
- BanDataPurger(Module *owner) : CallBack(owner, 300, Anope::CurTime, true) { }
+ BanDataPurger(Module *o) : Timer(o, 300, Anope::CurTime, true) { }
void Tick(time_t) anope_override
{
diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp
index 41c84bf87..5aa8a77ec 100644
--- a/modules/commands/bs_set.cpp
+++ b/modules/commands/bs_set.cpp
@@ -57,15 +57,15 @@ class CommandBSSet : public Command
class CommandBSSetBanExpire : public Command
{
public:
- class Timer : public CallBack
+ class UnbanTimer : public Timer
{
Anope::string chname;
Anope::string mask;
public:
- Timer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : CallBack(creator, t), chname(ch), mask(bmask) { }
+ UnbanTimer(Module *creator, const Anope::string &ch, const Anope::string &bmask, time_t t) : Timer(creator, t), chname(ch), mask(bmask) { }
- void Tick(time_t)
+ void Tick(time_t) anope_override
{
Channel *c = Channel::Find(chname);
if (c)
@@ -504,7 +504,7 @@ class BSSet : public Module
if (!ci->banexpire)
return;
- new CommandBSSetBanExpire::Timer(this, ci->name, mask, ci->banexpire);
+ new CommandBSSetBanExpire::UnbanTimer(this, ci->name, mask, ci->banexpire);
}
};
diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp
index c39f7f392..52c372fb4 100644
--- a/modules/commands/cs_ban.cpp
+++ b/modules/commands/cs_ban.cpp
@@ -15,14 +15,14 @@
static Module *me;
-class TempBan : public CallBack
+class TempBan : public Timer
{
private:
Anope::string channel;
Anope::string mask;
public:
- TempBan(time_t seconds, Channel *c, const Anope::string &banmask) : CallBack(me, seconds), channel(c->name), mask(banmask) { }
+ TempBan(time_t seconds, Channel *c, const Anope::string &banmask) : Timer(me, seconds), channel(c->name), mask(banmask) { }
void Tick(time_t ctime) anope_override
{
diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp
index cd12695aa..10c23dd53 100644
--- a/modules/commands/cs_seen.cpp
+++ b/modules/commands/cs_seen.cpp
@@ -293,10 +293,10 @@ class CommandSeen : public Command
}
};
-class DataBasePurger : public CallBack
+class DataBasePurger : public Timer
{
public:
- DataBasePurger(Module *owner) : CallBack(owner, 300, Anope::CurTime, true) { }
+ DataBasePurger(Module *o) : Timer(o, 300, Anope::CurTime, true) { }
void Tick(time_t) anope_override
{
diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp
index fe2ecc99f..214c14f2a 100644
--- a/modules/commands/os_defcon.cpp
+++ b/modules/commands/os_defcon.cpp
@@ -104,12 +104,12 @@ static ServiceReference<GlobalService> GlobalService("GlobalService", "Global");
static Timer *timeout;
-class DefConTimeout : public CallBack
+class DefConTimeout : public Timer
{
int level;
public:
- DefConTimeout(Module *mod, int newlevel) : CallBack(mod, DConfig.timeout), level(newlevel)
+ DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel)
{
timeout = this;
}
diff --git a/modules/extra/m_httpd.cpp b/modules/extra/m_httpd.cpp
index d9855a226..f1e5392c5 100644
--- a/modules/extra/m_httpd.cpp
+++ b/modules/extra/m_httpd.cpp
@@ -279,14 +279,14 @@ class MyHTTPClient : public HTTPClient
}
};
-class MyHTTPProvider : public HTTPProvider, public CallBack
+class MyHTTPProvider : public HTTPProvider, public Timer
{
int timeout;
std::map<Anope::string, HTTPPage *> pages;
std::list<Reference<MyHTTPClient> > clients;
public:
- MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p), CallBack(c, 10, Anope::CurTime, true), timeout(t) { }
+ MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t) : Socket(-1, i.find(':') != Anope::string::npos), HTTPProvider(c, n, i, p), Timer(c, 10, Anope::CurTime, true), timeout(t) { }
void Tick(time_t) anope_override
{
diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp
index feac20969..b77da2d3d 100644
--- a/modules/extra/m_proxyscan.cpp
+++ b/modules/extra/m_proxyscan.cpp
@@ -201,10 +201,10 @@ class ModuleProxyScan : public Module
ProxyCallbackListener *listener;
- class ConnectionTimeout : public CallBack
+ class ConnectionTimeout : public Timer
{
public:
- ConnectionTimeout(Module *creator, long timeout) : CallBack(creator, timeout, Anope::CurTime, true)
+ ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true)
{
}
diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp
index 9832c622e..7b59c0597 100644
--- a/modules/pseudoclients/chanserv.cpp
+++ b/modules/pseudoclients/chanserv.cpp
@@ -13,10 +13,10 @@
#include "module.h"
-class ExpireCallback : public CallBack
+class ExpireCallback : public Timer
{
public:
- ExpireCallback(Module *owner) : CallBack(owner, Config->ExpireTimeout, Anope::CurTime, true) { }
+ ExpireCallback(Module *o) : Timer(o, Config->ExpireTimeout, Anope::CurTime, true) { }
void Tick(time_t) anope_override
{
diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp
index 7b1ccd80c..e221c19c0 100644
--- a/modules/pseudoclients/nickserv.cpp
+++ b/modules/pseudoclients/nickserv.cpp
@@ -139,10 +139,10 @@ class MyNickServService : public NickServService
}
};
-class ExpireCallback : public CallBack
+class ExpireCallback : public Timer
{
public:
- ExpireCallback(Module *owner) : CallBack(owner, Config->ExpireTimeout, Anope::CurTime, true) { }
+ ExpireCallback(Module *o) : Timer(o, Config->ExpireTimeout, Anope::CurTime, true) { }
void Tick(time_t) anope_override
{
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;
+ }
+}
+