error.h

Go to the documentation of this file.
00001 /*
00002  * DB-ALLe - Archive for punctual meteorological data
00003  *
00004  * Copyright (C) 2005,2006  ARPA-SIM <urpsim@smr.arpa.emr.it>
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.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00022 #ifndef DBA_ERROR_H
00023 #define DBA_ERROR_H
00024 
00025 #ifdef  __cplusplus
00026 extern "C" {
00027 #endif
00028 
00130 enum _dba_err {
00131     DBA_OK = 0,
00132     DBA_ERROR = 1
00133 };
00135 typedef enum _dba_err dba_err;
00136 
00141 typedef enum {
00143     DBA_ERR_NONE            =  0,
00145     DBA_ERR_NOTFOUND        =  1,
00147     DBA_ERR_TYPE            =  2,
00149     DBA_ERR_ALLOC           =  3,
00151     DBA_ERR_ODBC            =  4,
00153     DBA_ERR_HANDLES         =  5,
00155     DBA_ERR_TOOLONG         =  6,
00157     DBA_ERR_SYSTEM          =  7,
00159     DBA_ERR_CONSISTENCY     =  8,
00161     DBA_ERR_PARSE           =  9,
00163     DBA_ERR_WRITE           = 10,
00165     DBA_ERR_REGEX           = 11,
00167     DBA_ERR_UNIMPLEMENTED   = 12
00168 } dba_err_code;
00169 
00174 typedef void (*dba_err_callback)(void* data);
00175 
00176 
00181 #define DBA_RUN_OR_RETURN(...) do { \
00182         dba_err err = __VA_ARGS__; \
00183         if (err != DBA_OK) \
00184             return err; \
00185     } while (0)
00186 
00225 #define DBA_RUN_OR_GOTO(label, ...) do { \
00226         err = __VA_ARGS__; \
00227         if (err != DBA_OK) \
00228             goto label; \
00229     } while (0)
00230 
00240 #define DBA_FAIL_RETURN(...) do { \
00241         return __VA_ARGS__; \
00242     } while (0)
00243 
00253 #define DBA_FAIL_GOTO(label, ...) do { \
00254         err = __VA_ARGS__; \
00255         goto label; \
00256     } while (0)
00257 
00273 dba_err dba_error_generic0(dba_err_code code, char* context, char* extended_message);
00274 
00287 dba_err dba_error_generic1(dba_err_code code, const char* fmt, ...);
00288 
00295 dba_err dba_error_ok();
00296 
00306 #define dba_error_notfound(fmt, ...) dba_error_generic1(DBA_ERR_NOTFOUND, fmt , ## __VA_ARGS__)
00307 
00318 #define dba_error_type(fmt, ...) dba_error_generic1(DBA_ERR_TYPE, fmt , ## __VA_ARGS__)
00319 
00326 dba_err dba_error_alloc(const char* message);
00327 
00339 #define dba_error_handles(fmt, ...) dba_error_generic1(DBA_ERR_HANDLES, fmt , ## __VA_ARGS__)
00340 
00350 #define dba_error_toolong(fmt, ...) dba_error_generic1(DBA_ERR_TOOLONG, fmt , ## __VA_ARGS__)
00351 
00362 dba_err dba_error_system(const char* fmt, ...);
00363 
00373 #define dba_error_consistency(fmt, ...) dba_error_generic1(DBA_ERR_CONSISTENCY, fmt , ## __VA_ARGS__)
00374 
00388 dba_err dba_error_parse(const char* file, int line, const char* fmt, ...);
00389 
00404 dba_err dba_error_regexp(int code, void* re, const char* fmt, ...);
00405 
00415 #define dba_error_unimplemented(fmt, ...) dba_error_generic1(DBA_ERR_UNIMPLEMENTED, fmt , ## __VA_ARGS__)
00416 
00417 
00424 dba_err_code dba_error_get_code();
00425 
00433 const char* dba_error_get_message();
00434 
00441 const char* dba_error_get_context();
00442 
00451 const char* dba_error_get_details();
00452 
00459 const char* dba_error_get_backtrace();
00460 
00474 void dba_error_set_callback(dba_err_code code, dba_err_callback cb, void* data);
00475 
00488 void dba_error_remove_callback(dba_err_code code, dba_err_callback cb, void* data);
00489 
00490 
00491 struct _dba_error_info;
00496 typedef struct _dba_error_info* dba_error_info;
00497 
00507 void dba_error_state_get(dba_error_info* info);
00508 
00515 void dba_error_state_set(dba_error_info info);
00516 
00520 void dba_error_state_delete(dba_error_info* info);
00521 
00522 
00526 void dba_error_print_to_stderr();
00527 
00528 
00529 #ifdef  __cplusplus
00530 }
00531 #endif
00532 
00533 /* vim:set ts=4 sw=4: */
00534 #endif

Generated on Fri Jun 22 15:34:02 2007 for libdballe-db by  doxygen 1.5.2