2 * @file gtk_eventloop.c Purple Event Loop API (gtk implementation)
8 * Pidgin is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
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.
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.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "gtkeventloop.h"
29 #include "eventloop.h"
34 #define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
35 #define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
37 typedef struct _PidginIOClosure
{
38 PurpleInputFunction function
;
44 static gboolean
pidgin_io_invoke(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
46 PidginIOClosure
*closure
= data
;
47 PurpleInputCondition purple_cond
= 0;
49 if (condition
& PIDGIN_READ_COND
)
50 purple_cond
|= PURPLE_INPUT_READ
;
51 if (condition
& PIDGIN_WRITE_COND
)
52 purple_cond
|= PURPLE_INPUT_WRITE
;
55 purple_debug_misc("gtk_eventloop",
56 "CLOSURE: callback for %d, fd is %d\n",
57 closure
->result
, g_io_channel_unix_get_fd(source
));
63 purple_debug_misc("gtk_eventloop",
64 "CLOSURE received GIOCondition of 0x%x, which does not"
65 " match 0x%x (READ) or 0x%x (WRITE)\n",
66 condition
, PIDGIN_READ_COND
, PIDGIN_WRITE_COND
);
73 closure
->function(closure
->data
, g_io_channel_unix_get_fd(source
),
79 static guint
pidgin_input_add(gint fd
, PurpleInputCondition condition
, PurpleInputFunction function
,
82 PidginIOClosure
*closure
= g_new0(PidginIOClosure
, 1);
84 GIOCondition cond
= 0;
86 static int use_glib_io_channel
= -1;
88 if (use_glib_io_channel
== -1)
89 use_glib_io_channel
= (g_getenv("PIDGIN_GLIB_IO_CHANNEL") != NULL
) ? 1 : 0;
92 closure
->function
= function
;
95 if (condition
& PURPLE_INPUT_READ
)
96 cond
|= PIDGIN_READ_COND
;
97 if (condition
& PURPLE_INPUT_WRITE
)
98 cond
|= PIDGIN_WRITE_COND
;
101 if (use_glib_io_channel
== 0)
102 channel
= wpurple_g_io_channel_win32_new_socket(fd
);
105 channel
= g_io_channel_unix_new(fd
);
107 closure
->result
= g_io_add_watch_full(channel
, G_PRIORITY_DEFAULT
, cond
,
108 pidgin_io_invoke
, closure
, g_free
);
111 purple_debug_misc("gtk_eventloop",
112 "CLOSURE: adding input watcher %d for fd %d\n",
113 closure
->result
, fd
);
116 g_io_channel_unref(channel
);
117 return closure
->result
;
120 static PurpleEventLoopUiOps eventloop_ops
=
126 NULL
, /* input_get_error */
127 #if GLIB_CHECK_VERSION(2,14,0)
128 g_timeout_add_seconds
,
137 PurpleEventLoopUiOps
*
138 pidgin_eventloop_get_ui_ops(void)
140 return &eventloop_ops
;