src/irc_chan.h
changeset 38 0c2e0cb46c3a
parent 37 4fe4a3c4496e
child 45 71e65564afd2
equal deleted inserted replaced
37:4fe4a3c4496e 38:0c2e0cb46c3a
    27  * Semantic IRC channel callbacks
    27  * Semantic IRC channel callbacks
    28  */
    28  */
    29 struct irc_chan_callbacks {
    29 struct irc_chan_callbacks {
    30     /** Joined the channel */
    30     /** Joined the channel */
    31     void (*on_self_join) (struct irc_chan *chan, void *arg);
    31     void (*on_self_join) (struct irc_chan *chan, void *arg);
       
    32 
       
    33     /** Someone sent a message to the channel */
       
    34     void (*on_msg) (struct irc_chan *chan, const char *prefix, const char *msg, void *arg);
    32 };
    35 };
       
    36 
       
    37 /**
       
    38  * Invoke the given callback with the given args
       
    39  */
       
    40 #define IRC_CHAN_INVOKE_CALLBACK(chan, _cb_name_, ...)          \
       
    41     do {                                                        \
       
    42         struct chain_head *head;                                \
       
    43                                                                 \
       
    44         CHAIN_FOREACH(&(chan)->callbacks, head) {               \
       
    45             const struct irc_chan_callbacks *callbacks = head->chain;       \
       
    46                                                                 \
       
    47             if (callbacks->_cb_name_)                           \
       
    48                 callbacks->_cb_name_((chan), ## __VA_ARGS__, head->arg);    \
       
    49         }                                                       \
       
    50     } while (0);
    33 
    51 
    34 /**
    52 /**
    35  * IRC channel state
    53  * IRC channel state
    36  */
    54  */
    37 struct irc_chan {
    55 struct irc_chan {
    54 
    72 
    55     } state;
    73     } state;
    56 
    74 
    57     /** General command handlers */
    75     /** General command handlers */
    58     irc_cmd_handlers_t handlers;
    76     irc_cmd_handlers_t handlers;
       
    77 
       
    78     /** High-level user callbacks */
       
    79     struct chain_list callbacks;
    59 };
    80 };
    60 
    81 
    61 /**
    82 /**
    62  * Return the channel's name
    83  * Return the channel's name
    63  */
    84  */
    79  * Destroy irc_chan state, without doing anything to the network
   100  * Destroy irc_chan state, without doing anything to the network
    80  */
   101  */
    81 void irc_chan_destroy (struct irc_chan *chan);
   102 void irc_chan_destroy (struct irc_chan *chan);
    82 
   103 
    83 /**
   104 /**
       
   105  * Add high-level irc_chan callbacks
       
   106  */
       
   107 err_t irc_chan_add_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg);
       
   108 
       
   109 /**
    84  * Send the initial JOIN message.
   110  * Send the initial JOIN message.
    85  *
   111  *
    86  * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state.
   112  * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state.
    87  *
   113  *
    88  * @param chan the channel to JOIN
   114  * @param chan the channel to JOIN