2 * @file eventloop.c Purple Event Loop API
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.
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.
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.
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
27 #include "eventloop.h"
29 static PurpleEventLoopUiOps
*eventloop_ui_ops
= NULL
;
32 purple_timeout_add(guint interval
, GSourceFunc function
, gpointer data
)
34 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
36 return ops
->timeout_add(interval
, function
, data
);
40 purple_timeout_add_seconds(guint interval
, GSourceFunc function
, gpointer data
)
42 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
44 if (ops
->timeout_add_seconds
)
45 return ops
->timeout_add_seconds(interval
, function
, data
);
47 return ops
->timeout_add(1000 * interval
, function
, data
);
51 purple_timeout_remove(guint tag
)
53 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
55 return ops
->timeout_remove(tag
);
59 purple_input_add(int source
, PurpleInputCondition condition
, PurpleInputFunction func
, gpointer user_data
)
61 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
63 return ops
->input_add(source
, condition
, func
, user_data
);
67 purple_input_remove(guint tag
)
69 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
71 return ops
->input_remove(tag
);
75 purple_input_get_error(int fd
, int *error
)
77 PurpleEventLoopUiOps
*ops
= purple_eventloop_get_ui_ops();
79 if (ops
->input_get_error
)
81 int ret
= ops
->input_get_error(fd
, error
);
90 return getsockopt(fd
, SOL_SOCKET
, SO_ERROR
, error
, &len
);
95 purple_eventloop_set_ui_ops(PurpleEventLoopUiOps
*ops
)
97 eventloop_ui_ops
= ops
;
100 PurpleEventLoopUiOps
*
101 purple_eventloop_get_ui_ops(void)
103 g_return_val_if_fail(eventloop_ui_ops
!= NULL
, NULL
);
105 return eventloop_ui_ops
;