00001 /* $Id: irplib_error.h,v 1.4 2007/10/04 08:57:15 rhaigron Exp $ 00002 * 00003 * This file is part of the irplib package 00004 * Copyright (C) 2002,2003,2004,2005,2006 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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA 00019 */ 00020 00021 /* 00022 * $Author: rhaigron $ 00023 * $Date: 2007/10/04 08:57:15 $ 00024 * $Revision: 1.4 $ 00025 * $Name: HEAD $ 00026 */ 00027 00028 #ifndef IRPLIB_ERROR_H 00029 #define IRPLIB_ERROR_H 00030 00031 /*----------------------------------------------------------------------------- 00032 Includes 00033 -----------------------------------------------------------------------------*/ 00034 00035 #include <cpl.h> 00036 #include <xsh_msg.h> 00037 /*----------------------------------------------------------------------------*/ 00041 /*----------------------------------------------------------------------------*/ 00044 /*----------------------------------------------------------------------------- 00045 Define 00046 -----------------------------------------------------------------------------*/ 00047 /* fixme: This is to avoid including irplib_utils.h which includes this file */ 00048 #if defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__ 00049 #ifndef __func__ 00050 #define __func__ "" 00051 #endif 00052 #endif 00053 00054 /*----------------------------------------------------------------------------*/ 00153 /*----------------------------------------------------------------------------*/ 00154 00155 #define irplib_error_assure(CONDITION, ERROR_CODE, MSG, ACTION) \ 00156 do {\ 00157 if (cpl_error_get_code() != CPL_ERROR_NONE){ \ 00158 irplib_error_push(cpl_error_get_code(), \ 00159 ("An error occurred that was not caught: %s", \ 00160 cpl_error_get_where()) ); \ 00161 ACTION; \ 00162 } \ 00163 else if (!(CONDITION)) \ 00164 {\ 00165 irplib_error_push(ERROR_CODE, MSG); \ 00166 ACTION; \ 00167 } \ 00168 } while (0) 00169 00170 /*----------------------------------------------------------------------------*/ 00180 /*----------------------------------------------------------------------------*/ 00181 #define irplib_error_push(ec, msg) \ 00182 do { \ 00183 xsh_irplib_error_set_msg msg; \ 00184 xsh_irplib_error_push_macro(__func__, ec, __FILE__, __LINE__); \ 00185 } while (0) 00186 00187 00188 00189 /*----------------------------------------------------------------------------*/ 00222 /*----------------------------------------------------------------------------*/ 00223 #define irplib_error_dump(severity, trace_severity) \ 00224 xsh_irplib_error_dump_macro(__func__, __FILE__, __LINE__, \ 00225 severity, trace_severity) 00226 00227 /*----------------------------------------------------------------------------- 00228 Functions prototypes 00229 -----------------------------------------------------------------------------*/ 00230 00231 void xsh_irplib_error_reset(void); 00232 00233 /* 00234 * The following functions should not be called directly ; but they must 00235 * be exported in order to support the macro nature of the interface 00236 */ 00237 cpl_error_code xsh_irplib_error_push_macro(const char *func, 00238 cpl_error_code ec, 00239 const char *file, 00240 unsigned int line); 00241 void xsh_irplib_error_dump_macro(const char *func, 00242 const char *file, 00243 unsigned int line, 00244 cpl_msg_severity severity, 00245 cpl_msg_severity trace_severity); 00246 00247 void xsh_irplib_error_set_msg(const char *format, ...) 00248 #ifdef __GNUC__ 00249 __attribute__((format (printf, 1, 2))) 00250 #endif 00251 ; 00252 00253 #endif /* IRPLIB_ERROR_H */ 00254