1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module glib.gmessages; 7 8 import glib.gtypes; 9 10 import core.stdc.stdarg; 11 12 13 extern (C) 14 gsize g_printf_string_upper_bound (const(gchar)* format, 15 va_list args); 16 17 18 enum G_LOG_LEVEL_USER_SHIFT = 8; 19 20 enum GLogLevelFlags 21 { 22 /* log flags */ 23 G_LOG_FLAG_RECURSION = 1 << 0, 24 G_LOG_FLAG_FATAL = 1 << 1, 25 26 /* GLib log levels */ 27 G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */ 28 G_LOG_LEVEL_CRITICAL = 1 << 3, 29 G_LOG_LEVEL_WARNING = 1 << 4, 30 G_LOG_LEVEL_MESSAGE = 1 << 5, 31 G_LOG_LEVEL_INFO = 1 << 6, 32 G_LOG_LEVEL_DEBUG = 1 << 7, 33 34 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL) 35 } 36 37 /* GLib log levels that are considered fatal by default */ 38 enum G_LOG_FATAL_MASK = (GLogLevelFlags.G_LOG_FLAG_RECURSION | 39 GLogLevelFlags.G_LOG_LEVEL_ERROR); 40 41 42 extern (C) { 43 44 alias GLogFunc = void function (const(gchar) *log_domain, 45 GLogLevelFlags log_level, 46 const(gchar) *message, 47 gpointer user_data); 48 49 /* Logging mechanism 50 */ 51 52 guint g_log_set_handler (const(gchar) *log_domain, 53 GLogLevelFlags log_levels, 54 GLogFunc log_func, 55 gpointer user_data); 56 57 void g_log_remove_handler (const(gchar) *log_domain, 58 guint handler_id); 59 60 void g_log_default_handler (const(gchar) *log_domain, 61 GLogLevelFlags log_level, 62 const(gchar) *message, 63 gpointer unused_data); 64 65 GLogFunc g_log_set_default_handler (GLogFunc log_func, 66 gpointer user_data); 67 68 void g_log (const(gchar) *log_domain, 69 GLogLevelFlags log_level, 70 const(gchar) *format, 71 ...); 72 73 void g_logv (const(gchar) *log_domain, 74 GLogLevelFlags log_level, 75 const(gchar) *format, 76 va_list args); 77 78 GLogLevelFlags g_log_set_fatal_mask (const(gchar) *log_domain, 79 GLogLevelFlags fatal_mask); 80 81 GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask); 82 83 /* internal */ 84 void _g_log_fallback_handler (const(gchar) *log_domain, 85 GLogLevelFlags log_level, 86 const(gchar) *message, 87 gpointer unused_data); 88 89 /* Internal functions, used to implement the following macros */ 90 91 void g_return_if_fail_warning (const(char) *log_domain, 92 const(char) *pretty_function, 93 const(char) *expression); 94 95 void g_warn_message (const(char) *domain, 96 const(char) *file, 97 int line, 98 const(char) *func, 99 const(char) *warnexpr); 100 101 deprecated 102 void g_assert_warning (const(char) *log_domain, 103 const(char) *file, 104 const(int) line, 105 const(char) *pretty_function, 106 const(char) *expression); 107 108 } 109 110 // #ifndef G_LOG_DOMAIN 111 // #define G_LOG_DOMAIN ((gchar*) 0) 112 // #endif /* G_LOG_DOMAIN */ 113 // 114 // #if defined(G_HAVE_ISO_VARARGS) && !G_ANALYZER_ANALYZING 115 // /* for(;;) ; so that GCC knows that control doesn't go past g_error(). 116 // * Put space before ending semicolon to avoid C++ build warnings. 117 // */ 118 // #define g_error(...) G_STMT_START { \ 119 // g_log (G_LOG_DOMAIN, \ 120 // G_LOG_LEVEL_ERROR, \ 121 // __VA_ARGS__); \ 122 // for (;;) ; \ 123 // } G_STMT_END 124 // 125 // #define g_message(...) g_log (G_LOG_DOMAIN, \ 126 // G_LOG_LEVEL_MESSAGE, \ 127 // __VA_ARGS__) 128 // #define g_critical(...) g_log (G_LOG_DOMAIN, \ 129 // G_LOG_LEVEL_CRITICAL, \ 130 // __VA_ARGS__) 131 // #define g_warning(...) g_log (G_LOG_DOMAIN, \ 132 // G_LOG_LEVEL_WARNING, \ 133 // __VA_ARGS__) 134 // #define g_info(...) g_log (G_LOG_DOMAIN, \ 135 // G_LOG_LEVEL_INFO, \ 136 // __VA_ARGS__) 137 // #define g_debug(...) g_log (G_LOG_DOMAIN, \ 138 // G_LOG_LEVEL_DEBUG, \ 139 // __VA_ARGS__) 140 // #elif defined(G_HAVE_GNUC_VARARGS) && !G_ANALYZER_ANALYZING 141 // #define g_error(format...) G_STMT_START { \ 142 // g_log (G_LOG_DOMAIN, \ 143 // G_LOG_LEVEL_ERROR, \ 144 // format); \ 145 // for (;;) ; \ 146 // } G_STMT_END 147 // 148 // #define g_message(format...) g_log (G_LOG_DOMAIN, \ 149 // G_LOG_LEVEL_MESSAGE, \ 150 // format) 151 // #define g_critical(format...) g_log (G_LOG_DOMAIN, \ 152 // G_LOG_LEVEL_CRITICAL, \ 153 // format) 154 // #define g_warning(format...) g_log (G_LOG_DOMAIN, \ 155 // G_LOG_LEVEL_WARNING, \ 156 // format) 157 // #define g_info(format...) g_log (G_LOG_DOMAIN, \ 158 // G_LOG_LEVEL_INFO, \ 159 // format) 160 // #define g_debug(format...) g_log (G_LOG_DOMAIN, \ 161 // G_LOG_LEVEL_DEBUG, \ 162 // format) 163 // #else /* no varargs macros */ 164 // static void g_error (const(gchar) *format, ...) G_ANALYZER_NORETURN; 165 // static void g_critical (const(gchar) *format, ...) G_ANALYZER_NORETURN; 166 // 167 // static void 168 // g_error (const(gchar) *format, 169 // ...) 170 // { 171 // va_list args; 172 // va_start (args, format); 173 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args); 174 // va_end (args); 175 // 176 // for(;;) ; 177 // } 178 // static void 179 // g_message (const(gchar) *format, 180 // ...) 181 // { 182 // va_list args; 183 // va_start (args, format); 184 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args); 185 // va_end (args); 186 // } 187 // static void 188 // g_critical (const(gchar) *format, 189 // ...) 190 // { 191 // va_list args; 192 // va_start (args, format); 193 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args); 194 // va_end (args); 195 // } 196 // static void 197 // g_warning (const(gchar) *format, 198 // ...) 199 // { 200 // va_list args; 201 // va_start (args, format); 202 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args); 203 // va_end (args); 204 // } 205 // static void 206 // g_info (const(gchar) *format, 207 // ...) 208 // { 209 // va_list args; 210 // va_start (args, format); 211 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format, args); 212 // va_end (args); 213 // } 214 // static void 215 // g_debug (const(gchar) *format, 216 // ...) 217 // { 218 // va_list args; 219 // va_start (args, format); 220 // g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args); 221 // va_end (args); 222 // } 223 // #endif /* !__GNUC__ */ 224 225 226 extern (C) { 227 228 alias GPrintFunc = void function (const(gchar) *str); 229 230 void g_print (const(gchar) *format, 231 ...); 232 233 GPrintFunc g_set_print_handler (GPrintFunc func); 234 235 void g_printerr (const(gchar) *format, 236 ...); 237 238 GPrintFunc g_set_printerr_handler (GPrintFunc func); 239 240 } 241 // /** 242 // * g_warn_if_reached: 243 // * 244 // * Logs a critical warning. 245 // * 246 // * Since: 2.16 247 // */ 248 // #define g_warn_if_reached() \ 249 // do { \ 250 // g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); \ 251 // } while (0) 252 // 253 // /** 254 // * g_warn_if_fail: 255 // * @expr: the expression to check 256 // * 257 // * Logs a warning if the expression is not true. 258 // * 259 // * Since: 2.16 260 // */ 261 // #define g_warn_if_fail(expr) \ 262 // do { \ 263 // if G_LIKELY (expr) ; \ 264 // else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr); \ 265 // } while (0) 266 // 267 // #ifdef G_DISABLE_CHECKS 268 // 269 // /** 270 // * g_return_if_fail: 271 // * @expr: the expression to check 272 // * 273 // * Verifies that the expression @expr, usually representing a precondition, 274 // * evaluates to %TRUE. If the function returns a value, use 275 // * g_return_val_if_fail() instead. 276 // * 277 // * If @expr evaluates to %FALSE, the current function should be considered to 278 // * have undefined behaviour (a programmer error). The only correct solution 279 // * to such an error is to change the module that is calling the current 280 // * function, so that it avoids this incorrect call. 281 // * 282 // * To make this undefined behaviour visible, if @expr evaluates to %FALSE, 283 // * the result is usually that a critical message is logged and the current 284 // * function returns. 285 // * 286 // * If G_DISABLE_CHECKS is defined then the check is not performed. You 287 // * should therefore not depend on any side effects of @expr. 288 // */ 289 // #define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END 290 // 291 // /** 292 // * g_return_val_if_fail: 293 // * @expr: the expression to check 294 // * @val: the value to return from the current function 295 // * if the expression is not true 296 // * 297 // * Verifies that the expression @expr, usually representing a precondition, 298 // * evaluates to %TRUE. If the function does not return a value, use 299 // * g_return_if_fail() instead. 300 // * 301 // * If @expr evaluates to %FALSE, the current function should be considered to 302 // * have undefined behaviour (a programmer error). The only correct solution 303 // * to such an error is to change the module that is calling the current 304 // * function, so that it avoids this incorrect call. 305 // * 306 // * To make this undefined behaviour visible, if @expr evaluates to %FALSE, 307 // * the result is usually that a critical message is logged and @val is 308 // * returned from the current function. 309 // * 310 // * If G_DISABLE_CHECKS is defined then the check is not performed. You 311 // * should therefore not depend on any side effects of @expr. 312 // */ 313 // #define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END 314 // 315 // /** 316 // * g_return_if_reached: 317 // * 318 // * Logs a critical message and returns from the current function. 319 // * This can only be used in functions which do not return a value. 320 // */ 321 // #define g_return_if_reached() G_STMT_START{ return; }G_STMT_END 322 // 323 // /** 324 // * g_return_val_if_reached: 325 // * @val: the value to return from the current function 326 // * 327 // * Logs a critical message and returns @val. 328 // */ 329 // #define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END 330 // 331 // #else /* !G_DISABLE_CHECKS */ 332 // 333 // #define g_return_if_fail(expr) G_STMT_START{ \ 334 // if G_LIKELY(expr) { } else \ 335 // { \ 336 // g_return_if_fail_warning (G_LOG_DOMAIN, \ 337 // G_STRFUNC, \ 338 // #expr); \ 339 // return; \ 340 // }; }G_STMT_END 341 // 342 // #define g_return_val_if_fail(expr,val) G_STMT_START{ \ 343 // if G_LIKELY(expr) { } else \ 344 // { \ 345 // g_return_if_fail_warning (G_LOG_DOMAIN, \ 346 // G_STRFUNC, \ 347 // #expr); \ 348 // return (val); \ 349 // }; }G_STMT_END 350 // 351 // #define g_return_if_reached() G_STMT_START{ \ 352 // g_log (G_LOG_DOMAIN, \ 353 // G_LOG_LEVEL_CRITICAL, \ 354 // "file %s: line %d (%s): should not be reached", \ 355 // __FILE__, \ 356 // __LINE__, \ 357 // G_STRFUNC); \ 358 // return; }G_STMT_END 359 // 360 // #define g_return_val_if_reached(val) G_STMT_START{ \ 361 // g_log (G_LOG_DOMAIN, \ 362 // G_LOG_LEVEL_CRITICAL, \ 363 // "file %s: line %d (%s): should not be reached", \ 364 // __FILE__, \ 365 // __LINE__, \ 366 // G_STRFUNC); \ 367 // return (val); }G_STMT_END 368 // 369 // #endif /* !G_DISABLE_CHECKS */ 370 //