src/irc_cmd.h
author Tero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 23:55:30 +0200
changeset 71 0a13030f795d
parent 69 6f298b6e0d5f
child 87 f0db6ebf18b9
permissions -rw-r--r--
implement signal_ignore using sigaction directly, without any libevent in between
#ifndef IRC_CMD_H
#define IRC_CMD_H

/**
 * @file
 *
 * Flexible command handlers callback lists for use with irc_lines
 */

#include "irc_line.h"
#include "chain.h"

/**
 * Single command -> handler mapping for lookup
 */
struct irc_cmd_handler {
    /** The command name to match */
    const char *command;

    /** The handler function */
    void (*func) (const struct irc_line *line, void *arg);
};

/**
 * @struct irc_cmd_handlers
 *
 * A dynamic list of irc_cmd_chain handlers
 */
typedef struct chain_list irc_cmd_handlers_t;

/**
 * Initialize a irc_cmd_handlers list.
 */
void irc_cmd_init (irc_cmd_handlers_t *handlers);

/**
 * Add an irc_cmd_chain to the irc_cmd_handlers list for the given handlers/arg
 */
err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);

/**
 * Trigger irc_cmd_chain callbacks for the given irc_line
 */
void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line);

/**
 * Remove a previously added chain_head from the irc_cmd_handlers list with the given list/arg
 */
void irc_cmd_remove (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);

/**
 * Cleanup an irc_cmd_handlers list
 */
void irc_cmd_free (irc_cmd_handlers_t *handlers);

#endif /* IRC_CMD_H */