gmessages.h

Go to the documentation of this file.
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 #ifndef __G_MESSAGES_H__
00028 #define __G_MESSAGES_H__
00029 
00030 #include <stdarg.h>
00031 #include <g_types.h>
00032 
00033 G_BEGIN_DECLS
00034 
00035 /* calculate a string size, guarranteed to fit format + args.
00036  */
00037 guint   g_printf_string_upper_bound (const gchar* format,
00038                                      va_list      args);
00039 
00040 /* Log level shift offset for user defined
00041  * log levels (0-7 are used by GLib).
00042  */
00043 #define G_LOG_LEVEL_USER_SHIFT  (8)
00044 
00045 /* Glib log levels and flags.
00046  */
00047 typedef enum
00048 {
00049   /* log flags */
00050   G_LOG_FLAG_RECURSION          = 1 << 0,
00051   G_LOG_FLAG_FATAL              = 1 << 1,
00052 
00053   /* GLib log levels */
00054   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
00055   G_LOG_LEVEL_CRITICAL          = 1 << 3,
00056   G_LOG_LEVEL_WARNING           = 1 << 4,
00057   G_LOG_LEVEL_MESSAGE           = 1 << 5,
00058   G_LOG_LEVEL_INFO              = 1 << 6,
00059   G_LOG_LEVEL_DEBUG             = 1 << 7,
00060 
00061   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
00062 } GLogLevelFlags;
00063 
00064 /* GLib log levels that are considered fatal by default */
00065 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
00066 
00067 typedef void            (*GLogFunc)             (const gchar   *log_domain,
00068                                                  GLogLevelFlags log_level,
00069                                                  const gchar   *message,
00070                                                  gpointer       user_data);
00071 
00072 /* Logging mechanism
00073  */
00074 extern          const gchar             *g_log_domain_glib;
00075 guint           g_log_set_handler       (const gchar    *log_domain,
00076                                          GLogLevelFlags  log_levels,
00077                                          GLogFunc        log_func,
00078                                          gpointer        user_data);
00079 void            g_log_remove_handler    (const gchar    *log_domain,
00080                                          guint           handler_id);
00081 void            g_log_default_handler   (const gchar    *log_domain,
00082                                          GLogLevelFlags  log_level,
00083                                          const gchar    *message,
00084                                          gpointer        unused_data);
00085 void            g_log                   (const gchar    *log_domain,
00086                                          GLogLevelFlags  log_level,
00087                                          const gchar    *format,
00088                                          ...) G_GNUC_PRINTF (3, 4);
00089 void            g_logv                  (const gchar    *log_domain,
00090                                          GLogLevelFlags  log_level,
00091                                          const gchar    *format,
00092                                          va_list         args);
00093 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
00094                                          GLogLevelFlags  fatal_mask);
00095 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
00096 
00097 #ifndef G_LOG_DOMAIN
00098 #define G_LOG_DOMAIN    ((gchar*) 0)
00099 #endif  /* G_LOG_DOMAIN */
00100 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
00101 #define g_error(...)    g_log (G_LOG_DOMAIN,         \
00102                                G_LOG_LEVEL_ERROR,    \
00103                                __VA_ARGS__)
00104 #define g_message(...)  g_log (G_LOG_DOMAIN,         \
00105                                G_LOG_LEVEL_MESSAGE,  \
00106                                __VA_ARGS__)
00107 #define g_critical(...) g_log (G_LOG_DOMAIN,         \
00108                                G_LOG_LEVEL_CRITICAL, \
00109                                __VA_ARGS__)
00110 #define g_warning(...)  g_log (G_LOG_DOMAIN,         \
00111                                G_LOG_LEVEL_WARNING,  \
00112                                __VA_ARGS__)
00113 #elif __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 4)
00114 #define g_error(format...)      g_log (G_LOG_DOMAIN,         \
00115                                        G_LOG_LEVEL_ERROR,    \
00116                                        format)
00117 #define g_message(format...)    g_log (G_LOG_DOMAIN,         \
00118                                        G_LOG_LEVEL_MESSAGE,  \
00119                                        format)
00120 #define g_critical(format...)   g_log (G_LOG_DOMAIN,         \
00121                                        G_LOG_LEVEL_CRITICAL, \
00122                                        format)
00123 #define g_warning(format...)    g_log (G_LOG_DOMAIN,         \
00124                                        G_LOG_LEVEL_WARNING,  \
00125                                        format)
00126 #else   /* !__GNUC__ */
00127 static void
00128 g_error (const gchar *format,
00129          ...)
00130 {
00131   va_list args;
00132   va_start (args, format);
00133   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
00134   va_end (args);
00135 }
00136 static void
00137 g_message (const gchar *format,
00138            ...)
00139 {
00140   va_list args;
00141   va_start (args, format);
00142   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
00143   va_end (args);
00144 }
00145 static void
00146 g_critical (const gchar *format,
00147             ...)
00148 {
00149   va_list args;
00150   va_start (args, format);
00151   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
00152   va_end (args);
00153 }
00154 static void
00155 g_warning (const gchar *format,
00156            ...)
00157 {
00158   va_list args;
00159   va_start (args, format);
00160   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
00161   va_end (args);
00162 }
00163 #endif  /* !__GNUC__ */
00164 
00165 typedef void    (*GPrintFunc)           (const gchar    *string);
00166 void            g_print                 (const gchar    *format,
00167                                          ...) G_GNUC_PRINTF (1, 2);
00168 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
00169 void            g_printerr              (const gchar    *format,
00170                                          ...) G_GNUC_PRINTF (1, 2);
00171 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
00172 
00173 /* deprecated compatibility functions, use g_log_set_handler() instead */
00174 typedef void            (*GErrorFunc)           (const gchar *str);
00175 typedef void            (*GWarningFunc)         (const gchar *str);
00176 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
00177 GWarningFunc g_set_warning_handler (GWarningFunc func);
00178 GPrintFunc   g_set_message_handler (GPrintFunc func);
00179 
00180 /* Provide macros for error handling. The "assert" macros will
00181  *  exit on failure. The "return" macros will exit the current
00182  *  function. Two different definitions are given for the macros
00183  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
00184  *  __PRETTY_FUNCTION__ capability.
00185  */
00186 
00187 #ifdef G_DISABLE_ASSERT
00188 
00189 #define g_assert(expr)
00190 #define g_assert_not_reached()
00191 
00192 #else /* !G_DISABLE_ASSERT */
00193 
00194 #ifdef __GNUC__
00195 
00196 #define g_assert(expr)                  G_STMT_START{           \
00197      if (!(expr))                                               \
00198        g_log (G_LOG_DOMAIN,                                     \
00199               G_LOG_LEVEL_ERROR,                                \
00200               "file %s: line %d (%s): assertion failed: (%s)",  \
00201               __FILE__,                                         \
00202               __LINE__,                                         \
00203               __PRETTY_FUNCTION__,                              \
00204               #expr);                   }G_STMT_END
00205 
00206 #define g_assert_not_reached()          G_STMT_START{           \
00207      g_log (G_LOG_DOMAIN,                                       \
00208             G_LOG_LEVEL_ERROR,                                  \
00209             "file %s: line %d (%s): should not be reached",     \
00210             __FILE__,                                           \
00211             __LINE__,                                           \
00212             __PRETTY_FUNCTION__);       }G_STMT_END
00213 
00214 #else /* !__GNUC__ */
00215 
00216 #define g_assert(expr)                  G_STMT_START{           \
00217      if (!(expr))                                               \
00218        g_log (G_LOG_DOMAIN,                                     \
00219               G_LOG_LEVEL_ERROR,                                \
00220               "file %s: line %d: assertion failed: (%s)",       \
00221               __FILE__,                                         \
00222               __LINE__,                                         \
00223               #expr);                   }G_STMT_END
00224 
00225 #define g_assert_not_reached()          G_STMT_START{   \
00226      g_log (G_LOG_DOMAIN,                               \
00227             G_LOG_LEVEL_ERROR,                          \
00228             "file %s: line %d: should not be reached",  \
00229             __FILE__,                                   \
00230             __LINE__);          }G_STMT_END
00231 
00232 #endif /* __GNUC__ */
00233 
00234 #endif /* !G_DISABLE_ASSERT */
00235 
00236 
00237 #ifdef G_DISABLE_CHECKS
00238 
00239 #define g_return_if_fail(expr)
00240 #define g_return_val_if_fail(expr,val)
00241 #define g_return_if_reached() return
00242 #define g_return_val_if_reached(val) return (val)
00243 
00244 #else /* !G_DISABLE_CHECKS */
00245 
00246 #ifdef __GNUC__
00247 
00248 #define g_return_if_fail(expr)          G_STMT_START{                   \
00249      if (!(expr))                                                       \
00250        {                                                                \
00251          g_log (G_LOG_DOMAIN,                                           \
00252                 G_LOG_LEVEL_CRITICAL,                                   \
00253                 "file %s: line %d (%s): assertion `%s' failed",         \
00254                 __FILE__,                                               \
00255                 __LINE__,                                               \
00256                 __PRETTY_FUNCTION__,                                    \
00257                 #expr);                                                 \
00258          return;                                                        \
00259        };                               }G_STMT_END
00260 
00261 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
00262      if (!(expr))                                                       \
00263        {                                                                \
00264          g_log (G_LOG_DOMAIN,                                           \
00265                 G_LOG_LEVEL_CRITICAL,                                   \
00266                 "file %s: line %d (%s): assertion `%s' failed",         \
00267                 __FILE__,                                               \
00268                 __LINE__,                                               \
00269                 __PRETTY_FUNCTION__,                                    \
00270                 #expr);                                                 \
00271          return (val);                                                  \
00272        };                               }G_STMT_END
00273 
00274 #define g_return_if_reached()           G_STMT_START{                   \
00275      g_log (G_LOG_DOMAIN,                                               \
00276             G_LOG_LEVEL_CRITICAL,                                       \
00277             "file %s: line %d (%s): should not be reached",             \
00278             __FILE__,                                                   \
00279             __LINE__,                                                   \
00280             __PRETTY_FUNCTION__);                                       \
00281      return;                            }G_STMT_END
00282 
00283 #define g_return_val_if_reached(val)    G_STMT_START{                   \
00284      g_log (G_LOG_DOMAIN,                                               \
00285             G_LOG_LEVEL_CRITICAL,                                       \
00286             "file %s: line %d (%s): should not be reached",             \
00287             __FILE__,                                                   \
00288             __LINE__,                                                   \
00289             __PRETTY_FUNCTION__);                                       \
00290      return (val);                      }G_STMT_END
00291 
00292 #else /* !__GNUC__ */
00293 
00294 #define g_return_if_fail(expr)          G_STMT_START{           \
00295      if (!(expr))                                               \
00296        {                                                        \
00297          g_log (G_LOG_DOMAIN,                                   \
00298                 G_LOG_LEVEL_CRITICAL,                           \
00299                 "file %s: line %d: assertion `%s' failed",      \
00300                 __FILE__,                                       \
00301                 __LINE__,                                       \
00302                 #expr);                                         \
00303          return;                                                \
00304        };                               }G_STMT_END
00305 
00306 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
00307      if (!(expr))                                               \
00308        {                                                        \
00309          g_log (G_LOG_DOMAIN,                                   \
00310                 G_LOG_LEVEL_CRITICAL,                           \
00311                 "file %s: line %d: assertion `%s' failed",      \
00312                 __FILE__,                                       \
00313                 __LINE__,                                       \
00314                 #expr);                                         \
00315          return (val);                                          \
00316        };                               }G_STMT_END
00317 
00318 #define g_return_if_reached()           G_STMT_START{           \
00319      g_log (G_LOG_DOMAIN,                                       \
00320             G_LOG_LEVEL_CRITICAL,                               \
00321             "file %s: line %d: should not be reached",          \
00322             __FILE__,                                           \
00323             __LINE__);                                          \
00324      return;                            }G_STMT_END
00325 
00326 #define g_return_val_if_reached(val)    G_STMT_START{           \
00327      g_log (G_LOG_DOMAIN,                                       \
00328             G_LOG_LEVEL_CRITICAL,                               \
00329             "file %s: line %d: should not be reached",          \
00330             __FILE__,                                           \
00331             __LINE__);                                          \
00332      return (val);                      }G_STMT_END
00333 
00334 #endif /* !__GNUC__ */
00335 
00336 #endif /* !G_DISABLE_CHECKS */
00337 
00338 G_END_DECLS
00339 
00340 #endif /* __G_MESSAGES_H__ */
00341 

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