00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _ERROR_H_
00023 #define _ERROR_H_
00024
00025 #ifndef _AVERSIVE_ERROR_H_
00026 #error "Don't include <error.h>, include <aversive/error.h> instead"
00027 #endif
00028
00029 #include <aversive/pgmspace.h>
00030 #include <aversive.h>
00031 #include <general_errors.h>
00032
00033 #include "error_config.h"
00034
00035 #define ERROR_SEVERITY_EMERG 0
00036 #define ERROR_SEVERITY_ERROR 1
00037 #define ERROR_SEVERITY_WARNING 2
00038 #define ERROR_SEVERITY_NOTICE 3
00039 #define ERROR_SEVERITY_DEBUG 4
00040
00042 struct error {
00043 uint8_t err_num;
00044 uint8_t severity;
00045 PGM_P text;
00046 PGM_P file;
00047 uint16_t line;
00048 };
00049
00050
00051 struct error_fct {
00052 void (*emerg)(struct error *, ...);
00053 void (*error)(struct error *, ...);
00054 void (*warning)(struct error *, ...);
00055 void (*notice)(struct error *, ...);
00056 void (*debug)(struct error *, ...);
00057 } ;
00058
00059 extern struct error_fct g_error_fct;
00060
00061
00062 struct error error_generate(uint8_t num, uint8_t severity, PGM_P t, PGM_P f, uint16_t l);
00063
00065 void error_register_emerg(void (*f)(struct error *, ...));
00066
00068 void error_register_error(void (*f)(struct error *, ...));
00069
00071 void error_register_warning(void (*f)(struct error *, ...));
00072
00074 void error_register_notice(void (*f)(struct error *, ...));
00075
00077 void error_register_debug(void (*f)(struct error *, ...));
00078
00079
00080
00081
00083 #define EMERG(num, text, ...) do { \
00084 if(g_error_fct.emerg) { \
00085 struct error e = error_generate(num, ERROR_SEVERITY_EMERG, \
00086 PSTR(text), \
00087 PSTR(__FILE__),\
00088 __LINE__); \
00089 g_error_fct.emerg(&e, ##__VA_ARGS__); \
00090 } \
00091 } while(0)
00092
00094 #define ERROR(num, text, ...) do { \
00095 if(g_error_fct.error) { \
00096 struct error e = error_generate(num, ERROR_SEVERITY_ERROR, \
00097 PSTR(text), \
00098 PSTR(__FILE__),\
00099 __LINE__); \
00100 g_error_fct.error(&e, ##__VA_ARGS__); \
00101 } \
00102 } while(0)
00103
00105 #define WARNING(num, text, ...) do { \
00106 if(g_error_fct.warning) { \
00107 struct error e = error_generate(num, ERROR_SEVERITY_WARNING, \
00108 PSTR(text), \
00109 PSTR(__FILE__),\
00110 __LINE__); \
00111 g_error_fct.warning(&e, ##__VA_ARGS__); \
00112 } \
00113 } while(0)
00114
00116 #define NOTICE(num, text, ...) do { \
00117 if(g_error_fct.notice) { \
00118 struct error e = error_generate(num, ERROR_SEVERITY_NOTICE, \
00119 PSTR(text), \
00120 PSTR(__FILE__),\
00121 __LINE__); \
00122 g_error_fct.notice(&e, ##__VA_ARGS__); \
00123 } \
00124 } while(0)
00125
00127 #define DEBUG(num, text, ...) do { \
00128 if(g_error_fct.debug) { \
00129 struct error e = error_generate(num, ERROR_SEVERITY_DEBUG, \
00130 PSTR(text), \
00131 PSTR(__FILE__),\
00132 __LINE__); \
00133 g_error_fct.debug(&e, ##__VA_ARGS__); \
00134 } \
00135 } while(0)
00136
00137
00138
00139
00140 #endif