/src/pidgin/libpurple/eventloop.c
Line | Count | Source |
1 | | /** |
2 | | * @file eventloop.c Purple Event Loop API |
3 | | * @ingroup core |
4 | | */ |
5 | | |
6 | | /* purple |
7 | | * |
8 | | * Purple is the legal property of its developers, whose names are too numerous |
9 | | * to list here. Please refer to the COPYRIGHT file distributed with this |
10 | | * source distribution. |
11 | | * |
12 | | * This program is free software; you can redistribute it and/or modify |
13 | | * it under the terms of the GNU General Public License as published by |
14 | | * the Free Software Foundation; either version 2 of the License, or |
15 | | * (at your option) any later version. |
16 | | * |
17 | | * This program is distributed in the hope that it will be useful, |
18 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | | * GNU General Public License for more details. |
21 | | * |
22 | | * You should have received a copy of the GNU General Public License |
23 | | * along with this program; if not, write to the Free Software |
24 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
25 | | */ |
26 | | #include "internal.h" |
27 | | #include "eventloop.h" |
28 | | |
29 | | static PurpleEventLoopUiOps *eventloop_ui_ops = NULL; |
30 | | |
31 | | guint |
32 | | purple_timeout_add(guint interval, GSourceFunc function, gpointer data) |
33 | 0 | { |
34 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
35 | |
|
36 | 0 | return ops->timeout_add(interval, function, data); |
37 | 0 | } |
38 | | |
39 | | guint |
40 | | purple_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data) |
41 | 0 | { |
42 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
43 | |
|
44 | 0 | if (ops->timeout_add_seconds) |
45 | 0 | return ops->timeout_add_seconds(interval, function, data); |
46 | 0 | else |
47 | 0 | return ops->timeout_add(1000 * interval, function, data); |
48 | 0 | } |
49 | | |
50 | | gboolean |
51 | | purple_timeout_remove(guint tag) |
52 | 0 | { |
53 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
54 | |
|
55 | 0 | return ops->timeout_remove(tag); |
56 | 0 | } |
57 | | |
58 | | guint |
59 | | purple_input_add(int source, PurpleInputCondition condition, PurpleInputFunction func, gpointer user_data) |
60 | 0 | { |
61 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
62 | |
|
63 | 0 | return ops->input_add(source, condition, func, user_data); |
64 | 0 | } |
65 | | |
66 | | gboolean |
67 | | purple_input_remove(guint tag) |
68 | 0 | { |
69 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
70 | |
|
71 | 0 | return ops->input_remove(tag); |
72 | 0 | } |
73 | | |
74 | | int |
75 | | purple_input_get_error(int fd, int *error) |
76 | 0 | { |
77 | 0 | PurpleEventLoopUiOps *ops = purple_eventloop_get_ui_ops(); |
78 | |
|
79 | 0 | if (ops->input_get_error) |
80 | 0 | { |
81 | 0 | int ret = ops->input_get_error(fd, error); |
82 | 0 | errno = *error; |
83 | 0 | return ret; |
84 | 0 | } |
85 | 0 | else |
86 | 0 | { |
87 | 0 | socklen_t len; |
88 | 0 | len = sizeof(*error); |
89 | |
|
90 | 0 | return getsockopt(fd, SOL_SOCKET, SO_ERROR, error, &len); |
91 | 0 | } |
92 | 0 | } |
93 | | |
94 | | void |
95 | | purple_eventloop_set_ui_ops(PurpleEventLoopUiOps *ops) |
96 | 0 | { |
97 | 0 | eventloop_ui_ops = ops; |
98 | 0 | } |
99 | | |
100 | | PurpleEventLoopUiOps * |
101 | | purple_eventloop_get_ui_ops(void) |
102 | 0 | { |
103 | 0 | g_return_val_if_fail(eventloop_ui_ops != NULL, NULL); |
104 | | |
105 | 0 | return eventloop_ui_ops; |
106 | 0 | } |