Minor doc clarification
[platform/upstream/glib.git] / glib / gmain.h
1 /* gmain.h - the GLib Main loop
2  * Copyright (C) 1998-2000 Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
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
23
24 #ifndef __G_MAIN_H__
25 #define __G_MAIN_H__
26
27 #include <glib/gpoll.h>
28 #include <glib/gslist.h>
29 #include <glib/gthread.h>
30
31 G_BEGIN_DECLS
32
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;
38
39 typedef gboolean (*GSourceFunc)       (gpointer data);
40 typedef void     (*GChildWatchFunc)   (GPid     pid,
41                                        gint     status,
42                                        gpointer data);
43 struct _GSource
44 {
45   /*< private >*/
46   gpointer callback_data;
47   GSourceCallbackFuncs *callback_funcs;
48
49   GSourceFuncs *source_funcs;
50   guint ref_count;
51
52   GMainContext *context;
53
54   gint priority;
55   guint flags;
56   guint source_id;
57
58   GSList *poll_fds;
59   
60   GSource *prev;
61   GSource *next;
62
63   gpointer reserved1;
64   gpointer reserved2;
65 };
66
67 struct _GSourceCallbackFuncs
68 {
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);
75 };
76
77 typedef void (*GSourceDummyMarshal) (void);
78
79 struct _GSourceFuncs
80 {
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 */
88
89   /* For use by g_source_set_closure */
90   GSourceFunc     closure_callback;        
91   GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
92 };
93
94 /* Standard priorities */
95
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
101
102 /* GMainContext: */
103
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);
108
109 gboolean      g_main_context_iteration (GMainContext *context,
110                                         gboolean      may_block);
111 gboolean      g_main_context_pending   (GMainContext *context);
112
113 /* For implementation of legacy interfaces
114  */
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);
122
123 /* Low level functions for implementing custom main loops.
124  */
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);
132
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);
145
146 void     g_main_context_set_poll_func (GMainContext *context,
147                                        GPollFunc     func);
148 GPollFunc g_main_context_get_poll_func (GMainContext *context);
149
150 /* Low level functions for use by source implementations
151  */
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);
157
158 gint     g_main_depth               (void);
159 GSource *g_main_current_source      (void);
160
161 /* GMainContexts for other threads
162  */
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);
166
167 /* GMainLoop: */
168
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);
177
178 /* GSource: */
179
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);
184
185 guint    g_source_attach          (GSource        *source,
186                                    GMainContext   *context);
187 void     g_source_destroy         (GSource        *source);
188
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);
196
197 GMainContext *g_source_get_context (GSource       *source);
198
199 void     g_source_set_callback    (GSource        *source,
200                                    GSourceFunc     func,
201                                    gpointer        data,
202                                    GDestroyNotify  notify);
203
204 void     g_source_set_funcs       (GSource        *source,
205                                    GSourceFuncs   *funcs);
206 gboolean g_source_is_destroyed    (GSource        *source);
207
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);
212
213 void     g_source_add_poll         (GSource        *source,
214                                     GPollFD        *fd);
215 void     g_source_remove_poll      (GSource        *source,
216                                     GPollFD        *fd);
217
218 void     g_source_get_current_time (GSource        *source,
219                                     GTimeVal       *timeval);
220
221  /* void g_source_connect_closure (GSource        *source,
222                                   GClosure       *closure);
223  */
224
225 /* Specific source types
226  */
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);
231
232 /* Miscellaneous functions
233  */
234 void g_get_current_time                 (GTimeVal       *result);
235
236 /* ============== Compat main loop stuff ================== */
237
238 #ifndef G_DISABLE_DEPRECATED
239
240 /* Legacy names for GMainLoop functions
241  */
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)
247
248 /* Functions to manipulate the default main loop
249  */
250
251 #define g_main_iteration(may_block) g_main_context_iteration      (NULL, may_block)
252 #define g_main_pending()            g_main_context_pending        (NULL)
253
254 #define g_main_set_poll_func(func)   g_main_context_set_poll_func (NULL, func)
255
256 #endif /* G_DISABLE_DEPRECATED */
257
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,
262                                               gpointer       user_data);
263
264 /* Idles, child watchers and timeouts */
265 guint    g_timeout_add_full         (gint            priority,
266                                      guint           interval,
267                                      GSourceFunc     function,
268                                      gpointer        data,
269                                      GDestroyNotify  notify);
270 guint    g_timeout_add              (guint           interval,
271                                      GSourceFunc     function,
272                                      gpointer        data);
273 guint    g_timeout_add_seconds_full (gint            priority,
274                                      guint           interval,
275                                      GSourceFunc     function,
276                                      gpointer        data,
277                                      GDestroyNotify  notify);
278 guint    g_timeout_add_seconds      (guint           interval,
279                                      GSourceFunc     function,
280                                      gpointer        data);
281 guint    g_child_watch_add_full     (gint            priority,
282                                      GPid            pid,
283                                      GChildWatchFunc function,
284                                      gpointer        data,
285                                      GDestroyNotify  notify);
286 guint    g_child_watch_add          (GPid            pid,
287                                      GChildWatchFunc function,
288                                      gpointer        data);
289 guint    g_idle_add                 (GSourceFunc     function,
290                                      gpointer        data);
291 guint    g_idle_add_full            (gint            priority,
292                                      GSourceFunc     function,
293                                      gpointer        data,
294                                      GDestroyNotify  notify);
295 gboolean g_idle_remove_by_data      (gpointer        data);
296
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;
301
302 G_END_DECLS
303
304 #endif /* __G_MAIN_H__ */