Add gdbus-proxy-well-known-name to the ignore file
[glib.git] / glib / gmain.h
blob3012cd17205724841af8df18c0bff238934bb0d0
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."
22 #endif
24 #ifndef __G_MAIN_H__
25 #define __G_MAIN_H__
27 #include <glib/gpoll.h>
28 #include <glib/gslist.h>
29 #include <glib/gthread.h>
31 G_BEGIN_DECLS
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,
41 gint status,
42 gpointer data);
43 struct _GSource
45 /*< private >*/
46 gpointer callback_data;
47 GSourceCallbackFuncs *callback_funcs;
49 GSourceFuncs *source_funcs;
50 guint ref_count;
52 GMainContext *context;
54 gint priority;
55 guint flags;
56 guint source_id;
58 GSList *poll_fds;
60 GSource *prev;
61 GSource *next;
63 char *name;
64 gpointer reserved2;
67 struct _GSourceCallbackFuncs
69 void (*ref) (gpointer cb_data);
70 void (*unref) (gpointer cb_data);
71 void (*get) (gpointer cb_data,
72 GSource *source,
73 GSourceFunc *func,
74 gpointer *data);
77 typedef void (*GSourceDummyMarshal) (void);
79 struct _GSourceFuncs
81 gboolean (*prepare) (GSource *source,
82 gint *timeout_);
83 gboolean (*check) (GSource *source);
84 gboolean (*dispatch) (GSource *source,
85 GSourceFunc callback,
86 gpointer user_data);
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
102 /* GMainContext: */
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,
110 gboolean may_block);
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,
116 guint source_id);
117 GSource *g_main_context_find_source_by_user_data (GMainContext *context,
118 gpointer user_data);
119 GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
120 GSourceFuncs *funcs,
121 gpointer user_data);
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,
130 GCond *cond,
131 GMutex *mutex);
133 gboolean g_main_context_prepare (GMainContext *context,
134 gint *priority);
135 gint g_main_context_query (GMainContext *context,
136 gint max_priority,
137 gint *timeout_,
138 GPollFD *fds,
139 gint n_fds);
140 gint g_main_context_check (GMainContext *context,
141 gint max_priority,
142 GPollFD *fds,
143 gint n_fds);
144 void g_main_context_dispatch (GMainContext *context);
146 void g_main_context_set_poll_func (GMainContext *context,
147 GPollFunc func);
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,
153 GPollFD *fd,
154 gint priority);
155 void g_main_context_remove_poll (GMainContext *context,
156 GPollFD *fd);
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);
167 /* GMainLoop: */
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);
178 /* GSource: */
180 GSource *g_source_new (GSourceFuncs *source_funcs,
181 guint struct_size);
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,
190 gint priority);
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,
200 GSourceFunc func,
201 gpointer data,
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,
209 const char *name);
210 G_CONST_RETURN char* g_source_get_name (GSource *source);
211 void g_source_set_name_by_id (guint tag,
212 const char *name);
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,
221 GPollFD *fd);
222 void g_source_remove_poll (GSource *source,
223 GPollFD *fd);
225 void g_source_get_current_time (GSource *source,
226 GTimeVal *timeval);
228 /* void g_source_connect_closure (GSource *source,
229 GClosure *closure);
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,
269 gpointer user_data);
271 /* Idles, child watchers and timeouts */
272 guint g_timeout_add_full (gint priority,
273 guint interval,
274 GSourceFunc function,
275 gpointer data,
276 GDestroyNotify notify);
277 guint g_timeout_add (guint interval,
278 GSourceFunc function,
279 gpointer data);
280 guint g_timeout_add_seconds_full (gint priority,
281 guint interval,
282 GSourceFunc function,
283 gpointer data,
284 GDestroyNotify notify);
285 guint g_timeout_add_seconds (guint interval,
286 GSourceFunc function,
287 gpointer data);
288 guint g_child_watch_add_full (gint priority,
289 GPid pid,
290 GChildWatchFunc function,
291 gpointer data,
292 GDestroyNotify notify);
293 guint g_child_watch_add (GPid pid,
294 GChildWatchFunc function,
295 gpointer data);
296 guint g_idle_add (GSourceFunc function,
297 gpointer data);
298 guint g_idle_add_full (gint priority,
299 GSourceFunc function,
300 gpointer data,
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;
309 G_END_DECLS
311 #endif /* __G_MAIN_H__ */