#ifndef __G_MAIN_H__
#define __G_MAIN_H__
-#include <gslist.h>
-#include <gthread.h>
+#include <glib/gslist.h>
+#include <glib/gthread.h>
G_BEGIN_DECLS
typedef struct _GSourceFuncs GSourceFuncs;
typedef gboolean (*GSourceFunc) (gpointer data);
-
+typedef void (*GChildWatchFunc) (GPid pid,
+ gint status,
+ gpointer data);
struct _GSource
{
/*< private >*/
gint priority;
guint flags;
- guint id;
+ guint source_id;
GSList *poll_fds;
GSource *prev;
GSource *next;
+
+ gpointer reserved1;
+ gpointer reserved2;
};
struct _GSourceCallbackFuncs
void (*ref) (gpointer cb_data);
void (*unref) (gpointer cb_data);
void (*get) (gpointer cb_data,
+ GSource *source,
GSourceFunc *func,
gpointer *data);
};
+typedef void (*GSourceDummyMarshal) (void);
+
struct _GSourceFuncs
{
gboolean (*prepare) (GSource *source,
- gint *timeout);
+ gint *timeout_);
gboolean (*check) (GSource *source);
gboolean (*dispatch) (GSource *source,
GSourceFunc callback,
gpointer user_data);
- void (*destroy) (GSource *source);
+ void (*finalize) (GSource *source); /* Can be NULL */
+
+ /* For use by g_source_set_closure */
+ GSourceFunc closure_callback;
+ GSourceDummyMarshal closure_marshal; /* Really is of type GClosureMarshal */
};
/* Any definitions using GPollFD or GPollFunc are primarily
* WSAEventSelect to signal events when a SOCKET is readable).
*
* On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
- * indicate polling for messages. These message queue GPollFDs should
- * be added with the g_main_poll_win32_msg_add function.
+ * indicate polling for messages.
*
* But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
* (GTK) programs, as GDK itself wants to read messages and convert them
typedef struct _GPollFD GPollFD;
typedef gint (*GPollFunc) (GPollFD *ufds,
guint nfsd,
- gint timeout);
+ gint timeout_);
struct _GPollFD
{
/* GMainContext: */
-GMainContext *g_main_context_get (GThread *thread);
+GMainContext *g_main_context_new (void);
+void g_main_context_ref (GMainContext *context);
+void g_main_context_unref (GMainContext *context);
GMainContext *g_main_context_default (void);
gboolean g_main_context_iteration (GMainContext *context,
/* For implementation of legacy interfaces
*/
GSource *g_main_context_find_source_by_id (GMainContext *context,
- guint id);
+ guint source_id);
GSource *g_main_context_find_source_by_user_data (GMainContext *context,
gpointer user_data);
GSource *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
/* Low level functions for implementing custom main loops.
*/
+void g_main_context_wakeup (GMainContext *context);
+gboolean g_main_context_acquire (GMainContext *context);
+void g_main_context_release (GMainContext *context);
+gboolean g_main_context_wait (GMainContext *context,
+ GCond *cond,
+ GMutex *mutex);
+
gboolean g_main_context_prepare (GMainContext *context,
gint *priority);
gint g_main_context_query (GMainContext *context,
gint max_priority,
- gint *timeout,
+ gint *timeout_,
GPollFD *fds,
gint n_fds);
gint g_main_context_check (GMainContext *context,
void g_main_context_remove_poll (GMainContext *context,
GPollFD *fd);
+int g_main_depth (void);
+
/* GMainLoop: */
GMainLoop *g_main_loop_new (GMainContext *context,
gboolean is_running);
void g_main_loop_run (GMainLoop *loop);
void g_main_loop_quit (GMainLoop *loop);
-void g_main_loop_destroy (GMainLoop *loop);
+GMainLoop *g_main_loop_ref (GMainLoop *loop);
+void g_main_loop_unref (GMainLoop *loop);
gboolean g_main_loop_is_running (GMainLoop *loop);
+GMainContext *g_main_loop_get_context (GMainLoop *loop);
/* GSource: */
/* Specific source types
*/
-GSource *g_idle_source_new (void);
-GSource *g_timeout_source_new (guint interval);
+GSource *g_idle_source_new (void);
+GSource *g_child_watch_source_new (GPid pid);
+GSource *g_timeout_source_new (guint interval);
/* Miscellaneous functions
*/
/* ============== Compat main loop stuff ================== */
+#ifndef G_DISABLE_DEPRECATED
+
/* Legacy names for GMainLoop functions
*/
#define g_main_new(is_running) g_main_loop_new (NULL, is_running);
#define g_main_run(loop) g_main_loop_run(loop)
#define g_main_quit(loop) g_main_loop_quit(loop)
-#define g_main_destroy(loop) g_main_loop_destroy(loop)
+#define g_main_destroy(loop) g_main_loop_unref(loop)
#define g_main_is_running(loop) g_main_loop_is_running(loop)
-/* Source manipulation by ID */
-gboolean g_source_remove (guint tag);
-gboolean g_source_remove_by_user_data (gpointer user_data);
-gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
- gpointer user_data);
-
/* Functions to manipulate the default main loop
*/
#define g_main_set_poll_func(func) g_main_context_set_poll_func (NULL, func)
-/* Idles and timeouts */
-guint g_timeout_add_full (gint priority,
- guint interval,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify notify);
-guint g_timeout_add (guint interval,
- GSourceFunc function,
- gpointer data);
-guint g_idle_add (GSourceFunc function,
- gpointer data);
-guint g_idle_add_full (gint priority,
- GSourceFunc function,
- gpointer data,
- GDestroyNotify notify);
-gboolean g_idle_remove_by_data (gpointer data);
-
-#ifdef G_OS_WIN32
-
-/* This is used to add polling for Windows messages. GDK (GTK+) programs
- * should *not* use this.
- */
-void g_main_poll_win32_msg_add (gint priority,
- GPollFD *fd,
- guint hwnd);
-#endif /* G_OS_WIN32 */
+#endif /* G_DISABLE_DEPRECATED */
+
+/* Source manipulation by ID */
+gboolean g_source_remove (guint tag);
+gboolean g_source_remove_by_user_data (gpointer user_data);
+gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs,
+ gpointer user_data);
+
+/* Idles, child watchers and timeouts */
+guint g_timeout_add_full (gint priority,
+ guint interval,
+ GSourceFunc function,
+ gpointer data,
+ GDestroyNotify notify);
+guint g_timeout_add (guint interval,
+ GSourceFunc function,
+ gpointer data);
+guint g_child_watch_add_full (gint priority,
+ GPid pid,
+ GChildWatchFunc function,
+ gpointer data,
+ GDestroyNotify notify);
+guint g_child_watch_add (GPid pid,
+ GChildWatchFunc function,
+ gpointer data);
+guint g_idle_add (GSourceFunc function,
+ gpointer data);
+guint g_idle_add_full (gint priority,
+ GSourceFunc function,
+ gpointer data,
+ GDestroyNotify notify);
+gboolean g_idle_remove_by_data (gpointer data);
+
+/* Hook for GClosure / GSource integration. Don't touch */
+GLIB_VAR GSourceFuncs g_timeout_funcs;
+GLIB_VAR GSourceFuncs g_child_watch_funcs;
+GLIB_VAR GSourceFuncs g_idle_funcs;
G_END_DECLS