2 * Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 * This file is part of python-purple.
6 * python-purple 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 3 of the License, or
9 * (at your option) any later version.
11 * python-purple 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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
32 #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
34 typedef struct _PurpleGLibIOClosure {
35 PurpleInputFunction function;
38 } PurpleGLibIOClosure;
40 static gboolean purple_glib_io_invoke(GIOChannel *source, GIOCondition condition,
43 PurpleGLibIOClosure *closure = data;
44 PurpleInputCondition purple_cond = 0;
46 if (condition & PURPLE_GLIB_READ_COND)
47 purple_cond |= PURPLE_INPUT_READ;
48 if (condition & PURPLE_GLIB_WRITE_COND)
49 purple_cond |= PURPLE_INPUT_WRITE;
51 closure->function(closure->data, g_io_channel_unix_get_fd(source),
57 guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
60 PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
62 GIOCondition cond = 0;
64 closure->function = function;
67 if (condition & PURPLE_INPUT_READ)
68 cond |= PURPLE_GLIB_READ_COND;
69 if (condition & PURPLE_INPUT_WRITE)
70 cond |= PURPLE_GLIB_WRITE_COND;
72 channel = g_io_channel_unix_new(fd);
73 closure->result = g_io_add_watch_full(channel, 0, cond,
74 purple_glib_io_invoke, closure, g_free);
76 g_io_channel_unref(channel);
77 return closure->result;