#ifndef IRC_CMD_H
#define IRC_CMD_H
/**
* @file
*
* Command handlers callback lists for use with irc_line's
*
* XXX: irc_cmd_remove called from iniside irc_cmd_invoke?
*/
#include "irc_line.h"
#include "chain.h"
/**
* A single command name + handler function lookup entry. This defines the irc_line::command to handle, and the function used to handle it.
*
* Note that when an irc_line is matched against an array of these, only the *first* matching handler is invoked.
*/
struct irc_cmd_handler {
/** Command name to match */
const char *command;
/**
* Handler function.
*
* @param line the irc_line that matched the command
* @param arg the context arg, as given to irc_cmd_add.
*/
void (*func) (const struct irc_line *line, void *arg);
};
/**
* A registered list of irc_cmd_handlers
*/
struct irc_cmd_table {
CHAIN_ITEM_HEADER(irc_cmd_table);
/** NULL-terminated array of handlers */
const struct irc_cmd_handler *list;
/** Context argument*/
void *arg;
};
CHAIN_HEAD_TYPE(irc_cmd_handlers, irc_cmd_table);
/**
* Initialize a irc_cmd_handlers.
*/
void irc_cmd_init (struct irc_cmd_handlers *handlers);
/**
* Append the given NULL-termianted array of irc_cmd_handler's to the irc_cmd_handlers, without copying it.
*
* @param list the { NULL, NULL } termianted array of irc_cmd_handler's
* @param arg the context argument
*/
err_t irc_cmd_add (struct irc_cmd_handlers *handlers, const struct irc_cmd_handler list[], void *arg);
/**
* Trigger all relevant handlers for the given irc_line.
*
* @param line the line to match against the handlers and invoke the func with
*/
void irc_cmd_invoke (struct irc_cmd_handlers *handlers, const struct irc_line *line);
/**
* Remove a previously added handler handlers.
*
* @param list the list given to irc_cmd_add, compared as pointer value
* @param arg the context arg given to irc_cmd_add, compared as pointer value
*/
void irc_cmd_remove (struct irc_cmd_handlers *handlers, const struct irc_cmd_handler list[], void *arg);
/**
* Clears an irc_cmd_list, releasing all memory allocated by the.
*/
void irc_cmd_clear (struct irc_cmd_handlers *handlers);
#endif /* IRC_CMD_H */