| 1 /* pidgin |
|
| 2 * |
|
| 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. |
|
| 6 * |
|
| 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. |
|
| 11 * |
|
| 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. |
|
| 16 * |
|
| 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 |
|
| 20 */ |
|
| 21 |
|
| 22 #include <glib.h> |
|
| 23 #include "gtkeventloop.h" |
|
| 24 #include "eventloop.h" |
|
| 25 #include "internal.h" |
|
| 26 |
|
| 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) |
|
| 29 |
|
| 30 typedef struct _PidginIOClosure { |
|
| 31 PurpleInputFunction function; |
|
| 32 guint result; |
|
| 33 gpointer data; |
|
| 34 |
|
| 35 } PidginIOClosure; |
|
| 36 |
|
| 37 static gboolean pidgin_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) |
|
| 38 { |
|
| 39 PidginIOClosure *closure = data; |
|
| 40 PurpleInputCondition purple_cond = 0; |
|
| 41 |
|
| 42 if (condition & PIDGIN_READ_COND) |
|
| 43 purple_cond |= PURPLE_INPUT_READ; |
|
| 44 if (condition & PIDGIN_WRITE_COND) |
|
| 45 purple_cond |= PURPLE_INPUT_WRITE; |
|
| 46 |
|
| 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 |
|
| 52 |
|
| 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 */ |
|
| 61 |
|
| 62 return TRUE; |
|
| 63 } |
|
| 64 #endif /* _WIN32 */ |
|
| 65 |
|
| 66 closure->function(closure->data, g_io_channel_unix_get_fd(source), |
|
| 67 purple_cond); |
|
| 68 |
|
| 69 return TRUE; |
|
| 70 } |
|
| 71 |
|
| 72 static guint pidgin_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, |
|
| 73 gpointer data) |
|
| 74 { |
|
| 75 PidginIOClosure *closure = g_new0(PidginIOClosure, 1); |
|
| 76 GIOChannel *channel; |
|
| 77 GIOCondition cond = 0; |
|
| 78 |
|
| 79 closure->function = function; |
|
| 80 closure->data = data; |
|
| 81 |
|
| 82 if (condition & PURPLE_INPUT_READ) |
|
| 83 cond |= PIDGIN_READ_COND; |
|
| 84 if (condition & PURPLE_INPUT_WRITE) |
|
| 85 cond |= PIDGIN_WRITE_COND; |
|
| 86 |
|
| 87 #ifdef _WIN32 |
|
| 88 channel = g_io_channel_win32_new_socket(fd); |
|
| 89 #else |
|
| 90 channel = g_io_channel_unix_new(fd); |
|
| 91 #endif |
|
| 92 |
|
| 93 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, |
|
| 94 pidgin_io_invoke, closure, g_free); |
|
| 95 |
|
| 96 #if 0 |
|
| 97 purple_debug_misc("gtk_eventloop", |
|
| 98 "CLOSURE: adding input watcher %d for fd %d\n", |
|
| 99 closure->result, fd); |
|
| 100 #endif |
|
| 101 |
|
| 102 g_io_channel_unref(channel); |
|
| 103 return closure->result; |
|
| 104 } |
|
| 105 |
|
| 106 static PurpleEventLoopUiOps eventloop_ops = |
|
| 107 { |
|
| 108 g_timeout_add, |
|
| 109 g_source_remove, |
|
| 110 pidgin_input_add, |
|
| 111 g_source_remove, |
|
| 112 NULL, /* input_get_error */ |
|
| 113 g_timeout_add_seconds, |
|
| 114 NULL, |
|
| 115 NULL, |
|
| 116 NULL, |
|
| 117 NULL |
|
| 118 }; |
|
| 119 |
|
| 120 PurpleEventLoopUiOps * |
|
| 121 pidgin_eventloop_get_ui_ops(void) |
|
| 122 { |
|
| 123 return &eventloop_ops; |
|
| 124 } |
|