epoc32/include/stdapis/glib-2.0/glib/gmessages.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 gmessages.h
     1 /* GLIB - Library of useful routines for C programming
       
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
       
     3  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
       
     4  *
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this library; if not, write to the
       
    17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    18  * Boston, MA 02111-1307, USA.
       
    19  */
       
    20 
       
    21 /*
       
    22  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
       
    23  * file for a list of people on the GLib Team.  See the ChangeLog
       
    24  * files for a list of changes.  These files are distributed with
       
    25  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
       
    26  */
       
    27 
       
    28 #ifndef __G_MESSAGES_H__
       
    29 #define __G_MESSAGES_H__
       
    30 
       
    31 #include <_ansi.h>
       
    32 #include <stdarg.h>
       
    33 #include <glib/gtypes.h>
       
    34 #include <glib/gmacros.h>
       
    35 
       
    36 /* Suppress warnings when GCC is in -pedantic mode and not -std=c99
       
    37  */
       
    38 #if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
       
    39 #pragma GCC system_header
       
    40 #endif
       
    41 
       
    42 G_BEGIN_DECLS
       
    43 
       
    44 /* calculate a string size, guaranteed to fit format + args.
       
    45  */
       
    46 IMPORT_C gsize	g_printf_string_upper_bound (const gchar* format,
       
    47 				     va_list	  args);
       
    48 
       
    49 /* Log level shift offset for user defined
       
    50  * log levels (0-7 are used by GLib).
       
    51  */
       
    52 #define G_LOG_LEVEL_USER_SHIFT  (8)
       
    53 
       
    54 /* Glib log levels and flags.
       
    55  */
       
    56 typedef enum
       
    57 {
       
    58   /* log flags */
       
    59   G_LOG_FLAG_RECURSION          = 1 << 0,
       
    60   G_LOG_FLAG_FATAL              = 1 << 1,
       
    61 
       
    62   /* GLib log levels */
       
    63   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
       
    64   G_LOG_LEVEL_CRITICAL          = 1 << 3,
       
    65   G_LOG_LEVEL_WARNING           = 1 << 4,
       
    66   G_LOG_LEVEL_MESSAGE           = 1 << 5,
       
    67   G_LOG_LEVEL_INFO              = 1 << 6,
       
    68   G_LOG_LEVEL_DEBUG             = 1 << 7,
       
    69 
       
    70   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
       
    71 } GLogLevelFlags;
       
    72 
       
    73 /* GLib log levels that are considered fatal by default */
       
    74 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
       
    75 
       
    76 typedef void            (*GLogFunc)             (const gchar   *log_domain,
       
    77                                                  GLogLevelFlags log_level,
       
    78                                                  const gchar   *message,
       
    79                                                  gpointer       user_data);
       
    80 
       
    81 /* Logging mechanism
       
    82  */
       
    83 IMPORT_C guint           g_log_set_handler       (const gchar    *log_domain,
       
    84                                          GLogLevelFlags  log_levels,
       
    85                                          GLogFunc        log_func,
       
    86                                          gpointer        user_data);
       
    87 IMPORT_C void            g_log_remove_handler    (const gchar    *log_domain,
       
    88                                          guint           handler_id);
       
    89 IMPORT_C void            g_log_default_handler   (const gchar    *log_domain,
       
    90                                          GLogLevelFlags  log_level,
       
    91                                          const gchar    *message,
       
    92                                          gpointer        unused_data);
       
    93 IMPORT_C GLogFunc        g_log_set_default_handler (GLogFunc      log_func,
       
    94 					   gpointer      user_data);
       
    95 IMPORT_C void            g_log                   (const gchar    *log_domain,
       
    96                                          GLogLevelFlags  log_level,
       
    97                                          const gchar    *format,
       
    98                                          ...) G_GNUC_PRINTF (3, 4);
       
    99 IMPORT_C void            g_logv                  (const gchar    *log_domain,
       
   100                                          GLogLevelFlags  log_level,
       
   101                                          const gchar    *format,
       
   102                                          va_list         args);
       
   103 IMPORT_C GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
       
   104                                          GLogLevelFlags  fatal_mask);
       
   105 IMPORT_C GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
       
   106 
       
   107 /* internal */
       
   108 void	_g_log_fallback_handler	(const gchar   *log_domain,
       
   109 				 GLogLevelFlags log_level,
       
   110 				 const gchar   *message,
       
   111 				 gpointer       unused_data) G_GNUC_INTERNAL;
       
   112 
       
   113 /* Internal functions, used to implement the following macros */
       
   114 IMPORT_C void g_return_if_fail_warning (const char *log_domain,
       
   115 			       const char *pretty_function,
       
   116 			       const char *expression);
       
   117 IMPORT_C void g_assert_warning         (const char *log_domain,
       
   118 			       const char *file,
       
   119 			       const int   line,
       
   120 		               const char *pretty_function,
       
   121 		               const char *expression) G_GNUC_NORETURN;
       
   122 
       
   123 
       
   124 #ifndef G_LOG_DOMAIN
       
   125 #define G_LOG_DOMAIN    ((gchar*) 0)
       
   126 #endif  /* G_LOG_DOMAIN */
       
   127 #ifdef G_HAVE_ISO_VARARGS
       
   128 #define g_error(...)    g_log (G_LOG_DOMAIN,         \
       
   129                                G_LOG_LEVEL_ERROR,    \
       
   130                                __VA_ARGS__)
       
   131 #define g_message(...)  g_log (G_LOG_DOMAIN,         \
       
   132                                G_LOG_LEVEL_MESSAGE,  \
       
   133                                __VA_ARGS__)
       
   134 #define g_critical(...) g_log (G_LOG_DOMAIN,         \
       
   135                                G_LOG_LEVEL_CRITICAL, \
       
   136                                __VA_ARGS__)
       
   137 #define g_warning(...)  g_log (G_LOG_DOMAIN,         \
       
   138                                G_LOG_LEVEL_WARNING,  \
       
   139                                __VA_ARGS__)
       
   140 #define g_debug(...)    g_log (G_LOG_DOMAIN,         \
       
   141                                G_LOG_LEVEL_DEBUG,    \
       
   142                                __VA_ARGS__)
       
   143 #elif defined(G_HAVE_GNUC_VARARGS)
       
   144 #define g_error(format...)      g_log (G_LOG_DOMAIN,         \
       
   145                                        G_LOG_LEVEL_ERROR,    \
       
   146                                        format)
       
   147 #define g_message(format...)    g_log (G_LOG_DOMAIN,         \
       
   148                                        G_LOG_LEVEL_MESSAGE,  \
       
   149                                        format)
       
   150 #define g_critical(format...)   g_log (G_LOG_DOMAIN,         \
       
   151                                        G_LOG_LEVEL_CRITICAL, \
       
   152                                        format)
       
   153 #define g_warning(format...)    g_log (G_LOG_DOMAIN,         \
       
   154                                        G_LOG_LEVEL_WARNING,  \
       
   155                                        format)
       
   156 #define g_debug(format...)      g_log (G_LOG_DOMAIN,         \
       
   157                                        G_LOG_LEVEL_DEBUG,    \
       
   158                                        format)
       
   159 #else   /* no varargs macros */
       
   160 static void
       
   161 g_error (const gchar *format,
       
   162          ...)
       
   163 {
       
   164   va_list args;
       
   165   va_start (args, format);
       
   166   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
       
   167   va_end (args);
       
   168 }
       
   169 static void
       
   170 g_message (const gchar *format,
       
   171            ...)
       
   172 {
       
   173   va_list args;
       
   174   va_start (args, format);
       
   175   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
       
   176   va_end (args);
       
   177 }
       
   178 static void
       
   179 g_critical (const gchar *format,
       
   180             ...)
       
   181 {
       
   182   va_list args;
       
   183   va_start (args, format);
       
   184   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
       
   185   va_end (args);
       
   186 }
       
   187 static void
       
   188 g_warning (const gchar *format,
       
   189            ...)
       
   190 {
       
   191   va_list args;
       
   192   va_start (args, format);
       
   193   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
       
   194   va_end (args);
       
   195 }
       
   196 static void
       
   197 g_debug (const gchar *format,
       
   198          ...)
       
   199 {
       
   200   va_list args;
       
   201   va_start (args, format);
       
   202   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
       
   203   va_end (args);
       
   204 }
       
   205 #endif  /* !__GNUC__ */
       
   206 
       
   207 typedef void    (*GPrintFunc)           (const gchar    *string);
       
   208 IMPORT_C void            g_print                 (const gchar    *format,
       
   209                                          ...) G_GNUC_PRINTF (1, 2);
       
   210 IMPORT_C GPrintFunc      g_set_print_handler     (GPrintFunc      func);
       
   211 IMPORT_C void            g_printerr              (const gchar    *format,
       
   212                                          ...) G_GNUC_PRINTF (1, 2);
       
   213 IMPORT_C GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
       
   214 
       
   215 
       
   216 /* Provide macros for error handling. The "assert" macros will
       
   217  *  exit on failure. The "return" macros will exit the current
       
   218  *  function. Two different definitions are given for the macros
       
   219  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
       
   220  *  __PRETTY_FUNCTION__ capability.
       
   221  */
       
   222 
       
   223 #ifdef G_DISABLE_ASSERT
       
   224 
       
   225 #define g_assert(expr)		G_STMT_START{ (void)0; }G_STMT_END
       
   226 #define g_assert_not_reached()	G_STMT_START{ (void)0; }G_STMT_END
       
   227 
       
   228 #else /* !G_DISABLE_ASSERT */
       
   229 
       
   230 #ifdef __GNUC__
       
   231 
       
   232 #define g_assert(expr)			G_STMT_START{		\
       
   233      if G_LIKELY(expr) { } else 				\
       
   234         g_assert_warning (G_LOG_DOMAIN,				\
       
   235 	                  __FILE__,    				\
       
   236 	                  __LINE__,	      			\
       
   237 	                  __PRETTY_FUNCTION__,	      		\
       
   238 	                  #expr);		  }G_STMT_END
       
   239 
       
   240 #define g_assert_not_reached()		G_STMT_START{		\
       
   241         g_assert_warning (G_LOG_DOMAIN,				\
       
   242 	                  __FILE__,    				\
       
   243 	                  __LINE__,	      			\
       
   244 	                  __PRETTY_FUNCTION__,	      		\
       
   245 	                  NULL);		  }G_STMT_END
       
   246 
       
   247 #else /* !__GNUC__ */
       
   248 
       
   249 #define g_assert(expr)			G_STMT_START{		\
       
   250      if (expr) { } else						\
       
   251        g_log (G_LOG_DOMAIN,					\
       
   252 	      G_LOG_LEVEL_ERROR,				\
       
   253 	      "file %s: line %d: assertion failed: (%s)",	\
       
   254 	      __FILE__,						\
       
   255 	      __LINE__,						\
       
   256 	      #expr);			}G_STMT_END
       
   257 
       
   258 #define g_assert_not_reached()		G_STMT_START{	\
       
   259      g_log (G_LOG_DOMAIN,				\
       
   260 	    G_LOG_LEVEL_ERROR,				\
       
   261 	    "file %s: line %d: should not be reached",	\
       
   262 	    __FILE__,					\
       
   263 	    __LINE__);		}G_STMT_END
       
   264 
       
   265 #endif /* __GNUC__ */
       
   266 
       
   267 #endif /* !G_DISABLE_ASSERT */
       
   268 
       
   269 
       
   270 #ifdef G_DISABLE_CHECKS
       
   271 
       
   272 #define g_return_if_fail(expr)			G_STMT_START{ (void)0; }G_STMT_END
       
   273 #define g_return_val_if_fail(expr,val)		G_STMT_START{ (void)0; }G_STMT_END
       
   274 #define g_return_if_reached()			G_STMT_START{ return; }G_STMT_END
       
   275 #define g_return_val_if_reached(val)		G_STMT_START{ return (val); }G_STMT_END
       
   276 
       
   277 #else /* !G_DISABLE_CHECKS */
       
   278 
       
   279 #ifdef __GNUC__
       
   280 
       
   281 #define g_return_if_fail(expr)		G_STMT_START{			\
       
   282      if G_LIKELY(expr) { } else       					\
       
   283        {								\
       
   284 	 g_return_if_fail_warning (G_LOG_DOMAIN,			\
       
   285 		                   __PRETTY_FUNCTION__,		        \
       
   286 		                   #expr);				\
       
   287 	 return;							\
       
   288        };				}G_STMT_END
       
   289 
       
   290 #define g_return_val_if_fail(expr,val)	G_STMT_START{			\
       
   291      if G_LIKELY(expr) { } else						\
       
   292        {								\
       
   293 	 g_return_if_fail_warning (G_LOG_DOMAIN,			\
       
   294 		                   __PRETTY_FUNCTION__,		        \
       
   295 		                   #expr);				\
       
   296 	 return (val);							\
       
   297        };				}G_STMT_END
       
   298 
       
   299 #define g_return_if_reached()		G_STMT_START{			\
       
   300      g_log (G_LOG_DOMAIN,						\
       
   301 	    G_LOG_LEVEL_CRITICAL,					\
       
   302 	    "file %s: line %d (%s): should not be reached",		\
       
   303 	    __FILE__,							\
       
   304 	    __LINE__,							\
       
   305 	    __PRETTY_FUNCTION__);					\
       
   306      return;				}G_STMT_END
       
   307 
       
   308 #define g_return_val_if_reached(val)	G_STMT_START{			\
       
   309      g_log (G_LOG_DOMAIN,						\
       
   310 	    G_LOG_LEVEL_CRITICAL,					\
       
   311 	    "file %s: line %d (%s): should not be reached",		\
       
   312 	    __FILE__,							\
       
   313 	    __LINE__,							\
       
   314 	    __PRETTY_FUNCTION__);					\
       
   315      return (val);			}G_STMT_END
       
   316 
       
   317 #else /* !__GNUC__ */
       
   318 
       
   319 #define g_return_if_fail(expr)		G_STMT_START{		\
       
   320      if (expr) { } else						\
       
   321        {							\
       
   322 	 g_log (G_LOG_DOMAIN,					\
       
   323 		G_LOG_LEVEL_CRITICAL,				\
       
   324 		"file %s: line %d: assertion `%s' failed",	\
       
   325 		__FILE__,					\
       
   326 		__LINE__,					\
       
   327 		#expr);						\
       
   328 	 return;						\
       
   329        };				}G_STMT_END
       
   330 
       
   331 #define g_return_val_if_fail(expr, val)	G_STMT_START{		\
       
   332      if (expr) { } else						\
       
   333        {							\
       
   334 	 g_log (G_LOG_DOMAIN,					\
       
   335 		G_LOG_LEVEL_CRITICAL,				\
       
   336 		"file %s: line %d: assertion `%s' failed",	\
       
   337 		__FILE__,					\
       
   338 		__LINE__,					\
       
   339 		#expr);						\
       
   340 	 return (val);						\
       
   341        };				}G_STMT_END
       
   342 
       
   343 #define g_return_if_reached()		G_STMT_START{		\
       
   344      g_log (G_LOG_DOMAIN,					\
       
   345 	    G_LOG_LEVEL_CRITICAL,				\
       
   346 	    "file %s: line %d: should not be reached",		\
       
   347 	    __FILE__,						\
       
   348 	    __LINE__);						\
       
   349      return;				}G_STMT_END
       
   350 
       
   351 #define g_return_val_if_reached(val)	G_STMT_START{		\
       
   352      g_log (G_LOG_DOMAIN,					\
       
   353 	    G_LOG_LEVEL_CRITICAL,				\
       
   354 	    "file %s: line %d: should not be reached",		\
       
   355 	    __FILE__,						\
       
   356 	    __LINE__);						\
       
   357      return (val);			}G_STMT_END
       
   358 
       
   359 #endif /* !__GNUC__ */
       
   360 
       
   361 #endif /* !G_DISABLE_CHECKS */
       
   362 
       
   363 G_END_DECLS
       
   364 
       
   365 #endif /* __G_MESSAGES_H__ */
       
   366