1 gmain.h |
1 /* gmain.h - the GLib Main loop |
|
2 * Copyright (C) 1998-2000 Red Hat, Inc. |
|
3 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the |
|
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
18 * Boston, MA 02111-1307, USA. |
|
19 */ |
|
20 |
|
21 #ifndef __G_MAIN_H__ |
|
22 #define __G_MAIN_H__ |
|
23 |
|
24 #include <_ansi.h> |
|
25 #include <glib/gslist.h> |
|
26 #include <glib/gthread.h> |
|
27 |
|
28 G_BEGIN_DECLS |
|
29 |
|
30 typedef struct _GMainContext GMainContext; /* Opaque */ |
|
31 typedef struct _GMainLoop GMainLoop; /* Opaque */ |
|
32 typedef struct _GSource GSource; |
|
33 typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs; |
|
34 typedef struct _GSourceFuncs GSourceFuncs; |
|
35 |
|
36 typedef gboolean (*GSourceFunc) (gpointer data); |
|
37 typedef void (*GChildWatchFunc) (GPid pid, |
|
38 gint status, |
|
39 gpointer data); |
|
40 struct _GSource |
|
41 { |
|
42 /*< private >*/ |
|
43 gpointer callback_data; |
|
44 GSourceCallbackFuncs *callback_funcs; |
|
45 |
|
46 GSourceFuncs *source_funcs; |
|
47 guint ref_count; |
|
48 |
|
49 GMainContext *context; |
|
50 |
|
51 gint priority; |
|
52 guint flags; |
|
53 guint source_id; |
|
54 |
|
55 GSList *poll_fds; |
|
56 |
|
57 GSource *prev; |
|
58 GSource *next; |
|
59 |
|
60 gpointer reserved1; |
|
61 gpointer reserved2; |
|
62 }; |
|
63 |
|
64 struct _GSourceCallbackFuncs |
|
65 { |
|
66 void (*ref) (gpointer cb_data); |
|
67 void (*unref) (gpointer cb_data); |
|
68 void (*get) (gpointer cb_data, |
|
69 GSource *source, |
|
70 GSourceFunc *func, |
|
71 gpointer *data); |
|
72 }; |
|
73 |
|
74 typedef void (*GSourceDummyMarshal) (void); |
|
75 |
|
76 struct _GSourceFuncs |
|
77 { |
|
78 gboolean (*prepare) (GSource *source, |
|
79 gint *timeout_); |
|
80 gboolean (*check) (GSource *source); |
|
81 gboolean (*dispatch) (GSource *source, |
|
82 GSourceFunc callback, |
|
83 gpointer user_data); |
|
84 void (*finalize) (GSource *source); /* Can be NULL */ |
|
85 |
|
86 /* For use by g_source_set_closure */ |
|
87 GSourceFunc closure_callback; |
|
88 GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */ |
|
89 }; |
|
90 |
|
91 /* Any definitions using GPollFD or GPollFunc are primarily |
|
92 * for Unix and not guaranteed to be the compatible on all |
|
93 * operating systems on which GLib runs. Right now, the |
|
94 * GLib does use these functions on Win32 as well, but interprets |
|
95 * them in a fairly different way than on Unix. If you use |
|
96 * these definitions, you are should be prepared to recode |
|
97 * for different operating systems. |
|
98 * |
|
99 * |
|
100 * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file |
|
101 * descriptor as provided by the C runtime) that can be used by |
|
102 * MsgWaitForMultipleObjects. This does *not* include file handles |
|
103 * from CreateFile, SOCKETs, nor pipe handles. (But you can use |
|
104 * WSAEventSelect to signal events when a SOCKET is readable). |
|
105 * |
|
106 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to |
|
107 * indicate polling for messages. |
|
108 * |
|
109 * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK |
|
110 * (GTK) programs, as GDK itself wants to read messages and convert them |
|
111 * to GDK events. |
|
112 * |
|
113 * So, unless you really know what you are doing, it's best not to try |
|
114 * to use the main loop polling stuff for your own needs on |
|
115 * Win32. It's really only written for the GIMP's needs so |
|
116 * far. |
|
117 */ |
|
118 typedef struct _GPollFD GPollFD; |
|
119 typedef gint (*GPollFunc) (GPollFD *ufds, |
|
120 guint nfsd, |
|
121 gint timeout_); |
|
122 |
|
123 struct _GPollFD |
|
124 { |
|
125 gint fd; |
|
126 gushort events; |
|
127 gushort revents; |
|
128 }; |
|
129 |
|
130 /* Standard priorities */ |
|
131 |
|
132 #define G_PRIORITY_HIGH -100 |
|
133 #define G_PRIORITY_DEFAULT 0 |
|
134 #define G_PRIORITY_HIGH_IDLE 100 |
|
135 #define G_PRIORITY_DEFAULT_IDLE 200 |
|
136 #define G_PRIORITY_LOW 300 |
|
137 |
|
138 /* GMainContext: */ |
|
139 |
|
140 IMPORT_C GMainContext *g_main_context_new (void); |
|
141 IMPORT_C GMainContext *g_main_context_ref (GMainContext *context); |
|
142 IMPORT_C void g_main_context_unref (GMainContext *context); |
|
143 IMPORT_C GMainContext *g_main_context_default (void); |
|
144 |
|
145 IMPORT_C gboolean g_main_context_iteration (GMainContext *context, |
|
146 gboolean may_block); |
|
147 IMPORT_C gboolean g_main_context_pending (GMainContext *context); |
|
148 |
|
149 /* For implementation of legacy interfaces |
|
150 */ |
|
151 IMPORT_C GSource *g_main_context_find_source_by_id (GMainContext *context, |
|
152 guint source_id); |
|
153 IMPORT_C GSource *g_main_context_find_source_by_user_data (GMainContext *context, |
|
154 gpointer user_data); |
|
155 IMPORT_C GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context, |
|
156 GSourceFuncs *funcs, |
|
157 gpointer user_data); |
|
158 |
|
159 /* Low level functions for implementing custom main loops. |
|
160 */ |
|
161 IMPORT_C void g_main_context_wakeup (GMainContext *context); |
|
162 IMPORT_C gboolean g_main_context_acquire (GMainContext *context); |
|
163 IMPORT_C void g_main_context_release (GMainContext *context); |
|
164 IMPORT_C gboolean g_main_context_is_owner (GMainContext *context); |
|
165 IMPORT_C gboolean g_main_context_wait (GMainContext *context, |
|
166 GCond *cond, |
|
167 GMutex *mutex); |
|
168 |
|
169 IMPORT_C gboolean g_main_context_prepare (GMainContext *context, |
|
170 gint *priority); |
|
171 IMPORT_C gint g_main_context_query (GMainContext *context, |
|
172 gint max_priority, |
|
173 gint *timeout_, |
|
174 GPollFD *fds, |
|
175 gint n_fds); |
|
176 IMPORT_C gint g_main_context_check (GMainContext *context, |
|
177 gint max_priority, |
|
178 GPollFD *fds, |
|
179 gint n_fds); |
|
180 IMPORT_C void g_main_context_dispatch (GMainContext *context); |
|
181 |
|
182 IMPORT_C void g_main_context_set_poll_func (GMainContext *context, |
|
183 GPollFunc func); |
|
184 IMPORT_C GPollFunc g_main_context_get_poll_func (GMainContext *context); |
|
185 |
|
186 /* Low level functions for use by source implementations |
|
187 */ |
|
188 IMPORT_C void g_main_context_add_poll (GMainContext *context, |
|
189 GPollFD *fd, |
|
190 gint priority); |
|
191 IMPORT_C void g_main_context_remove_poll (GMainContext *context, |
|
192 GPollFD *fd); |
|
193 |
|
194 IMPORT_C int g_main_depth (void); |
|
195 |
|
196 /* GMainLoop: */ |
|
197 |
|
198 IMPORT_C GMainLoop *g_main_loop_new (GMainContext *context, |
|
199 gboolean is_running); |
|
200 IMPORT_C void g_main_loop_run (GMainLoop *loop); |
|
201 IMPORT_C void g_main_loop_quit (GMainLoop *loop); |
|
202 IMPORT_C GMainLoop *g_main_loop_ref (GMainLoop *loop); |
|
203 IMPORT_C void g_main_loop_unref (GMainLoop *loop); |
|
204 IMPORT_C gboolean g_main_loop_is_running (GMainLoop *loop); |
|
205 IMPORT_C GMainContext *g_main_loop_get_context (GMainLoop *loop); |
|
206 |
|
207 /* GSource: */ |
|
208 |
|
209 IMPORT_C GSource *g_source_new (GSourceFuncs *source_funcs, |
|
210 guint struct_size); |
|
211 IMPORT_C GSource *g_source_ref (GSource *source); |
|
212 IMPORT_C void g_source_unref (GSource *source); |
|
213 |
|
214 IMPORT_C guint g_source_attach (GSource *source, |
|
215 GMainContext *context); |
|
216 IMPORT_C void g_source_destroy (GSource *source); |
|
217 |
|
218 IMPORT_C void g_source_set_priority (GSource *source, |
|
219 gint priority); |
|
220 IMPORT_C gint g_source_get_priority (GSource *source); |
|
221 IMPORT_C void g_source_set_can_recurse (GSource *source, |
|
222 gboolean can_recurse); |
|
223 IMPORT_C gboolean g_source_get_can_recurse (GSource *source); |
|
224 IMPORT_C guint g_source_get_id (GSource *source); |
|
225 |
|
226 IMPORT_C GMainContext *g_source_get_context (GSource *source); |
|
227 |
|
228 IMPORT_C void g_source_set_callback (GSource *source, |
|
229 GSourceFunc func, |
|
230 gpointer data, |
|
231 GDestroyNotify notify); |
|
232 |
|
233 |
|
234 /* Used to implement g_source_connect_closure and internally*/ |
|
235 IMPORT_C void g_source_set_callback_indirect (GSource *source, |
|
236 gpointer callback_data, |
|
237 GSourceCallbackFuncs *callback_funcs); |
|
238 |
|
239 IMPORT_C void g_source_add_poll (GSource *source, |
|
240 GPollFD *fd); |
|
241 IMPORT_C void g_source_remove_poll (GSource *source, |
|
242 GPollFD *fd); |
|
243 |
|
244 IMPORT_C void g_source_get_current_time (GSource *source, |
|
245 GTimeVal *timeval); |
|
246 |
|
247 /* void g_source_connect_closure (GSource *source, |
|
248 GClosure *closure); |
|
249 */ |
|
250 |
|
251 /* Specific source types |
|
252 */ |
|
253 IMPORT_C GSource *g_idle_source_new (void); |
|
254 IMPORT_C GSource *g_child_watch_source_new (GPid pid); |
|
255 IMPORT_C GSource *g_timeout_source_new (guint interval); |
|
256 |
|
257 /* Miscellaneous functions |
|
258 */ |
|
259 IMPORT_C void g_get_current_time (GTimeVal *result); |
|
260 |
|
261 /* ============== Compat main loop stuff ================== */ |
|
262 |
|
263 #ifndef G_DISABLE_DEPRECATED |
|
264 |
|
265 /* Legacy names for GMainLoop functions |
|
266 */ |
|
267 #define g_main_new(is_running) g_main_loop_new (NULL, is_running); |
|
268 #define g_main_run(loop) g_main_loop_run(loop) |
|
269 #define g_main_quit(loop) g_main_loop_quit(loop) |
|
270 #define g_main_destroy(loop) g_main_loop_unref(loop) |
|
271 #define g_main_is_running(loop) g_main_loop_is_running(loop) |
|
272 |
|
273 /* Functions to manipulate the default main loop |
|
274 */ |
|
275 |
|
276 #define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block) |
|
277 #define g_main_pending() g_main_context_pending (NULL) |
|
278 |
|
279 #define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func) |
|
280 |
|
281 #endif /* G_DISABLE_DEPRECATED */ |
|
282 |
|
283 /* Source manipulation by ID */ |
|
284 IMPORT_C gboolean g_source_remove (guint tag); |
|
285 IMPORT_C gboolean g_source_remove_by_user_data (gpointer user_data); |
|
286 IMPORT_C gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs, |
|
287 gpointer user_data); |
|
288 |
|
289 /* Idles, child watchers and timeouts */ |
|
290 IMPORT_C guint g_timeout_add_full (gint priority, |
|
291 guint interval, |
|
292 GSourceFunc function, |
|
293 gpointer data, |
|
294 GDestroyNotify notify); |
|
295 IMPORT_C guint g_timeout_add (guint interval, |
|
296 GSourceFunc function, |
|
297 gpointer data); |
|
298 IMPORT_C guint g_child_watch_add_full (gint priority, |
|
299 GPid pid, |
|
300 GChildWatchFunc function, |
|
301 gpointer data, |
|
302 GDestroyNotify notify); |
|
303 IMPORT_C guint g_child_watch_add (GPid pid, |
|
304 GChildWatchFunc function, |
|
305 gpointer data); |
|
306 IMPORT_C guint g_idle_add (GSourceFunc function, |
|
307 gpointer data); |
|
308 IMPORT_C guint g_idle_add_full (gint priority, |
|
309 GSourceFunc function, |
|
310 gpointer data, |
|
311 GDestroyNotify notify); |
|
312 IMPORT_C gboolean g_idle_remove_by_data (gpointer data); |
|
313 |
|
314 /* Hook for GClosure / GSource integration. Don't touch */ |
|
315 #ifdef __SYMBIAN32__ |
|
316 IMPORT_C GSourceFuncs * _g_timeout_funcs(); |
|
317 #endif /*__SYMBIAN32__ */ |
|
318 GLIB_VAR GSourceFuncs g_timeout_funcs; |
|
319 #ifdef __SYMBIAN32__ |
|
320 IMPORT_C GSourceFuncs * _g_child_watch_funcs(); |
|
321 #endif /* __SYMBIAN32__ */ |
|
322 GLIB_VAR GSourceFuncs g_child_watch_funcs; |
|
323 #ifdef __SYMBIAN32__ |
|
324 IMPORT_C GSourceFuncs * _g_idle_funcs(); |
|
325 #endif/* __SYMBIAN32__ */ |
|
326 GLIB_VAR GSourceFuncs g_idle_funcs; |
|
327 |
|
328 G_END_DECLS |
|
329 |
|
330 #endif /* __G_MAIN_H__ */ |