src/irc_chan.h
author Tero Marttila <terom@fixme.fi>
Thu, 12 Mar 2009 18:11:44 +0200
changeset 37 4fe4a3c4496e
parent 26 aec062af155d
child 38 0c2e0cb46c3a
permissions -rw-r--r--
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
#ifndef IRC_CHAN_H
#define IRC_CHAN_H

/**
 * @file
 *
 * Support for IRC channels, including tracking their state and actions on them.
 */
struct irc_chan_info;
struct irc_chan;

#include "irc_net.h"
#include "irc_cmd.h"
#include "error.h"
#include <sys/queue.h>

/**
 * IRC channel info, as required to create an irc_chan
 */
struct irc_chan_info {
    /** Channel name, with the [#&!] prefix */
    const char *channel;

};

/**
 * Semantic IRC channel callbacks
 */
struct irc_chan_callbacks {
    /** Joined the channel */
    void (*on_self_join) (struct irc_chan *chan, void *arg);
};

/**
 * IRC channel state
 */
struct irc_chan {
    /** The irc_net.channels list */
    TAILQ_ENTRY(irc_chan) node;

    /* The network we're on */
    struct irc_net *net;

    /** Our identifying info */
    struct irc_chan_info info;
    
    /** State flags */
    struct {
        /** JOIN request sent, waiting for reply */
        bool joining;

        /** Currently joined to channel */
        bool joined;

    } state;

    /** General command handlers */
    irc_cmd_handlers_t handlers;
};

/**
 * Return the channel's name
 */
const char* irc_chan_name (struct irc_chan *chan);

/**
 * Build/initialize a new irc_chan struct. This does not have any external side-effects.
 *
 * The channel will be in the IRC_CHAN_INIT state after this.
 *
 * @param chan_ptr the new irc_chan is returned via this pointer
 * @param net the irc_net this channel is on
 * @param info the channel's identifying information
 * @param err error codes are returned via this
 */
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err);

/**
 * Destroy irc_chan state, without doing anything to the network
 */
void irc_chan_destroy (struct irc_chan *chan);

/**
 * Send the initial JOIN message.
 *
 * The channel must be in the IRC_CHAN_INIT state, and will transition to the IRC_CHAN_JOINING state.
 *
 * @param chan the channel to JOIN
 */
err_t irc_chan_join (struct irc_chan *chan);


#endif