src/irc_cmd.h
changeset 171 b54f393c3df0
parent 132 f2ece471fb07
--- a/src/irc_cmd.h	Mon May 04 23:19:50 2009 +0300
+++ b/src/irc_cmd.h	Tue May 05 03:15:25 2009 +0300
@@ -18,11 +18,11 @@
  * Note that when an irc_line is matched against an array of these, only the *first* matching handler is invoked.
  */
 struct irc_cmd_handler {
-    /** The command name to match */
+    /** Command name to match */
     const char *command;
 
     /**
-     * The handler function.
+     * Handler function.
      *
      * @param line the irc_line that matched the command
      * @param arg the context arg, as given to irc_cmd_add.
@@ -31,46 +31,51 @@
 };
 
 /**
- * A dynamic list of irc_cmd_handler's
+ * A registered list of irc_cmd_handlers
  */
-typedef struct chain_list irc_cmd_handlers_t;
+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 list.
+ * Initialize a irc_cmd_handlers.
  */
-void irc_cmd_init (irc_cmd_handlers_t *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 list, without copying it.
+ * Append the given NULL-termianted array of irc_cmd_handler's to the irc_cmd_handlers, without copying it.
  *
- * @param handlers the irc_cmd_handlers_t
- * @param list the { NULL, NULL } termianted array of irc_cmd_handlers
- * @param arg the opaque context argument, will be passed to the func's of the given list when invoked
+ * @param list the { NULL, NULL } termianted array of irc_cmd_handler's
+ * @param arg the context argument
  */
-err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);
+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 handlers the irc_cmd_handlers_t
  * @param line the line to match against the handlers and invoke the func with
  */
-void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line);
+void irc_cmd_invoke (struct irc_cmd_handlers *handlers, const struct irc_line *line);
 
 /**
- * Remove a previously added handler list.
+ * Remove a previously added handler handlers.
  *
- * @param handlers the irc_cmd_handlers_t
  * @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 (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);
+void irc_cmd_remove (struct irc_cmd_handlers *handlers, const struct irc_cmd_handler list[], void *arg);
 
 /**
- * Cleanup an irc_cmd_handlers list, releasing all memory.
- *
- * @param handlers the irc_cmd_handlers_t to cleanup
+ * Clears an irc_cmd_list, releasing all memory allocated by the.
  */
-void irc_cmd_free (irc_cmd_handlers_t *handlers);
+void irc_cmd_clear (struct irc_cmd_handlers *handlers);
 
 #endif /* IRC_CMD_H */