terom@22: #ifndef IRC_CMD_H terom@22: #define IRC_CMD_H terom@22: terom@23: /** terom@23: * @file terom@23: * terom@87: * Command handlers callback lists for use with irc_line's terom@132: * terom@132: * XXX: irc_cmd_remove called from iniside irc_cmd_invoke? terom@23: */ terom@23: terom@23: #include "irc_line.h" terom@37: #include "chain.h" terom@23: terom@23: /** terom@87: * A single command name + handler function lookup entry. This defines the irc_line::command to handle, and the function used to handle it. terom@87: * terom@87: * Note that when an irc_line is matched against an array of these, only the *first* matching handler is invoked. terom@23: */ terom@23: struct irc_cmd_handler { terom@23: /** The command name to match */ terom@23: const char *command; terom@23: terom@87: /** terom@87: * The handler function. terom@87: * terom@87: * @param line the irc_line that matched the command terom@87: * @param arg the context arg, as given to irc_cmd_add. terom@87: */ terom@37: void (*func) (const struct irc_line *line, void *arg); terom@23: }; terom@23: terom@23: /** terom@87: * A dynamic list of irc_cmd_handler's terom@23: */ terom@37: typedef struct chain_list irc_cmd_handlers_t; terom@23: terom@37: /** terom@37: * Initialize a irc_cmd_handlers list. terom@37: */ terom@37: void irc_cmd_init (irc_cmd_handlers_t *handlers); terom@23: terom@37: /** terom@87: * Append the given NULL-termianted array of irc_cmd_handler's to the irc_cmd_handlers list, without copying it. terom@87: * terom@87: * @param handlers the irc_cmd_handlers_t terom@87: * @param list the { NULL, NULL } termianted array of irc_cmd_handlers terom@87: * @param arg the opaque context argument, will be passed to the func's of the given list when invoked terom@37: */ terom@37: err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg); terom@23: terom@37: /** terom@87: * Trigger all relevant handlers for the given irc_line. terom@87: * terom@87: * @param handlers the irc_cmd_handlers_t terom@87: * @param line the line to match against the handlers and invoke the func with terom@37: */ terom@37: void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line); terom@37: terom@37: /** terom@87: * Remove a previously added handler list. terom@87: * terom@87: * @param handlers the irc_cmd_handlers_t terom@87: * @param list the list given to irc_cmd_add, compared as pointer value terom@87: * @param arg the context arg given to irc_cmd_add, compared as pointer value terom@69: */ terom@69: void irc_cmd_remove (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg); terom@69: terom@69: /** terom@87: * Cleanup an irc_cmd_handlers list, releasing all memory. terom@87: * terom@87: * @param handlers the irc_cmd_handlers_t to cleanup terom@37: */ terom@37: void irc_cmd_free (irc_cmd_handlers_t *handlers); terom@37: terom@22: #endif /* IRC_CMD_H */