source: protocols/events_glib.c @ ecf8fa8

Last change on this file since ecf8fa8 was ecf8fa8, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-05-09T07:20:05Z

Split off event handling related functions (depending on GLib) to events_glib.c.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/*
8 * Event handling (using GLib)
9 */
10
11/*
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  GNU General Public License for more details.
21
22  You should have received a copy of the GNU General Public License with
23  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
24  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25  Suite 330, Boston, MA  02111-1307  USA
26*/
27
28#define BITLBEE_CORE
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <sys/types.h>
33#ifndef _WIN32
34#include <sys/socket.h>
35#include <netdb.h>
36#include <netinet/in.h>
37#include <arpa/inet.h>
38#include <unistd.h>
39#else
40#include "sock.h"
41#define ETIMEDOUT WSAETIMEDOUT
42#define EINPROGRESS WSAEINPROGRESS
43#endif
44#include <fcntl.h>
45#include <errno.h>
46#include "proxy.h"
47
48typedef struct _GaimIOClosure {
49        GaimInputFunction function;
50        guint result;
51        gpointer data;
52} GaimIOClosure;
53
54static gboolean gaim_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
55{
56        GaimIOClosure *closure = data;
57        GaimInputCondition gaim_cond = 0;
58
59        if (condition & GAIM_READ_COND)
60                gaim_cond |= GAIM_INPUT_READ;
61        if (condition & GAIM_WRITE_COND)
62                gaim_cond |= GAIM_INPUT_WRITE;
63
64        closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond);
65
66        return TRUE;
67}
68
69static void gaim_io_destroy(gpointer data)
70{
71        g_free(data);
72}
73
74gint gaim_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, gpointer data)
75{
76        GaimIOClosure *closure = g_new0(GaimIOClosure, 1);
77        GIOChannel *channel;
78        GIOCondition cond = 0;
79       
80        closure->function = function;
81        closure->data = data;
82       
83        if (condition & GAIM_INPUT_READ)
84                cond |= GAIM_READ_COND;
85        if (condition & GAIM_INPUT_WRITE)
86                cond |= GAIM_WRITE_COND;
87       
88        channel = g_io_channel_unix_new(source);
89        closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
90                                              gaim_io_invoke, closure, gaim_io_destroy);
91       
92        g_io_channel_unref(channel);
93        return closure->result;
94}
95
96void gaim_input_remove(gint tag)
97{
98        if (tag > 0)
99                g_source_remove(tag);
100}
Note: See TracBrowser for help on using the repository browser.