src/irc_chan.h
changeset 26 aec062af155d
child 37 4fe4a3c4496e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/irc_chan.h	Tue Mar 10 01:11:12 2009 +0200
@@ -0,0 +1,82 @@
+#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 "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;
+
+};
+
+/**
+ * General IRC channel states
+ */
+enum irc_chan_state {
+    /** Initialized, but idle */
+    IRC_CHAN_INIT,
+
+    /** JOIN request sent */
+    IRC_CHAN_JOINING,
+
+    /** Currently joined to the channel */
+    IRC_CHAN_JOINED,
+};
+
+/**
+ * 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;
+    
+    /** Current state */
+    enum irc_chan_state state;
+};
+
+/**
+ * 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);
+
+/**
+ * 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