Modules:QuickList:Callbacks
From Anope Wiki
Contents |
Callbacks
Callbacks allow you to execute a given function at a given time.
moduleAddCallback
Registers a callback with the system.
int moduleAddCallback(char *name, time_t when, int (*func) (int argc, char *argv[]), int argc, char **argc)
Each callback must have their unique name, which is a normal string. The function specified as func will be called as soon as possible after when (absolute unixtime) has passed; it can be called a bit later if services are idling. The argc and argv arguments will be copied and passed with the callback when it is executed.
Returns:
- MOD_ERR_OK - Success
- MOD_ERR_MEMORY - Not enough memory to add callback
moduleDelCallback
Delete a registered callback.
void moduleDelCallback(char *name)
Deletes the callback with the given name from the system. It won't be called anymore at the time it was scheduled to be called. There is no need to delete a callback if it is being called; it will be deleted automatically after it has been called.
Example
#include <module.h>
int myCallback(int argc, char **argv);
int AnopeInit(int argc, char **argv)
{
int ret1, ret2;
char *data = "hello world";
ret1 = moduleAddCallback("myCallback", (time(NULL) + 10), myCallback, 0, NULL);
ret2 = moduleAddCallback("myCallback2", (time(NULL) + 15), myCallback, 1, &data);
if ((ret1 != MOD_ERR_OK) || (ret2 != MOD_ERR_OK)) {
alog("Can't add callbacks");
return MOD_STOP
}
return MOD_CONT;
}
int myCallback(int argc, char **argv)
{
alog("Ten seconds have passed");
moduleDelCallback("myCallback2");
return MOD_CONT;
}

