1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
36 typedef struct _GTimeVal GTimeVal;
37 typedef struct _GSourceFuncs GSourceFuncs;
38 typedef struct _GMainLoop GMainLoop; /* Opaque */
47 gboolean (*prepare) (gpointer source_data,
48 GTimeVal *current_time,
51 gboolean (*check) (gpointer source_data,
52 GTimeVal *current_time,
54 gboolean (*dispatch) (gpointer source_data,
55 GTimeVal *dispatch_time,
57 GDestroyNotify destroy;
60 /* Standard priorities */
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
68 typedef gboolean (*GSourceFunc) (gpointer data);
70 /* Hooks for adding to the main loop */
71 guint g_source_add (gint priority,
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,
83 void g_get_current_time (GTimeVal *result);
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);
92 /* Run a single iteration of the mainloop. If block is FALSE,
95 gboolean g_main_iteration (gboolean may_block);
97 /* See if any events are pending */
98 gboolean g_main_pending (void);
100 /* Idles and timeouts */
101 guint g_timeout_add_full (gint priority,
103 GSourceFunc function,
105 GDestroyNotify notify);
106 guint g_timeout_add (guint interval,
107 GSourceFunc function,
109 guint g_idle_add (GSourceFunc function,
111 guint g_idle_add_full (gint priority,
112 GSourceFunc function,
114 GDestroyNotify destroy);
115 gboolean g_idle_remove_by_data (gpointer data);
119 * System-specific IO and main loop calls
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).
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.
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
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
141 typedef struct _GPollFD GPollFD;
142 typedef gint (*GPollFunc) (GPollFD *ufds,
152 void g_main_add_poll (GPollFD *fd,
154 void g_main_remove_poll (GPollFD *fd);
155 void g_main_set_poll_func (GPollFunc func);
159 /* Useful on other platforms, too? */
161 GPollFunc g_main_win32_get_poll_func (void);
167 #endif /* __G_MAIN_H__ */