2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: chatroom.h,v 1.6 2003/02/22 15:34:27 rich Exp $
33 typedef struct chatroom *chatroom;
35 /* Get (or create) the shared chatroom object for resource resid. */
36 extern chatroom get_chatroom (db_handle dbh, int resid);
38 /* Get the resid of a particular chatroom. */
39 extern int chatroom_get_resid (const chatroom r);
41 /* Get the index of the first and last message + 1 available in the room.
44 extern int chatroom_first_message_index (const chatroom r);
45 extern int chatroom_last_message_index (const chatroom r);
47 /* Get a message. If you try to get a message < first index, then this
48 * function returns NULL. If you try to get a message >= last index, then
49 * this function sleeps until the message becomes available. Before
50 * going to sleep, the function "pre_sleep (session, data)" is called.
52 extern message chatroom_get_message (const chatroom r, int index, void (*pre_sleep) (ml_session, void *data), ml_session session, void *data);
54 /* Get the next message across several chatrooms. This is used by the
55 * chatbot interface. 'rooms' is a vector of chatroom objects.
56 * 'next_msgids' is a hash from chatroom resid -> message ID
57 * (equivalent to the 'index' parameter to the chatroom_get_message
58 * function above). On success, the function sets *msg_rtn and
59 * *room_rtn and returns 0. On failure (basically, message < first
60 * index as above), then this sets *room_rtn only and returns -1.
62 extern int chatroom_get_message_multiple (const vector rooms, const hash next_msgids, message *msg_rtn, chatroom *room_rtn);
64 /* Post a message into the chatroom. Assumes the current time and the
65 * current user identity from the session.
67 extern void chatroom_post (chatroom r, ml_session session, const char *conninfo, const char *body);
69 /* Post a blank message to all chatrooms. */
70 extern void chatroom_spam_blank (pool thread_pool);
72 /* Enter and leave the chatroom. The chatroom object uses these functions
73 * to maintain a list of who is in the room at a moment in time.
75 extern void chatroom_enter (chatroom r, int userid, const char *username);
76 extern void chatroom_leave (chatroom r);
78 /* Get the current list of users. This returns a hash of userid -> count
79 * where count is the number of times this user is in the room. In
80 * particular, element 0 is the number of anonymous users in the room.
82 extern const hash chatroom_users (chatroom r);
84 /* This function is used to wait for changes in the list of users. It
85 * sleeps until a user enters or leaves the room and then returns.
87 extern void chatroom_wait_enter_leave_event (chatroom r, ml_session session);
89 #endif /* CHATROOM_H */