From 235c4ae95c1cf467ec47514c2226df675494c12c Mon Sep 17 00:00:00 2001 From: Adam- Date: Thu, 25 Feb 2010 06:20:00 +0000 Subject: 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 --- include/modules.h | 47 ++++++++++++++++++++++++++++------------------- include/timers.h | 6 ------ 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/modules.h b/include/modules.h index cc42f4abc..4c5c4cf6b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -311,6 +311,9 @@ class Version const unsigned GetBuild(); }; +/* Forward declaration of CallBack class for the Module class */ +class CallBack; + /** Every module in Anope is actually a class. */ class CoreExport Module @@ -326,9 +329,9 @@ class CoreExport Module */ std::string filename; - /** Timers used in this module + /** Callbacks used in this module */ - std::list CallBacks; + std::list CallBacks; ano_module_t handle; time_t created; @@ -432,20 +435,6 @@ class CoreExport Module */ int DelCommand(CommandHash * cmdTable[], const char *name); - /** - * 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 AddCallBack(Timer *t); - - /** - * Deletes a timer for the current module - * @param t The timer - */ - bool DelCallBack(Timer *t); - /** Called on NickServ HELP * @param u The user requesting help */ @@ -1201,10 +1190,10 @@ class CoreExport ModuleManager */ static void Attach(Implementation* i, Module* mod, size_t sz); - /** Delete all timers attached to a module + /** Delete all callbacks attached to a module * @param m The module */ - static void ClearTimers(Module *m); + static void ClearCallBacks(Module *m); private: /** Call the module_delete function to safely delete the module @@ -1213,7 +1202,27 @@ private: static void DeleteModule(Module *m); }; - +/** Class used for callbacks within modules + */ +class CallBack : public Timer +{ + private: + Module *m; + public: + CallBack(Module *mod, long time_from_now, time_t now = time(NULL), bool repeating = false) : Timer(time_from_now, now, repeating), m(mod) + { + m->CallBacks.push_back(this); + } + + virtual ~CallBack() + { + std::list::iterator it = std::find(m->CallBacks.begin(), m->CallBacks.end(), this); + if (it != m->CallBacks.end()) + { + m->CallBacks.erase(it); + } + } +}; struct ModuleHash_ { char *name; diff --git a/include/timers.h b/include/timers.h index 0de49b17d..30a49acff 100644 --- a/include/timers.h +++ b/include/timers.h @@ -103,12 +103,6 @@ class CoreExport TimerManager : public Extensible */ static void DelTimer(Timer *T); - /** Check if something is a timer - * @param T A pointer - * @return true or false - */ - static bool IsTimer(Timer *T); - /** Tick all pending timers * @param ctime The current time */ -- cgit