Split glib.h into many header files mostly according to the resp.
[platform/upstream/glib.git] / gmain.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_MAIN_H__
28 #define __G_MAIN_H__
29
30 #include <gtypes.h>
31
32 G_BEGIN_DECLS
33
34 /* Main loop
35  */
36 typedef struct _GTimeVal        GTimeVal;
37 typedef struct _GSourceFuncs    GSourceFuncs;
38 typedef struct _GMainLoop       GMainLoop;      /* Opaque */
39
40 struct _GTimeVal
41 {
42   glong tv_sec;
43   glong tv_usec;
44 };
45 struct _GSourceFuncs
46 {
47   gboolean (*prepare)  (gpointer  source_data,
48                         GTimeVal *current_time,
49                         gint     *timeout,
50                         gpointer  user_data);
51   gboolean (*check)    (gpointer  source_data,
52                         GTimeVal *current_time,
53                         gpointer  user_data);
54   gboolean (*dispatch) (gpointer  source_data,
55                         GTimeVal *dispatch_time,
56                         gpointer  user_data);
57   GDestroyNotify destroy;
58 };
59
60 /* Standard priorities */
61
62 #define G_PRIORITY_HIGH            -100
63 #define G_PRIORITY_DEFAULT          0
64 #define G_PRIORITY_HIGH_IDLE        100
65 #define G_PRIORITY_DEFAULT_IDLE     200
66 #define G_PRIORITY_LOW              300
67
68 typedef gboolean (*GSourceFunc) (gpointer data);
69
70 /* Hooks for adding to the main loop */
71 guint    g_source_add                        (gint           priority,
72                                               gboolean       can_recurse,
73                                               GSourceFuncs  *funcs,
74                                               gpointer       source_data,
75                                               gpointer       user_data,
76                                               GDestroyNotify notify);
77 gboolean g_source_remove                     (guint          tag);
78 gboolean g_source_remove_by_user_data        (gpointer       user_data);
79 gboolean g_source_remove_by_source_data      (gpointer       source_data);
80 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
81                                               gpointer       user_data);
82
83 void g_get_current_time                 (GTimeVal       *result);
84
85 /* Running the main loop */
86 GMainLoop*      g_main_new              (gboolean        is_running);
87 void            g_main_run              (GMainLoop      *loop);
88 void            g_main_quit             (GMainLoop      *loop);
89 void            g_main_destroy          (GMainLoop      *loop);
90 gboolean        g_main_is_running       (GMainLoop      *loop);
91
92 /* Run a single iteration of the mainloop. If block is FALSE,
93  * will never block
94  */
95 gboolean        g_main_iteration        (gboolean       may_block);
96
97 /* See if any events are pending */
98 gboolean        g_main_pending          (void);
99
100 /* Idles and timeouts */
101 guint           g_timeout_add_full      (gint           priority,
102                                          guint          interval,
103                                          GSourceFunc    function,
104                                          gpointer       data,
105                                          GDestroyNotify notify);
106 guint           g_timeout_add           (guint          interval,
107                                          GSourceFunc    function,
108                                          gpointer       data);
109 guint           g_idle_add              (GSourceFunc    function,
110                                          gpointer       data);
111 guint           g_idle_add_full         (gint           priority,
112                                          GSourceFunc    function,
113                                          gpointer       data,
114                                          GDestroyNotify destroy);
115 gboolean        g_idle_remove_by_data   (gpointer       data);
116
117 /* GPollFD
118  *
119  * System-specific IO and main loop calls
120  *
121  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
122  * descriptor as provided by the C runtime) that can be used by
123  * MsgWaitForMultipleObjects. This does *not* include file handles
124  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
125  * WSAEventSelect to signal events when a SOCKET is readable).
126  *
127  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
128  * indicate polling for messages. These message queue GPollFDs should
129  * be added with the g_main_poll_win32_msg_add function.
130  *
131  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
132  * (GTK) programs, as GDK itself wants to read messages and convert them
133  * to GDK events.
134  *
135  * So, unless you really know what you are doing, it's best not to try
136  * to use the main loop polling stuff for your own needs on
137  * Win32. It's really only written for the GIMP's needs so
138  * far.
139  */
140
141 typedef struct _GPollFD GPollFD;
142 typedef gint    (*GPollFunc)    (GPollFD *ufds,
143                                  guint    nfsd,
144                                  gint     timeout);
145 struct _GPollFD
146 {
147   gint          fd;
148   gushort       events;
149   gushort       revents;
150 };
151
152 void        g_main_add_poll          (GPollFD    *fd,
153                                       gint        priority);
154 void        g_main_remove_poll       (GPollFD    *fd);
155 void        g_main_set_poll_func     (GPollFunc   func);
156
157 #ifdef G_OS_WIN32
158
159 /* Useful on other platforms, too? */
160
161 GPollFunc   g_main_win32_get_poll_func (void);
162
163 #endif
164
165 G_END_DECLS
166
167 #endif /* __G_MAIN_H__ */
168