source: lib/events.h @ 92a9c68

Last change on this file since 92a9c68 was 9ff5737, checked in by Wilmer van der Gaast <wilmer@…>, at 2007-11-29T21:55:14Z

printf() in daemons considered harmful.

  • 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        GAIM_INPUT_READ = 1 << 1,
51        GAIM_INPUT_WRITE = 1 << 2
52} b_input_condition;
53typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond);
54
55/* For internal use. */
56#define GAIM_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR)
57#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
58#define GAIM_ERR_COND   (G_IO_HUP | G_IO_ERR | G_IO_NVAL)
59
60/* #define event_debug( x... ) printf( x ) */
61#define event_debug( x... )
62
63/* Call this once when the program starts. It'll initialize the event handler
64   library (if necessary) and then return immediately. */
65G_MODULE_EXPORT void b_main_init();
66
67/* This one enters the event loop. It shouldn't return until one of the event
68   handlers calls b_main_quit(). */
69G_MODULE_EXPORT void b_main_run();
70G_MODULE_EXPORT void b_main_quit();
71
72
73/* Add event handlers (for I/O or a timeout). The event handler will be called
74   every time the event "happens", until your event handler returns FALSE (or
75   until you remove it using b_event_remove(). As usual, the data argument
76   can be used to pass your own data to the event handler. */
77G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data);
78G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data);
79G_MODULE_EXPORT void b_event_remove(gint id);
80
81/* For now, closesocket() is only a function when using libevent. With GLib
82   it's a preprocessor macro. */
83#ifdef EVENTS_LIBEVENT
84G_MODULE_EXPORT void closesocket(int fd);
85#endif
86
87#endif /* _EVENTS_H_ */
Note: See TracBrowser for help on using the repository browser.