gmain.h

Go to the documentation of this file.
00001 /* gmain.h - the GLib Main loop
00002  * Copyright (C) 1998-2000 Red Hat, Inc.
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef __G_MAIN_H__
00021 #define __G_MAIN_H__
00022 
00023 #include <gslist.h>
00024 #include <gthread.h>
00025 
00026 G_BEGIN_DECLS
00027 
00028 typedef struct _GMainContext            GMainContext;   /* Opaque */
00029 typedef struct _GMainLoop               GMainLoop;      /* Opaque */
00030 typedef struct _GSource                 GSource;
00031 typedef struct _GSourceCallbackFuncs    GSourceCallbackFuncs;
00032 typedef struct _GSourceFuncs            GSourceFuncs;
00033 
00034 typedef gboolean (*GSourceFunc)       (gpointer data);
00035 
00036 struct _GSource
00037 {
00038   /*< private >*/
00039   gpointer callback_data;
00040   GSourceCallbackFuncs *callback_funcs;
00041 
00042   GSourceFuncs *source_funcs;
00043   guint ref_count;
00044 
00045   GMainContext *context;
00046 
00047   gint priority;
00048   guint flags;
00049   guint id;
00050 
00051   GSList *poll_fds;
00052   
00053   GSource *prev;
00054   GSource *next;
00055 };
00056 
00057 struct _GSourceCallbackFuncs
00058 {
00059   void (*ref)   (gpointer     cb_data);
00060   void (*unref) (gpointer     cb_data);
00061   void (*get)   (gpointer     cb_data,
00062                  GSourceFunc *func,
00063                  gpointer    *data);
00064 };
00065 
00066 struct _GSourceFuncs
00067 {
00068   gboolean (*prepare)  (GSource    *source,
00069                         gint       *timeout);
00070   gboolean (*check)    (GSource    *source);
00071   gboolean (*dispatch) (GSource    *source,
00072                         GSourceFunc callback,
00073                         gpointer    user_data);
00074   void     (*destroy)  (GSource    *source); /* Can be NULL */
00075 };
00076 
00077 /* Any definitions using GPollFD or GPollFunc are primarily
00078  * for Unix and not guaranteed to be the compatible on all
00079  * operating systems on which GLib runs. Right now, the
00080  * GLib does use these functions on Win32 as well, but interprets
00081  * them in a fairly different way than on Unix. If you use
00082  * these definitions, you are should be prepared to recode
00083  * for different operating systems.
00084  *
00085  *
00086  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
00087  * descriptor as provided by the C runtime) that can be used by
00088  * MsgWaitForMultipleObjects. This does *not* include file handles
00089  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
00090  * WSAEventSelect to signal events when a SOCKET is readable).
00091  *
00092  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
00093  * indicate polling for messages. These message queue GPollFDs should
00094  * be added with the g_main_poll_win32_msg_add function.
00095  *
00096  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
00097  * (GTK) programs, as GDK itself wants to read messages and convert them
00098  * to GDK events.
00099  *
00100  * So, unless you really know what you are doing, it's best not to try
00101  * to use the main loop polling stuff for your own needs on
00102  * Win32. It's really only written for the GIMP's needs so
00103  * far.
00104  */
00105 typedef struct _GPollFD GPollFD;
00106 typedef gint    (*GPollFunc)    (GPollFD *ufds,
00107                                  guint    nfsd,
00108                                  gint     timeout);
00109 
00110 struct _GPollFD
00111 {
00112   gint          fd;
00113   gushort       events;
00114   gushort       revents;
00115 };
00116 
00117 /* Standard priorities */
00118 
00119 #define G_PRIORITY_HIGH            -100
00120 #define G_PRIORITY_DEFAULT          0
00121 #define G_PRIORITY_HIGH_IDLE        100
00122 #define G_PRIORITY_DEFAULT_IDLE     200
00123 #define G_PRIORITY_LOW              300
00124 
00125 /* GMainContext: */
00126 
00127 GMainContext *g_main_context_get       (GThread      *thread);
00128 GMainContext *g_main_context_default   (void);
00129 
00130 gboolean      g_main_context_iteration (GMainContext *context,
00131                                         gboolean      may_block);
00132 gboolean      g_main_context_pending   (GMainContext *context);
00133 
00134 /* For implementation of legacy interfaces
00135  */
00136 GSource      *g_main_context_find_source_by_id              (GMainContext *context,
00137                                                              guint         id);
00138 GSource      *g_main_context_find_source_by_user_data       (GMainContext *context,
00139                                                              gpointer      user_data);
00140 GSource      *g_main_context_find_source_by_funcs_user_data (GMainContext *context,
00141                                                              GSourceFuncs *funcs,
00142                                                              gpointer      user_data);
00143 
00144 /* Low level functions for implementing custom main loops.
00145  */
00146 gboolean g_main_context_prepare  (GMainContext *context,
00147                                   gint         *priority);
00148 gint     g_main_context_query    (GMainContext *context,
00149                                   gint          max_priority,
00150                                   gint         *timeout,
00151                                   GPollFD      *fds,
00152                                   gint          n_fds);
00153 gint     g_main_context_check    (GMainContext *context,
00154                                   gint          max_priority,
00155                                   GPollFD      *fds,
00156                                   gint          n_fds);
00157 void     g_main_context_dispatch (GMainContext *context);
00158 
00159 void      g_main_context_set_poll_func (GMainContext *context,
00160                                         GPollFunc     func);
00161 GPollFunc g_main_context_get_poll_func (GMainContext *context);
00162 
00163 /* Low level functions for use by source implementations
00164  */
00165 void g_main_context_add_poll      (GMainContext *context,
00166                                    GPollFD      *fd,
00167                                    gint          priority);
00168 void g_main_context_remove_poll   (GMainContext *context,
00169                                    GPollFD      *fd);
00170 
00171 /* GMainLoop: */
00172 
00173 GMainLoop *g_main_loop_new        (GMainContext *context,
00174                                    gboolean      is_running);
00175 void       g_main_loop_run        (GMainLoop    *loop);
00176 void       g_main_loop_quit       (GMainLoop    *loop);
00177 void       g_main_loop_destroy    (GMainLoop    *loop);
00178 gboolean   g_main_loop_is_running (GMainLoop    *loop);
00179 
00180 /* GSource: */
00181 
00182 GSource *g_source_new             (GSourceFuncs   *source_funcs,
00183                                    guint           struct_size);
00184 GSource *g_source_ref             (GSource        *source);
00185 void     g_source_unref           (GSource        *source);
00186 
00187 guint    g_source_attach          (GSource        *source,
00188                                    GMainContext   *context);
00189 void     g_source_destroy         (GSource        *source);
00190 
00191 void     g_source_set_priority    (GSource        *source,
00192                                    gint            priority);
00193 gint     g_source_get_priority    (GSource        *source);
00194 void     g_source_set_can_recurse (GSource        *source,
00195                                    gboolean        can_recurse);
00196 gboolean g_source_get_can_recurse (GSource        *source);
00197 guint    g_source_get_id          (GSource        *source);
00198 
00199 GMainContext *g_source_get_context (GSource       *source);
00200 
00201 void g_source_set_callback          (GSource              *source,
00202                                      GSourceFunc           func,
00203                                      gpointer              data,
00204                                      GDestroyNotify        notify);
00205 
00206 
00207 /* Used to implement g_source_connect_closure and internally*/
00208 void g_source_set_callback_indirect (GSource              *source,
00209                                      gpointer              callback_data,
00210                                      GSourceCallbackFuncs *callback_funcs);
00211 
00212 void     g_source_add_poll         (GSource        *source,
00213                                     GPollFD        *fd);
00214 void     g_source_remove_poll      (GSource        *source,
00215                                     GPollFD        *fd);
00216 
00217 void     g_source_get_current_time (GSource        *source,
00218                                     GTimeVal       *timeval);
00219 
00220  /* void g_source_connect_closure (GSource        *source,
00221                                   GClosure       *closure);
00222  */
00223 
00224 /* Specific source types
00225  */
00226 GSource *g_idle_source_new    (void);
00227 GSource *g_timeout_source_new (guint         interval);
00228 
00229 /* Miscellaneous functions
00230  */
00231 void g_get_current_time                 (GTimeVal       *result);
00232 
00233 /* ============== Compat main loop stuff ================== */
00234 
00235 /* Legacy names for GMainLoop functions
00236  */
00237 #define         g_main_new(is_running)  g_main_loop_new (NULL, is_running);
00238 #define         g_main_run(loop)        g_main_loop_run(loop)
00239 #define         g_main_quit(loop)       g_main_loop_quit(loop)
00240 #define         g_main_destroy(loop)    g_main_loop_destroy(loop)
00241 #define         g_main_is_running(loop) g_main_loop_is_running(loop)
00242 
00243 /* Source manipulation by ID */
00244 gboolean g_source_remove                     (guint          tag);
00245 gboolean g_source_remove_by_user_data        (gpointer       user_data);
00246 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
00247                                               gpointer       user_data);
00248 
00249 /* Functions to manipulate the default main loop
00250  */
00251 
00252 #define g_main_iteration(may_block) g_main_context_iteration      (NULL, may_block)
00253 #define g_main_pending()            g_main_context_pending        (NULL)
00254 
00255 #define g_main_set_poll_func(func)   g_main_context_set_poll_func (NULL, func)
00256 
00257 /* Idles and timeouts */
00258 guint           g_timeout_add_full      (gint           priority,
00259                                          guint          interval, 
00260                                          GSourceFunc    function,
00261                                          gpointer       data,
00262                                          GDestroyNotify notify);
00263 guint           g_timeout_add           (guint          interval,
00264                                          GSourceFunc    function,
00265                                          gpointer       data);
00266 guint           g_idle_add              (GSourceFunc    function,
00267                                          gpointer       data);
00268 guint           g_idle_add_full         (gint           priority,
00269                                          GSourceFunc    function,
00270                                          gpointer       data,
00271                                          GDestroyNotify notify);
00272 gboolean        g_idle_remove_by_data   (gpointer       data);
00273 
00274 #ifdef G_OS_WIN32
00275 
00276 /* This is used to add polling for Windows messages. GDK (GTK+) programs
00277  * should *not* use this.
00278  */
00279 void        g_main_poll_win32_msg_add (gint        priority,
00280                                        GPollFD    *fd,
00281                                        guint       hwnd);
00282 #endif /* G_OS_WIN32 */
00283 
00284 G_END_DECLS
00285 
00286 #endif /* __G_MAIN_H__ */

Generated on Tue Jul 5 14:14:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1