2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: error.h,v 1.11.4.3 2007-12-31 16:25:00 zer0 Exp $
25 #ifndef _AVERSIVE_ERROR_H_
26 #error "Don't include <error.h>, include <aversive/error.h> instead"
29 #include <aversive/pgmspace.h>
31 #include <general_errors.h>
33 #include "error_config.h"
35 #define ERROR_SEVERITY_EMERG 0
36 #define ERROR_SEVERITY_ERROR 1
37 #define ERROR_SEVERITY_WARNING 2
38 #define ERROR_SEVERITY_NOTICE 3
39 #define ERROR_SEVERITY_DEBUG 4
41 /** The error structure, which is given as a parameter in log funcs */
52 void (*emerg)(struct error *, ...);
53 void (*error)(struct error *, ...);
54 void (*warning)(struct error *, ...);
55 void (*notice)(struct error *, ...);
56 void (*debug)(struct error *, ...);
59 extern struct error_fct g_error_fct;
62 struct error error_generate(uint8_t num, uint8_t severity, PGM_P t, PGM_P f, uint16_t l);
64 /** Register log function for EMERG level */
65 void error_register_emerg(void (*f)(struct error *, ...));
67 /** Register log function for ERROR level */
68 void error_register_error(void (*f)(struct error *, ...));
70 /** Register log function for WARNING level */
71 void error_register_warning(void (*f)(struct error *, ...));
73 /** Register log function for NOTICE level */
74 void error_register_notice(void (*f)(struct error *, ...));
76 /** Register log function for DEBUG level */
77 void error_register_debug(void (*f)(struct error *, ...));
82 /** Call this macro to log EMERG events */
83 #define EMERG(num, text, ...) do { \
84 if(g_error_fct.emerg) { \
85 struct error e = error_generate(num, ERROR_SEVERITY_EMERG, \
89 g_error_fct.emerg(&e, ##__VA_ARGS__); \
93 /** Call this macro to log ERROR events */
94 #define ERROR(num, text, ...) do { \
95 if(g_error_fct.error) { \
96 struct error e = error_generate(num, ERROR_SEVERITY_ERROR, \
100 g_error_fct.error(&e, ##__VA_ARGS__); \
104 /** Call this macro to log WARNING events */
105 #define WARNING(num, text, ...) do { \
106 if(g_error_fct.warning) { \
107 struct error e = error_generate(num, ERROR_SEVERITY_WARNING, \
111 g_error_fct.warning(&e, ##__VA_ARGS__); \
115 /** Call this macro to log NOTICE events */
116 #define NOTICE(num, text, ...) do { \
117 if(g_error_fct.notice) { \
118 struct error e = error_generate(num, ERROR_SEVERITY_NOTICE, \
122 g_error_fct.notice(&e, ##__VA_ARGS__); \
126 /** Call this macro to log DEBUG events */
127 #define DEBUG(num, text, ...) do { \
128 if(g_error_fct.debug) { \
129 struct error e = error_generate(num, ERROR_SEVERITY_DEBUG, \
133 g_error_fct.debug(&e, ##__VA_ARGS__); \
140 #endif /* _ERROR_H_ */