source: lib/events.h @ c7eb771

Last change on this file since c7eb771 was c5c18c1, checked in by Wilmer van der Gaast <wilmer@…>, at 2009-10-10T23:57:26Z

Hacked up a B_EV_FLAG_FORCE_REPEAT event handler flag to make libpurple
happy.

  • Property mode set to 100644
File size: 3.3 KB
Line 
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
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. */
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
47/* The conditions you can pass to b_input_add()/that will be passed to
48   the given callback function. */
49typedef enum {
50        B_EV_IO_READ = 1 << 0,
51        B_EV_IO_WRITE = 1 << 1,
52        B_EV_FLAG_FORCE_ONCE = 1 << 16,
53        B_EV_FLAG_FORCE_REPEAT = 1 << 17,
54} b_input_condition;
55typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond);
56
57/* For internal use. */
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
62/* #define event_debug( x... ) printf( x ) */
63#define event_debug( x... )
64
65/* Call this once when the program starts. It'll initialize the event handler
66   library (if necessary) and then return immediately. */
67G_MODULE_EXPORT void b_main_init();
68
69/* This one enters the event loop. It shouldn't return until one of the event
70   handlers calls b_main_quit(). */
71G_MODULE_EXPORT void b_main_run();
72G_MODULE_EXPORT void b_main_quit();
73
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. */
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);
82
83/* For now, closesocket() is only a function when using libevent. With GLib
84   it's a preprocessor macro. */
85#ifdef EVENTS_LIBEVENT
86G_MODULE_EXPORT void closesocket(int fd);
87#endif
88
89#endif /* _EVENTS_H_ */
Note: See TracBrowser for help on using the repository browser.