3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "gtkeventloop.h"
24 #include "eventloop.h"
27 #define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
28 #define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
30 typedef struct _PidginIOClosure
{
31 PurpleInputFunction function
;
37 static gboolean
pidgin_io_invoke(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
39 PidginIOClosure
*closure
= data
;
40 PurpleInputCondition purple_cond
= 0;
42 if (condition
& PIDGIN_READ_COND
)
43 purple_cond
|= PURPLE_INPUT_READ
;
44 if (condition
& PIDGIN_WRITE_COND
)
45 purple_cond
|= PURPLE_INPUT_WRITE
;
48 purple_debug_misc("gtk_eventloop",
49 "CLOSURE: callback for %d, fd is %d\n",
50 closure
->result
, g_io_channel_unix_get_fd(source
));
56 purple_debug_misc("gtk_eventloop",
57 "CLOSURE received GIOCondition of 0x%x, which does not"
58 " match 0x%x (READ) or 0x%x (WRITE)\n",
59 condition
, PIDGIN_READ_COND
, PIDGIN_WRITE_COND
);
66 closure
->function(closure
->data
, g_io_channel_unix_get_fd(source
),
72 static guint
pidgin_input_add(gint fd
, PurpleInputCondition condition
, PurpleInputFunction function
,
75 PidginIOClosure
*closure
= g_new0(PidginIOClosure
, 1);
77 GIOCondition cond
= 0;
79 static int use_glib_io_channel
= -1;
81 if (use_glib_io_channel
== -1)
82 use_glib_io_channel
= (g_getenv("PIDGIN_GLIB_IO_CHANNEL") != NULL
) ? 1 : 0;
85 closure
->function
= function
;
88 if (condition
& PURPLE_INPUT_READ
)
89 cond
|= PIDGIN_READ_COND
;
90 if (condition
& PURPLE_INPUT_WRITE
)
91 cond
|= PIDGIN_WRITE_COND
;
94 if (use_glib_io_channel
== 0)
95 channel
= wpurple_g_io_channel_win32_new_socket(fd
);
98 channel
= g_io_channel_unix_new(fd
);
100 closure
->result
= g_io_add_watch_full(channel
, G_PRIORITY_DEFAULT
, cond
,
101 pidgin_io_invoke
, closure
, g_free
);
104 purple_debug_misc("gtk_eventloop",
105 "CLOSURE: adding input watcher %d for fd %d\n",
106 closure
->result
, fd
);
109 g_io_channel_unref(channel
);
110 return closure
->result
;
113 static PurpleEventLoopUiOps eventloop_ops
=
119 NULL
, /* input_get_error */
120 g_timeout_add_seconds
,
127 PurpleEventLoopUiOps
*
128 pidgin_eventloop_get_ui_ops(void)
130 return &eventloop_ops
;