1 /* gmain.h - the GLib Main loop
2 * Copyright (C) 1998-2000 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
21 #error "Only <glib.h> can be included directly."
27 #include <glib/gpoll.h>
28 #include <glib/gslist.h>
29 #include <glib/gthread.h>
33 typedef struct _GMainContext GMainContext; /* Opaque */
34 typedef struct _GMainLoop GMainLoop; /* Opaque */
35 typedef struct _GSource GSource;
36 typedef struct _GSourceCallbackFuncs GSourceCallbackFuncs;
37 typedef struct _GSourceFuncs GSourceFuncs;
39 typedef gboolean (*GSourceFunc) (gpointer data);
40 typedef void (*GChildWatchFunc) (GPid pid,
46 gpointer callback_data;
47 GSourceCallbackFuncs *callback_funcs;
49 GSourceFuncs *source_funcs;
52 GMainContext *context;
67 struct _GSourceCallbackFuncs
69 void (*ref) (gpointer cb_data);
70 void (*unref) (gpointer cb_data);
71 void (*get) (gpointer cb_data,
77 typedef void (*GSourceDummyMarshal) (void);
81 gboolean (*prepare) (GSource *source,
83 gboolean (*check) (GSource *source);
84 gboolean (*dispatch) (GSource *source,
87 void (*finalize) (GSource *source); /* Can be NULL */
89 /* For use by g_source_set_closure */
90 GSourceFunc closure_callback;
91 GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
94 /* Standard priorities */
96 #define G_PRIORITY_HIGH -100
97 #define G_PRIORITY_DEFAULT 0
98 #define G_PRIORITY_HIGH_IDLE 100
99 #define G_PRIORITY_DEFAULT_IDLE 200
100 #define G_PRIORITY_LOW 300
104 GMainContext *g_main_context_new (void);
105 GMainContext *g_main_context_ref (GMainContext *context);
106 void g_main_context_unref (GMainContext *context);
107 GMainContext *g_main_context_default (void);
109 gboolean g_main_context_iteration (GMainContext *context,
111 gboolean g_main_context_pending (GMainContext *context);
113 /* For implementation of legacy interfaces
115 GSource *g_main_context_find_source_by_id (GMainContext *context,
117 GSource *g_main_context_find_source_by_user_data (GMainContext *context,
119 GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
123 /* Low level functions for implementing custom main loops.
125 void g_main_context_wakeup (GMainContext *context);
126 gboolean g_main_context_acquire (GMainContext *context);
127 void g_main_context_release (GMainContext *context);
128 gboolean g_main_context_is_owner (GMainContext *context);
129 gboolean g_main_context_wait (GMainContext *context,
133 gboolean g_main_context_prepare (GMainContext *context,
135 gint g_main_context_query (GMainContext *context,
140 gint g_main_context_check (GMainContext *context,
144 void g_main_context_dispatch (GMainContext *context);
146 void g_main_context_set_poll_func (GMainContext *context,
148 GPollFunc g_main_context_get_poll_func (GMainContext *context);
150 /* Low level functions for use by source implementations
152 void g_main_context_add_poll (GMainContext *context,
155 void g_main_context_remove_poll (GMainContext *context,
158 gint g_main_depth (void);
159 GSource *g_main_current_source (void);
161 /* GMainContexts for other threads
163 void g_main_context_push_thread_default (GMainContext *context);
164 void g_main_context_pop_thread_default (GMainContext *context);
165 GMainContext *g_main_context_get_thread_default (void);
169 GMainLoop *g_main_loop_new (GMainContext *context,
170 gboolean is_running);
171 void g_main_loop_run (GMainLoop *loop);
172 void g_main_loop_quit (GMainLoop *loop);
173 GMainLoop *g_main_loop_ref (GMainLoop *loop);
174 void g_main_loop_unref (GMainLoop *loop);
175 gboolean g_main_loop_is_running (GMainLoop *loop);
176 GMainContext *g_main_loop_get_context (GMainLoop *loop);
180 GSource *g_source_new (GSourceFuncs *source_funcs,
182 GSource *g_source_ref (GSource *source);
183 void g_source_unref (GSource *source);
185 guint g_source_attach (GSource *source,
186 GMainContext *context);
187 void g_source_destroy (GSource *source);
189 void g_source_set_priority (GSource *source,
191 gint g_source_get_priority (GSource *source);
192 void g_source_set_can_recurse (GSource *source,
193 gboolean can_recurse);
194 gboolean g_source_get_can_recurse (GSource *source);
195 guint g_source_get_id (GSource *source);
197 GMainContext *g_source_get_context (GSource *source);
199 void g_source_set_callback (GSource *source,
202 GDestroyNotify notify);
204 void g_source_set_funcs (GSource *source,
205 GSourceFuncs *funcs);
206 gboolean g_source_is_destroyed (GSource *source);
208 /* Used to implement g_source_connect_closure and internally*/
209 void g_source_set_callback_indirect (GSource *source,
210 gpointer callback_data,
211 GSourceCallbackFuncs *callback_funcs);
213 void g_source_add_poll (GSource *source,
215 void g_source_remove_poll (GSource *source,
218 void g_source_get_current_time (GSource *source,
221 /* void g_source_connect_closure (GSource *source,
225 /* Specific source types
227 GSource *g_idle_source_new (void);
228 GSource *g_child_watch_source_new (GPid pid);
229 GSource *g_timeout_source_new (guint interval);
230 GSource *g_timeout_source_new_seconds (guint interval);
232 /* Miscellaneous functions
234 void g_get_current_time (GTimeVal *result);
236 /* ============== Compat main loop stuff ================== */
238 #ifndef G_DISABLE_DEPRECATED
240 /* Legacy names for GMainLoop functions
242 #define g_main_new(is_running) g_main_loop_new (NULL, is_running);
243 #define g_main_run(loop) g_main_loop_run(loop)
244 #define g_main_quit(loop) g_main_loop_quit(loop)
245 #define g_main_destroy(loop) g_main_loop_unref(loop)
246 #define g_main_is_running(loop) g_main_loop_is_running(loop)
248 /* Functions to manipulate the default main loop
251 #define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block)
252 #define g_main_pending() g_main_context_pending (NULL)
254 #define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
256 #endif /* G_DISABLE_DEPRECATED */
258 /* Source manipulation by ID */
259 gboolean g_source_remove (guint tag);
260 gboolean g_source_remove_by_user_data (gpointer user_data);
261 gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
264 /* Idles, child watchers and timeouts */
265 guint g_timeout_add_full (gint priority,
267 GSourceFunc function,
269 GDestroyNotify notify);
270 guint g_timeout_add (guint interval,
271 GSourceFunc function,
273 guint g_timeout_add_seconds_full (gint priority,
275 GSourceFunc function,
277 GDestroyNotify notify);
278 guint g_timeout_add_seconds (guint interval,
279 GSourceFunc function,
281 guint g_child_watch_add_full (gint priority,
283 GChildWatchFunc function,
285 GDestroyNotify notify);
286 guint g_child_watch_add (GPid pid,
287 GChildWatchFunc function,
289 guint g_idle_add (GSourceFunc function,
291 guint g_idle_add_full (gint priority,
292 GSourceFunc function,
294 GDestroyNotify notify);
295 gboolean g_idle_remove_by_data (gpointer data);
297 /* Hook for GClosure / GSource integration. Don't touch */
298 GLIB_VAR GSourceFuncs g_timeout_funcs;
299 GLIB_VAR GSourceFuncs g_child_watch_funcs;
300 GLIB_VAR GSourceFuncs g_idle_funcs;
304 #endif /* __G_MAIN_H__ */