3 * Purple 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
22 #include "eventloop.h"
24 #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
25 #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
28 PurpleInputFunction function
;
34 purple_io_invoke(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
36 PurpleIOClosure
*closure
= data
;
37 PurpleInputCondition purple_cond
= 0;
39 if (condition
& PURPLE_GLIB_READ_COND
)
40 purple_cond
|= PURPLE_INPUT_READ
;
41 if (condition
& PURPLE_GLIB_WRITE_COND
)
42 purple_cond
|= PURPLE_INPUT_WRITE
;
50 closure
->function(closure
->data
, g_io_channel_unix_get_fd(source
),
57 purple_input_add(int source
, PurpleInputCondition condition
, PurpleInputFunction func
, gpointer user_data
)
59 PurpleIOClosure
*closure
= g_new0(PurpleIOClosure
, 1);
61 GIOCondition cond
= 0;
63 closure
->function
= func
;
64 closure
->data
= user_data
;
66 if (condition
& PURPLE_INPUT_READ
)
67 cond
|= PURPLE_GLIB_READ_COND
;
68 if (condition
& PURPLE_INPUT_WRITE
)
69 cond
|= PURPLE_GLIB_WRITE_COND
;
72 channel
= g_io_channel_win32_new_socket(source
);
74 channel
= g_io_channel_unix_new(source
);
77 closure
->result
= g_io_add_watch_full(channel
, G_PRIORITY_DEFAULT
,
78 cond
, purple_io_invoke
, closure
, g_free
);
80 g_io_channel_unref(channel
);
81 return closure
->result
;
85 purple_input_remove(guint tag
)
87 return g_source_remove(tag
);
91 purple_input_pipe(int pipefd
[2])
94 return wpurple_input_pipe(pipefd
);