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.
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.
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.
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.
25 #include <glib/gslist.h>
26 #include <glib/gthread.h>
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;
36 typedef gboolean (*GSourceFunc) (gpointer data);
37 typedef void (*GChildWatchFunc) (GPid pid,
43 gpointer callback_data;
44 GSourceCallbackFuncs *callback_funcs;
46 GSourceFuncs *source_funcs;
49 GMainContext *context;
64 struct _GSourceCallbackFuncs
66 void (*ref) (gpointer cb_data);
67 void (*unref) (gpointer cb_data);
68 void (*get) (gpointer cb_data,
74 typedef void (*GSourceDummyMarshal) (void);
78 gboolean (*prepare) (GSource *source,
80 gboolean (*check) (GSource *source);
81 gboolean (*dispatch) (GSource *source,
84 void (*finalize) (GSource *source); /* Can be NULL */
86 /* For use by g_source_set_closure */
87 GSourceFunc closure_callback;
88 GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
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.
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).
106 * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
107 * indicate polling for messages.
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
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
118 typedef struct _GPollFD GPollFD;
119 typedef gint (*GPollFunc) (GPollFD *ufds,
130 /* Standard priorities */
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
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);
145 IMPORT_C gboolean g_main_context_iteration (GMainContext *context,
147 IMPORT_C gboolean g_main_context_pending (GMainContext *context);
149 /* For implementation of legacy interfaces
151 IMPORT_C GSource *g_main_context_find_source_by_id (GMainContext *context,
153 IMPORT_C GSource *g_main_context_find_source_by_user_data (GMainContext *context,
155 IMPORT_C GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
159 /* Low level functions for implementing custom main loops.
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,
169 IMPORT_C gboolean g_main_context_prepare (GMainContext *context,
171 IMPORT_C gint g_main_context_query (GMainContext *context,
176 IMPORT_C gint g_main_context_check (GMainContext *context,
180 IMPORT_C void g_main_context_dispatch (GMainContext *context);
182 IMPORT_C void g_main_context_set_poll_func (GMainContext *context,
184 IMPORT_C GPollFunc g_main_context_get_poll_func (GMainContext *context);
186 /* Low level functions for use by source implementations
188 IMPORT_C void g_main_context_add_poll (GMainContext *context,
191 IMPORT_C void g_main_context_remove_poll (GMainContext *context,
194 IMPORT_C int g_main_depth (void);
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);
209 IMPORT_C GSource *g_source_new (GSourceFuncs *source_funcs,
211 IMPORT_C GSource *g_source_ref (GSource *source);
212 IMPORT_C void g_source_unref (GSource *source);
214 IMPORT_C guint g_source_attach (GSource *source,
215 GMainContext *context);
216 IMPORT_C void g_source_destroy (GSource *source);
218 IMPORT_C void g_source_set_priority (GSource *source,
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);
226 IMPORT_C GMainContext *g_source_get_context (GSource *source);
228 IMPORT_C void g_source_set_callback (GSource *source,
231 GDestroyNotify notify);
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);
239 IMPORT_C void g_source_add_poll (GSource *source,
241 IMPORT_C void g_source_remove_poll (GSource *source,
244 IMPORT_C void g_source_get_current_time (GSource *source,
247 /* void g_source_connect_closure (GSource *source,
251 /* Specific source types
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);
257 /* Miscellaneous functions
259 IMPORT_C void g_get_current_time (GTimeVal *result);
261 /* ============== Compat main loop stuff ================== */
263 #ifndef G_DISABLE_DEPRECATED
265 /* Legacy names for GMainLoop functions
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)
273 /* Functions to manipulate the default main loop
276 #define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block)
277 #define g_main_pending() g_main_context_pending (NULL)
279 #define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
281 #endif /* G_DISABLE_DEPRECATED */
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,
289 /* Idles, child watchers and timeouts */
290 IMPORT_C guint g_timeout_add_full (gint priority,
292 GSourceFunc function,
294 GDestroyNotify notify);
295 IMPORT_C guint g_timeout_add (guint interval,
296 GSourceFunc function,
298 IMPORT_C guint g_child_watch_add_full (gint priority,
300 GChildWatchFunc function,
302 GDestroyNotify notify);
303 IMPORT_C guint g_child_watch_add (GPid pid,
304 GChildWatchFunc function,
306 IMPORT_C guint g_idle_add (GSourceFunc function,
308 IMPORT_C guint g_idle_add_full (gint priority,
309 GSourceFunc function,
311 GDestroyNotify notify);
312 IMPORT_C gboolean g_idle_remove_by_data (gpointer data);
314 /* Hook for GClosure / GSource integration. Don't touch */
316 IMPORT_C GSourceFuncs * _g_timeout_funcs();
317 #endif /*__SYMBIAN32__ */
318 GLIB_VAR GSourceFuncs g_timeout_funcs;
320 IMPORT_C GSourceFuncs * _g_child_watch_funcs();
321 #endif /* __SYMBIAN32__ */
322 GLIB_VAR GSourceFuncs g_child_watch_funcs;
324 IMPORT_C GSourceFuncs * _g_idle_funcs();
325 #endif/* __SYMBIAN32__ */
326 GLIB_VAR GSourceFuncs g_idle_funcs;
330 #endif /* __G_MAIN_H__ */