Navit SVN

/work/compile/navit/src/navit/support/glib/gmessages.h

00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser 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 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/.
00025  */
00026 
00027 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
00028 #error "Only <glib.h> can be included directly."
00029 #endif
00030 
00031 #ifndef __G_MESSAGES_H__
00032 #define __G_MESSAGES_H__
00033 
00034 #include <stdarg.h>
00035 #include <glib/gtypes.h>
00036 #include <glib/gmacros.h>
00037 
00038 /* Suppress warnings when GCC is in -pedantic mode and not -std=c99
00039  */
00040 #if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
00041 #pragma GCC system_header
00042 #endif
00043 
00044 G_BEGIN_DECLS
00045 
00046 /* calculate a string size, guaranteed to fit format + args.
00047  */
00048 gsize   g_printf_string_upper_bound (const gchar* format,
00049                                      va_list      args);
00050 
00051 /* Log level shift offset for user defined
00052  * log levels (0-7 are used by GLib).
00053  */
00054 #define G_LOG_LEVEL_USER_SHIFT  (8)
00055 
00056 /* Glib log levels and flags.
00057  */
00058 typedef enum
00059 {
00060   /* log flags */
00061   G_LOG_FLAG_RECURSION          = 1 << 0,
00062   G_LOG_FLAG_FATAL              = 1 << 1,
00063 
00064   /* GLib log levels */
00065   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
00066   G_LOG_LEVEL_CRITICAL          = 1 << 3,
00067   G_LOG_LEVEL_WARNING           = 1 << 4,
00068   G_LOG_LEVEL_MESSAGE           = 1 << 5,
00069   G_LOG_LEVEL_INFO              = 1 << 6,
00070   G_LOG_LEVEL_DEBUG             = 1 << 7,
00071 
00072   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
00073 } GLogLevelFlags;
00074 
00075 /* GLib log levels that are considered fatal by default */
00076 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
00077 
00078 typedef void            (*GLogFunc)             (const gchar   *log_domain,
00079                                                  GLogLevelFlags log_level,
00080                                                  const gchar   *message,
00081                                                  gpointer       user_data);
00082 
00083 /* Logging mechanism
00084  */
00085 guint           g_log_set_handler       (const gchar    *log_domain,
00086                                          GLogLevelFlags  log_levels,
00087                                          GLogFunc        log_func,
00088                                          gpointer        user_data);
00089 void            g_log_remove_handler    (const gchar    *log_domain,
00090                                          guint           handler_id);
00091 void            g_log_default_handler   (const gchar    *log_domain,
00092                                          GLogLevelFlags  log_level,
00093                                          const gchar    *message,
00094                                          gpointer        unused_data);
00095 GLogFunc        g_log_set_default_handler (GLogFunc      log_func,
00096                                            gpointer      user_data);
00097 void            g_log                   (const gchar    *log_domain,
00098                                          GLogLevelFlags  log_level,
00099                                          const gchar    *format,
00100                                          ...) G_GNUC_PRINTF (3, 4);
00101 void            g_logv                  (const gchar    *log_domain,
00102                                          GLogLevelFlags  log_level,
00103                                          const gchar    *format,
00104                                          va_list         args);
00105 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
00106                                          GLogLevelFlags  fatal_mask);
00107 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
00108 
00109 /* internal */
00110 G_GNUC_INTERNAL void    _g_log_fallback_handler (const gchar   *log_domain,
00111                                                  GLogLevelFlags log_level,
00112                                                  const gchar   *message,
00113                                                  gpointer       unused_data);
00114 
00115 /* Internal functions, used to implement the following macros */
00116 void g_return_if_fail_warning (const char *log_domain,
00117                                const char *pretty_function,
00118                                const char *expression);
00119 void g_warn_message           (const char     *domain,
00120                                const char     *file,
00121                                int             line,
00122                                const char     *func,
00123                                const char     *warnexpr);
00124 #ifndef G_DISABLE_DEPRECATED
00125 void g_assert_warning         (const char *log_domain,
00126                                const char *file,
00127                                const int   line,
00128                                const char *pretty_function,
00129                                const char *expression) G_GNUC_NORETURN;
00130 #endif /* !G_DISABLE_DEPRECATED */
00131 
00132 
00133 #ifndef G_LOG_DOMAIN
00134 #define G_LOG_DOMAIN    ((gchar*) 0)
00135 #endif  /* G_LOG_DOMAIN */
00136 #ifdef G_HAVE_ISO_VARARGS
00137 /* for(;;); so that GCC knows that control doesn't go past g_error() */
00138 #define g_error(...)  G_STMT_START {                 \
00139                         g_log (G_LOG_DOMAIN,         \
00140                                G_LOG_LEVEL_ERROR,    \
00141                                __VA_ARGS__);         \
00142                         for (;;);                    \
00143                       } G_STMT_END
00144                         
00145 #define g_message(...)  g_log (G_LOG_DOMAIN,         \
00146                                G_LOG_LEVEL_MESSAGE,  \
00147                                __VA_ARGS__)
00148 #define g_critical(...) g_log (G_LOG_DOMAIN,         \
00149                                G_LOG_LEVEL_CRITICAL, \
00150                                __VA_ARGS__)
00151 #define g_warning(...)  g_log (G_LOG_DOMAIN,         \
00152                                G_LOG_LEVEL_WARNING,  \
00153                                __VA_ARGS__)
00154 #define g_debug(...)    g_log (G_LOG_DOMAIN,         \
00155                                G_LOG_LEVEL_DEBUG,    \
00156                                __VA_ARGS__)
00157 #elif defined(G_HAVE_GNUC_VARARGS)
00158 #define g_error(format...)    G_STMT_START {                 \
00159                                 g_log (G_LOG_DOMAIN,         \
00160                                        G_LOG_LEVEL_ERROR,    \
00161                                        format);              \
00162                                 for (;;);                    \
00163                               } G_STMT_END
00164                               
00165 #define g_message(format...)    g_log (G_LOG_DOMAIN,         \
00166                                        G_LOG_LEVEL_MESSAGE,  \
00167                                        format)
00168 #define g_critical(format...)   g_log (G_LOG_DOMAIN,         \
00169                                        G_LOG_LEVEL_CRITICAL, \
00170                                        format)
00171 #define g_warning(format...)    g_log (G_LOG_DOMAIN,         \
00172                                        G_LOG_LEVEL_WARNING,  \
00173                                        format)
00174 #define g_debug(format...)      g_log (G_LOG_DOMAIN,         \
00175                                        G_LOG_LEVEL_DEBUG,    \
00176                                        format)
00177 #else   /* no varargs macros */
00178 static void
00179 g_error (const gchar *format,
00180          ...)
00181 {
00182   va_list args;
00183   va_start (args, format);
00184   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
00185   va_end (args);
00186 
00187   for(;;);
00188 }
00189 static void
00190 g_message (const gchar *format,
00191            ...)
00192 {
00193   va_list args;
00194   va_start (args, format);
00195   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
00196   va_end (args);
00197 }
00198 static void
00199 g_critical (const gchar *format,
00200             ...)
00201 {
00202   va_list args;
00203   va_start (args, format);
00204   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
00205   va_end (args);
00206 }
00207 static void
00208 g_warning (const gchar *format,
00209            ...)
00210 {
00211   va_list args;
00212   va_start (args, format);
00213   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
00214   va_end (args);
00215 }
00216 static void
00217 g_debug (const gchar *format,
00218          ...)
00219 {
00220   va_list args;
00221   va_start (args, format);
00222   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
00223   va_end (args);
00224 }
00225 #endif  /* !__GNUC__ */
00226 
00227 typedef void    (*GPrintFunc)           (const gchar    *string);
00228 void            g_print                 (const gchar    *format,
00229                                          ...) G_GNUC_PRINTF (1, 2);
00230 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
00231 void            g_printerr              (const gchar    *format,
00232                                          ...) G_GNUC_PRINTF (1, 2);
00233 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
00234 
00235 
00236 /* Provide macros for graceful error handling.
00237  * The "return" macros will return from the current function.
00238  * Two different definitions are given for the macros in
00239  * order to support gcc's __PRETTY_FUNCTION__ capability.
00240  */
00241 
00242 #define g_warn_if_reached()     do { g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0)
00243 #define g_warn_if_fail(expr)    do { if G_LIKELY (expr) ; else \
00244                                        g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr); } while (0)
00245 
00246 #ifdef G_DISABLE_CHECKS
00247 
00248 #define g_return_if_fail(expr)                  G_STMT_START{ (void)0; }G_STMT_END
00249 #define g_return_val_if_fail(expr,val)          G_STMT_START{ (void)0; }G_STMT_END
00250 #define g_return_if_reached()                   G_STMT_START{ return; }G_STMT_END
00251 #define g_return_val_if_reached(val)            G_STMT_START{ return (val); }G_STMT_END
00252 
00253 #else /* !G_DISABLE_CHECKS */
00254 
00255 #ifdef __GNUC__
00256 
00257 #define g_return_if_fail(expr)          G_STMT_START{                   \
00258      if G_LIKELY(expr) { } else                                         \
00259        {                                                                \
00260          g_return_if_fail_warning (G_LOG_DOMAIN,                        \
00261                                    __PRETTY_FUNCTION__,                 \
00262                                    #expr);                              \
00263          return;                                                        \
00264        };                               }G_STMT_END
00265 
00266 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
00267      if G_LIKELY(expr) { } else                                         \
00268        {                                                                \
00269          g_return_if_fail_warning (G_LOG_DOMAIN,                        \
00270                                    __PRETTY_FUNCTION__,                 \
00271                                    #expr);                              \
00272          return (val);                                                  \
00273        };                               }G_STMT_END
00274 
00275 #define g_return_if_reached()           G_STMT_START{                   \
00276      g_log (G_LOG_DOMAIN,                                               \
00277             G_LOG_LEVEL_CRITICAL,                                       \
00278             "file %s: line %d (%s): should not be reached",             \
00279             __FILE__,                                                   \
00280             __LINE__,                                                   \
00281             __PRETTY_FUNCTION__);                                       \
00282      return;                            }G_STMT_END
00283 
00284 #define g_return_val_if_reached(val)    G_STMT_START{                   \
00285      g_log (G_LOG_DOMAIN,                                               \
00286             G_LOG_LEVEL_CRITICAL,                                       \
00287             "file %s: line %d (%s): should not be reached",             \
00288             __FILE__,                                                   \
00289             __LINE__,                                                   \
00290             __PRETTY_FUNCTION__);                                       \
00291      return (val);                      }G_STMT_END
00292 
00293 #else /* !__GNUC__ */
00294 
00295 #define g_return_if_fail(expr)          G_STMT_START{           \
00296      if (expr) { } else                                         \
00297        {                                                        \
00298          g_log (G_LOG_DOMAIN,                                   \
00299                 G_LOG_LEVEL_CRITICAL,                           \
00300                 "file %s: line %d: assertion `%s' failed",      \
00301                 __FILE__,                                       \
00302                 __LINE__,                                       \
00303                 #expr);                                         \
00304          return;                                                \
00305        };                               }G_STMT_END
00306 
00307 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
00308      if (expr) { } else                                         \
00309        {                                                        \
00310          g_log (G_LOG_DOMAIN,                                   \
00311                 G_LOG_LEVEL_CRITICAL,                           \
00312                 "file %s: line %d: assertion `%s' failed",      \
00313                 __FILE__,                                       \
00314                 __LINE__,                                       \
00315                 #expr);                                         \
00316          return (val);                                          \
00317        };                               }G_STMT_END
00318 
00319 #define g_return_if_reached()           G_STMT_START{           \
00320      g_log (G_LOG_DOMAIN,                                       \
00321             G_LOG_LEVEL_CRITICAL,                               \
00322             "file %s: line %d: should not be reached",          \
00323             __FILE__,                                           \
00324             __LINE__);                                          \
00325      return;                            }G_STMT_END
00326 
00327 #define g_return_val_if_reached(val)    G_STMT_START{           \
00328      g_log (G_LOG_DOMAIN,                                       \
00329             G_LOG_LEVEL_CRITICAL,                               \
00330             "file %s: line %d: should not be reached",          \
00331             __FILE__,                                           \
00332             __LINE__);                                          \
00333      return (val);                      }G_STMT_END
00334 
00335 #endif /* !__GNUC__ */
00336 
00337 #endif /* !G_DISABLE_CHECKS */
00338 
00339 G_END_DECLS
00340 
00341 #endif /* __G_MESSAGES_H__ */