Mon, 30 Apr 2007 01:18:28 +0000
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
| 8273 | 1 | /** |
| 15884 | 2 | * @file gtk_eventloop.c Purple Event Loop API (gtk implementation) |
|
16254
eeb2bba4dc94
Rename the Doxygen group from gtkui to pidgin.
Richard Laager <rlaager@pidgin.im>
parents:
15931
diff
changeset
|
3 | * @ingroup pidgin |
| 8273 | 4 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
5 | * pidgin |
| 8273 | 6 | * |
|
15931
716b5fac1895
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
7 | * Pidgin is the legal property of its developers, whose names are too numerous |
| 8273 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | ||
| 26 | #include <glib.h> | |
| 27 | #include "gtkeventloop.h" | |
| 28 | #include "eventloop.h" | |
|
14793
66e32c262451
[gaim-migrate @ 17487]
Daniel Atallah <datallah@pidgin.im>
parents:
14792
diff
changeset
|
29 | #ifdef _WIN32 |
|
14792
02a5df4343f7
[gaim-migrate @ 17486]
Daniel Atallah <datallah@pidgin.im>
parents:
14253
diff
changeset
|
30 | #include "win32dep.h" |
|
14793
66e32c262451
[gaim-migrate @ 17487]
Daniel Atallah <datallah@pidgin.im>
parents:
14792
diff
changeset
|
31 | #endif |
| 8273 | 32 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
33 | #define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
34 | #define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) |
| 8273 | 35 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
36 | typedef struct _PidginIOClosure { |
| 15884 | 37 | PurpleInputFunction function; |
| 8273 | 38 | guint result; |
| 39 | gpointer data; | |
| 40 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
41 | } PidginIOClosure; |
| 8273 | 42 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
43 | static void pidgin_io_destroy(gpointer data) |
| 8273 | 44 | { |
| 45 | g_free(data); | |
| 46 | } | |
| 47 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
48 | static gboolean pidgin_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) |
| 8273 | 49 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
50 | PidginIOClosure *closure = data; |
| 15884 | 51 | PurpleInputCondition purple_cond = 0; |
| 8273 | 52 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
53 | if (condition & PIDGIN_READ_COND) |
| 15884 | 54 | purple_cond |= PURPLE_INPUT_READ; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
55 | if (condition & PIDGIN_WRITE_COND) |
| 15884 | 56 | purple_cond |= PURPLE_INPUT_WRITE; |
| 8273 | 57 | |
| 58 | #if 0 | |
| 15884 | 59 | purple_debug(PURPLE_DEBUG_MISC, "gtk_eventloop", |
| 8273 | 60 | "CLOSURE: callback for %d, fd is %d\n", |
| 61 | closure->result, g_io_channel_unix_get_fd(source)); | |
| 62 | #endif | |
| 63 | ||
|
11065
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
64 | #ifdef _WIN32 |
| 15884 | 65 | if(! purple_cond) { |
|
15697
78ddac185d80
winpidgin warning fixes
Daniel Atallah <datallah@pidgin.im>
parents:
15562
diff
changeset
|
66 | #ifdef DEBUG |
| 15884 | 67 | purple_debug(PURPLE_DEBUG_MISC, "gtk_eventloop", |
|
11065
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
68 | "CLOSURE received GIOCondition of 0x%x, which does not" |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
69 | " match 0x%x (READ) or 0x%x (WRITE)\n", |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
70 | condition, PIDGIN_READ_COND, PIDGIN_WRITE_COND); |
|
11065
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
71 | #endif /* DEBUG */ |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
72 | |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
73 | return TRUE; |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
74 | } |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
75 | #endif /* _WIN32 */ |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
76 | |
|
895342350443
[gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents:
8807
diff
changeset
|
77 | closure->function(closure->data, g_io_channel_unix_get_fd(source), |
| 15884 | 78 | purple_cond); |
| 8273 | 79 | |
| 80 | return TRUE; | |
| 81 | } | |
| 82 | ||
| 15884 | 83 | static guint pidgin_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, |
| 8273 | 84 | gpointer data) |
| 85 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
86 | PidginIOClosure *closure = g_new0(PidginIOClosure, 1); |
| 8273 | 87 | GIOChannel *channel; |
| 88 | GIOCondition cond = 0; | |
| 89 | ||
| 90 | closure->function = function; | |
| 91 | closure->data = data; | |
| 92 | ||
| 15884 | 93 | if (condition & PURPLE_INPUT_READ) |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
94 | cond |= PIDGIN_READ_COND; |
| 15884 | 95 | if (condition & PURPLE_INPUT_WRITE) |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
96 | cond |= PIDGIN_WRITE_COND; |
| 8273 | 97 | |
|
14792
02a5df4343f7
[gaim-migrate @ 17486]
Daniel Atallah <datallah@pidgin.im>
parents:
14253
diff
changeset
|
98 | #ifdef _WIN32 |
| 15884 | 99 | channel = wpurple_g_io_channel_win32_new_socket(fd); |
|
14792
02a5df4343f7
[gaim-migrate @ 17486]
Daniel Atallah <datallah@pidgin.im>
parents:
14253
diff
changeset
|
100 | #else |
| 8280 | 101 | channel = g_io_channel_unix_new(fd); |
|
14792
02a5df4343f7
[gaim-migrate @ 17486]
Daniel Atallah <datallah@pidgin.im>
parents:
14253
diff
changeset
|
102 | #endif |
| 8273 | 103 | closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
104 | pidgin_io_invoke, closure, pidgin_io_destroy); |
| 8273 | 105 | |
| 106 | #if 0 | |
| 15884 | 107 | purple_debug(PURPLE_DEBUG_MISC, "gtk_eventloop", |
| 8273 | 108 | "CLOSURE: adding input watcher %d for fd %d\n", |
| 8280 | 109 | closure->result, fd); |
| 8273 | 110 | #endif |
| 111 | ||
| 112 | g_io_channel_unref(channel); | |
| 113 | return closure->result; | |
| 114 | } | |
| 115 | ||
| 15884 | 116 | static PurpleEventLoopUiOps eventloop_ops = |
| 8273 | 117 | { |
| 118 | g_timeout_add, | |
|
15729
6932ac4e5b3d
Change out source_remove and input_remove eventloop functions to return
Mark Doliner <markdoliner@pidgin.im>
parents:
15697
diff
changeset
|
119 | g_source_remove, |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
120 | pidgin_input_add, |
|
15746
017e33725857
Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evands@pidgin.im>
parents:
15729
diff
changeset
|
121 | g_source_remove, |
|
16752
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
122 | NULL, /* input_get_error */ |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
123 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
124 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
125 | NULL, |
|
e6bcb1628c57
Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents:
16254
diff
changeset
|
126 | NULL |
| 8273 | 127 | }; |
| 128 | ||
| 15884 | 129 | PurpleEventLoopUiOps * |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
130 | pidgin_eventloop_get_ui_ops(void) |
| 8273 | 131 | { |
| 132 | return &eventloop_ops; | |
| 133 | } |