00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CX_MESSAGES_H
00029 #define CX_MESSAGES_H
00030
00031 #include <stdarg.h>
00032
00033 #include <cxmacros.h>
00034 #include <cxtypes.h>
00035
00036
00037 CX_BEGIN_DECLS
00038
00039
00040
00041
00042
00043
00044 #define CX_LOG_LEVEL_USER_SHIFT (8)
00045
00046
00047
00048
00049
00050
00051 typedef enum
00052 {
00053
00054 CX_LOG_FLAG_RECURSION = 1 << 0,
00055 CX_LOG_FLAG_FATAL = 1 << 1,
00056
00057
00058 CX_LOG_LEVEL_ERROR = 1 << 2,
00059 CX_LOG_LEVEL_CRITICAL = 1 << 3,
00060 CX_LOG_LEVEL_WARNING = 1 << 4,
00061 CX_LOG_LEVEL_MESSAGE = 1 << 5,
00062 CX_LOG_LEVEL_INFO = 1 << 6,
00063 CX_LOG_LEVEL_DEBUG = 1 << 7,
00064
00065 CX_LOG_LEVEL_MASK = ~(CX_LOG_FLAG_RECURSION | CX_LOG_FLAG_FATAL)
00066 } cx_log_level_flags;
00067
00068 #define CX_LOG_FATAL_MASK (CX_LOG_FLAG_RECURSION | CX_LOG_LEVEL_ERROR)
00069
00070
00071
00072
00073
00074
00075 typedef void (*cx_log_func) (const cxchar *, cx_log_level_flags,
00076 const cxchar *, cxptr);
00077 typedef void (*cx_print_func) (const cxchar *);
00078
00079
00080
00081
00082
00083
00084 void cx_log_default_handler(const cxchar *, cx_log_level_flags,
00085 const cxchar *, cxptr);
00086 cx_log_func cx_log_set_default_handler(cx_log_func);
00087 cxuint cx_log_set_handler(const cxchar *, cx_log_level_flags,
00088 cx_log_func, cxptr);
00089 void cx_log_remove_handler(const cxchar *, cxuint);
00090
00091 cx_log_level_flags cx_log_set_fatal_mask(const cxchar *, cx_log_level_flags);
00092 cx_log_level_flags cx_log_set_always_fatal(cx_log_level_flags);
00093
00094 cxsize cx_log_get_domain_count(void);
00095 const cxchar *cx_log_get_domain_name(cxsize);
00096
00097 void cx_log(const cxchar *, cx_log_level_flags, const cxchar *, ...);
00098 void cx_logv(const cxchar *, cx_log_level_flags, const cxchar *, va_list);
00099
00100 cx_print_func cx_print_set_handler(cx_print_func);
00101 cx_print_func cx_printerr_set_handler(cx_print_func);
00102
00103 void cx_print(const cxchar *, ...);
00104 void cx_printerr(const cxchar *, ...);
00105
00106
00107
00108
00109
00110
00111 void cx_error(const cxchar *, ...);
00112 void cx_critical(const cxchar *, ...);
00113 void cx_warning(const cxchar *, ...);
00114 void cx_message(const cxchar *, ...);
00115
00116
00117 #ifndef CX_LOG_DOMAIN
00118 # define CX_LOG_DOMAIN ((cxchar *)0)
00119 #endif
00120
00121
00122
00123
00124
00125
00126 #ifdef CX_DISABLE_ASSERT
00127
00128 # define cx_assert(expr)
00129
00130 #else
00131
00132 # ifdef __GNUC__
00133 # define cx_assert(expr) \
00134 do { \
00135 if (expr) { \
00136 ; \
00137 } \
00138 else { \
00139 cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, \
00140 "file %s: line %d (%s): assertion failed: (%s)", \
00141 __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
00142 } \
00143 } while (0)
00144 # else
00145 # define cx_assert(expr) \
00146 do { \
00147 if (expr) { \
00148 ; \
00149 } \
00150 else { \
00151 cx_log(CX_LOG_DOMAIN,CX_LOG_LEVEL_ERROR, \
00152 "file %s: line %d: assertion failed: (%s)", \
00153 __FILE__, __LINE__, #expr); \
00154 } \
00155 } while (0)
00156 # endif
00157
00158 #endif
00159
00160 CX_END_DECLS
00161
00162 #endif
00163