Main Page | Modules | Directories | File List

cxmessages.h

00001 /* $Id: cxmessages.h,v 1.4 2003/12/29 14:17:40 rpalsa Exp $
00002  *
00003  * This file is part of the ESO C Extension Library
00004  * Copyright (C) 2001-2004 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2003/12/29 14:17:40 $
00024  * $Revision: 1.4 $
00025  * $Name: cpl-2_1_1 $
00026  */
00027 
00028 #ifndef CX_MESSAGES_H
00029 #define CX_MESSAGES_H
00030 
00031 #include <stdarg.h>
00032 #include <cxtypes.h>
00033 
00034 
00035 CX_BEGIN_DECLS
00036 
00037 /*
00038  * Message level offset for user defined message levels
00039  * (0 - 7 are used internally).
00040  */
00041 
00042 #define CX_LOG_LEVEL_USER_SHIFT  (8)
00043 
00044 
00045 /*
00046  * Log levels and flags
00047  */
00048 
00049 typedef enum
00050 {
00051     /* flags */
00052     CX_LOG_FLAG_RECURSION = 1 << 0,
00053     CX_LOG_FLAG_FATAL     = 1 << 1,
00054 
00055     /* levels */
00056     CX_LOG_LEVEL_ERROR    = 1 << 2,
00057     CX_LOG_LEVEL_CRITICAL = 1 << 3,
00058     CX_LOG_LEVEL_WARNING  = 1 << 4,
00059     CX_LOG_LEVEL_MESSAGE  = 1 << 5,
00060     CX_LOG_LEVEL_INFO     = 1 << 6,
00061     CX_LOG_LEVEL_DEBUG    = 1 << 7,
00062 
00063     CX_LOG_LEVEL_MASK     = ~(CX_LOG_FLAG_RECURSION | CX_LOG_FLAG_FATAL)
00064 } cx_log_level_flags;
00065 
00066 #define CX_LOG_FATAL_MASK (CX_LOG_FLAG_RECURSION | CX_LOG_LEVEL_ERROR)
00067 
00068 
00069 /*
00070  * Message handlers
00071  */
00072 
00073 typedef void (*cx_log_func) (const cxchar *, cx_log_level_flags,
00074                                 const cxchar *, cxptr);
00075 typedef void (*cx_print_func) (const cxchar *);
00076 
00077 
00078 /*
00079  * Messaging mechanisms
00080  */
00081 
00082 void cx_log_default_handler(const cxchar *, cx_log_level_flags,
00083                             const cxchar *, cxptr);
00084 cx_log_func cx_log_set_default_handler(cx_log_func);
00085 cxuint cx_log_set_handler(const cxchar *, cx_log_level_flags,
00086                           cx_log_func, cxptr);
00087 void cx_log_remove_handler(const cxchar *, cxuint);
00088 
00089 cx_log_level_flags cx_log_set_fatal_mask(const cxchar *, cx_log_level_flags);
00090 cx_log_level_flags cx_log_set_always_fatal(cx_log_level_flags);
00091 
00092 cxsize cx_log_get_domain_count(void);
00093 const cxchar *cx_log_get_domain_name(cxsize);
00094 
00095 void cx_log(const cxchar *, cx_log_level_flags, const cxchar *, ...);
00096 void cx_logv(const cxchar *, cx_log_level_flags, const cxchar *, va_list);
00097 
00098 cx_print_func cx_print_set_handler(cx_print_func);
00099 cx_print_func cx_printerr_set_handler(cx_print_func);
00100 
00101 void cx_print(const cxchar *, ...);
00102 void cx_printerr(const cxchar *, ...);
00103 
00104 
00105 /*
00106  * Convenience functions
00107  */
00108 
00109 void cx_error(const cxchar *, ...);
00110 void cx_critical(const cxchar *, ...);
00111 void cx_warning(const cxchar *, ...);
00112 void cx_message(const cxchar *, ...);
00113 
00114 
00115 #ifndef CX_LOG_DOMAIN
00116 #  define CX_LOG_DOMAIN  ((cxchar *)0)
00117 #endif
00118 
00119 
00120 /*
00121  * Macros for error handling.
00122  */
00123 
00124 #ifdef CX_DISABLE_ASSERT
00125 
00126 #  define cx_assert(expr)  /* empty */
00127 
00128 #else /* !CX_DISABLE_ASSERT */
00129 
00130 #  ifdef __GNUC_
00131 #    define cx_assert(expr) {                                        \
00132         if (expr) {                                                  \
00133             ;                                                        \
00134         }                                                            \
00135         else                                                         \
00136             cx_log(CX_LOG_DOMAIN,                                    \
00137                    CX_LOG_LEVEL_ERROR,                               \
00138                    "file %s: line %d (%s): assertion failed: (%s)",  \
00139                    __FILE__, __LINE__,                               \
00140                    __PRETTY_FUNCTION__,                              \
00141                    #expr); }
00142 #  else /* !__GNUC__ */
00143 #    define cx_assert(expr) {                                        \
00144         if (expr) {                                                  \
00145             ;                                                        \
00146         }                                                            \
00147         else                                                         \
00148             cx_log(CX_LOG_DOMAIN,                                    \
00149                    CX_LOG_LEVEL_ERROR,                               \
00150                    "file %s: line %d: assertion failed: (%s)",       \
00151                    __FILE__, __LINE__,                               \
00152                    #expr); }
00153 #  endif /* !__GNUC__ */
00154 
00155 #endif /* !CX_DISABLE_ASSERT */
00156                                             
00157 CX_END_DECLS
00158 
00159 #endif /* CX_MESSAGES_H */
00160 
00161 

Generated on Mon Sep 26 14:38:11 2005 for C Standard Library Extensions by  doxygen 1.4.1