source: lib/events.h @ b6ab05b

Last change on this file since b6ab05b was 25b5a4a, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-10-03T03:03:19Z

Make sure events_*.c are fully compatible to callers so plugins built for
a different flavour will still work.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[ecf8fa8]1/*
2 * nogaim
3 *
4 * Copyright (C) 2006 Wilmer van der Gaast and others
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 *
20 */
21
[0aaca60]22/* This stuff used to be in proxy.c too, but I split it off so BitlBee can
23   use other libraries (like libevent) to handle events. proxy.c is one very
24   nice piece of work from Gaim. It connects to a TCP server in the back-
25   ground and calls a callback function once the connection is ready to use.
26   This function (proxy_connect()) can be found in proxy.c. (It also
27   transparently handles HTTP/SOCKS proxies, when necessary.)
28   
29   This file offers some extra event handling toys, which will be handled
30   by GLib or libevent. The advantage of using libevent is that it can use
31   more advanced I/O polling functions like epoll() in recent Linux
32   kernels. This should improve BitlBee's scalability. */
[ecf8fa8]33
34
35#ifndef _EVENTS_H_
36#define _EVENTS_H_
37
38#include <sys/types.h>
39#ifndef _WIN32
40#include <sys/socket.h>
41#include <netdb.h>
42#include <netinet/in.h>
43#endif
44#include <glib.h>
45#include <gmodule.h>
46
[9ff5737]47/* The conditions you can pass to b_input_add()/that will be passed to
[0aaca60]48   the given callback function. */
[ecf8fa8]49typedef enum {
[e046390]50        B_EV_IO_READ = 1 << 0,
[c5c18c1]51        B_EV_IO_WRITE = 1 << 1,
52        B_EV_FLAG_FORCE_ONCE = 1 << 16,
53        B_EV_FLAG_FORCE_REPEAT = 1 << 17,
[ba9edaa]54} b_input_condition;
55typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond);
[ecf8fa8]56
[0aaca60]57/* For internal use. */
[ecf8fa8]58#define GAIM_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR)
59#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
60#define GAIM_ERR_COND   (G_IO_HUP | G_IO_ERR | G_IO_NVAL)
61
[9ff5737]62/* #define event_debug( x... ) printf( x ) */
[df70eafa]63#define event_debug( x... )
[fc2ee0f]64
[0aaca60]65/* Call this once when the program starts. It'll initialize the event handler
66   library (if necessary) and then return immediately. */
[ba9edaa]67G_MODULE_EXPORT void b_main_init();
[0aaca60]68
69/* This one enters the event loop. It shouldn't return until one of the event
70   handlers calls b_main_quit(). */
[ba9edaa]71G_MODULE_EXPORT void b_main_run();
72G_MODULE_EXPORT void b_main_quit();
[ecf8fa8]73
[0aaca60]74
75/* Add event handlers (for I/O or a timeout). The event handler will be called
76   every time the event "happens", until your event handler returns FALSE (or
77   until you remove it using b_event_remove(). As usual, the data argument
78   can be used to pass your own data to the event handler. */
[ba9edaa]79G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data);
80G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data);
81G_MODULE_EXPORT void b_event_remove(gint id);
[ecf8fa8]82
[25b5a4a]83/* With libevent, this one also cleans up event handlers if that wasn't already
84   done (the caller is expected to do so but may miss it sometimes). */
[3f199fc]85G_MODULE_EXPORT void closesocket(int fd);
86
[ecf8fa8]87#endif /* _EVENTS_H_ */
Note: See TracBrowser for help on using the repository browser.