Add purple_util_write_data_to_*_file declarations
[pidgin-git.git] / pidgin / gtkeventloop.c
blob6239a8b4da8bd688adfc5927027e350005c0bb7b
1 /* pidgin
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
5 * source distribution.
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 <glib.h>
23 #include "gtkeventloop.h"
24 #include "eventloop.h"
25 #include "internal.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;
32 guint result;
33 gpointer data;
35 } PidginIOClosure;
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;
47 #if 0
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));
51 #endif
53 #ifdef _WIN32
54 if(! purple_cond) {
55 #if 0
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);
60 #endif /* DEBUG */
62 return TRUE;
64 #endif /* _WIN32 */
66 closure->function(closure->data, g_io_channel_unix_get_fd(source),
67 purple_cond);
69 return TRUE;
72 static guint pidgin_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
73 gpointer data)
75 PidginIOClosure *closure = g_new0(PidginIOClosure, 1);
76 GIOChannel *channel;
77 GIOCondition cond = 0;
78 #ifdef _WIN32
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;
83 #endif
85 closure->function = function;
86 closure->data = data;
88 if (condition & PURPLE_INPUT_READ)
89 cond |= PIDGIN_READ_COND;
90 if (condition & PURPLE_INPUT_WRITE)
91 cond |= PIDGIN_WRITE_COND;
93 #ifdef _WIN32
94 if (use_glib_io_channel == 0)
95 channel = wpurple_g_io_channel_win32_new_socket(fd);
96 else
97 #endif
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);
103 #if 0
104 purple_debug_misc("gtk_eventloop",
105 "CLOSURE: adding input watcher %d for fd %d\n",
106 closure->result, fd);
107 #endif
109 g_io_channel_unref(channel);
110 return closure->result;
113 static PurpleEventLoopUiOps eventloop_ops =
115 g_timeout_add,
116 g_source_remove,
117 pidgin_input_add,
118 g_source_remove,
119 NULL, /* input_get_error */
120 g_timeout_add_seconds,
121 NULL,
122 NULL,
123 NULL,
124 NULL
127 PurpleEventLoopUiOps *
128 pidgin_eventloop_get_ui_ops(void)
130 return &eventloop_ops;