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 void g_source_set_name (GSource
*source
,
210 G_CONST_RETURN
char* g_source_get_name (GSource
*source
);
211 void g_source_set_name_by_id (guint tag
,
215 /* Used to implement g_source_connect_closure and internally*/
216 void g_source_set_callback_indirect (GSource
*source
,
217 gpointer callback_data
,
218 GSourceCallbackFuncs
*callback_funcs
);
220 void g_source_add_poll (GSource
*source
,
222 void g_source_remove_poll (GSource
*source
,
225 void g_source_get_current_time (GSource
*source
,
228 /* void g_source_connect_closure (GSource *source,
232 /* Specific source types
234 GSource
*g_idle_source_new (void);
235 GSource
*g_child_watch_source_new (GPid pid
);
236 GSource
*g_timeout_source_new (guint interval
);
237 GSource
*g_timeout_source_new_seconds (guint interval
);
239 /* Miscellaneous functions
241 void g_get_current_time (GTimeVal
*result
);
243 /* ============== Compat main loop stuff ================== */
245 #ifndef G_DISABLE_DEPRECATED
247 /* Legacy names for GMainLoop functions
249 #define g_main_new(is_running) g_main_loop_new (NULL, is_running);
250 #define g_main_run(loop) g_main_loop_run(loop)
251 #define g_main_quit(loop) g_main_loop_quit(loop)
252 #define g_main_destroy(loop) g_main_loop_unref(loop)
253 #define g_main_is_running(loop) g_main_loop_is_running(loop)
255 /* Functions to manipulate the default main loop
258 #define g_main_iteration(may_block) g_main_context_iteration (NULL, may_block)
259 #define g_main_pending() g_main_context_pending (NULL)
261 #define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
263 #endif /* G_DISABLE_DEPRECATED */
265 /* Source manipulation by ID */
266 gboolean
g_source_remove (guint tag
);
267 gboolean
g_source_remove_by_user_data (gpointer user_data
);
268 gboolean
g_source_remove_by_funcs_user_data (GSourceFuncs
*funcs
,
271 /* Idles, child watchers and timeouts */
272 guint
g_timeout_add_full (gint priority
,
274 GSourceFunc function
,
276 GDestroyNotify notify
);
277 guint
g_timeout_add (guint interval
,
278 GSourceFunc function
,
280 guint
g_timeout_add_seconds_full (gint priority
,
282 GSourceFunc function
,
284 GDestroyNotify notify
);
285 guint
g_timeout_add_seconds (guint interval
,
286 GSourceFunc function
,
288 guint
g_child_watch_add_full (gint priority
,
290 GChildWatchFunc function
,
292 GDestroyNotify notify
);
293 guint
g_child_watch_add (GPid pid
,
294 GChildWatchFunc function
,
296 guint
g_idle_add (GSourceFunc function
,
298 guint
g_idle_add_full (gint priority
,
299 GSourceFunc function
,
301 GDestroyNotify notify
);
302 gboolean
g_idle_remove_by_data (gpointer data
);
304 /* Hook for GClosure / GSource integration. Don't touch */
305 GLIB_VAR GSourceFuncs g_timeout_funcs
;
306 GLIB_VAR GSourceFuncs g_child_watch_funcs
;
307 GLIB_VAR GSourceFuncs g_idle_funcs
;
311 #endif /* __G_MAIN_H__ */