PageRenderTime 66ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/error/error.h

https://bitbucket.org/cvra/cvra-nios2
C Header | 145 lines | 81 code | 29 blank | 35 comment | 5 complexity | 821d3cb3d3319f7cc2f58f2a4a8909da MD5 | raw file
  1. /*
  2. * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
  3. *
  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.
  8. *
  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.
  13. *
  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
  17. *
  18. * Revision : $Id: error.h,v 1.11.4.3 2007-12-31 16:25:00 zer0 Exp $
  19. *
  20. */
  21. #ifndef _ERROR_H_
  22. #define _ERROR_H_
  23. #ifndef _AVERSIVE_ERROR_H_
  24. #error "Don't include <error.h>, include <aversive/error.h> instead"
  25. #endif
  26. #include <aversive.h>
  27. #include <general_errors.h>
  28. #define ERROR_SEVERITY_EMERG 0
  29. #define ERROR_SEVERITY_ERROR 1
  30. #define ERROR_SEVERITY_WARNING 2
  31. #define ERROR_SEVERITY_NOTICE 3
  32. #define ERROR_SEVERITY_DEBUG 4
  33. /** enable the dump of the comment */
  34. #define ERROR_DUMP_TEXTLOG
  35. /** enable the dump of filename and line number */
  36. #define ERROR_DUMP_FILE_LINE
  37. /** The error structure, which is given as a parameter in log funcs */
  38. struct error {
  39. uint8_t err_num; /**< Error number */
  40. uint8_t severity; /**< Error severity */
  41. const char * text; /**< Error text */
  42. const char * file; /**< File in which the error occurred */
  43. uint16_t line; /**< Line number in which the error occurred */
  44. };
  45. /** Structure of pointers to functions which are called on errors
  46. */
  47. struct error_fct {
  48. void (*emerg)(struct error *, ...); /**< Pointer to emergency func */
  49. void (*error)(struct error *, ...); /**< Pointer to error func */
  50. void (*warning)(struct error *, ...); /**< Pointer to warning func */
  51. void (*notice)(struct error *, ...); /**< Pointer to notice func */
  52. void (*debug)(struct error *, ...); /**< Pointer to debug func */
  53. } ;
  54. extern struct error_fct g_error_fct;
  55. struct error error_generate(uint8_t num, uint8_t severity, const char * t, const char * f, uint16_t l);
  56. /** Register log function for EMERG level */
  57. void error_register_emerg(void (*f)(struct error *, ...));
  58. /** Register log function for ERROR level */
  59. void error_register_error(void (*f)(struct error *, ...));
  60. /** Register log function for WARNING level */
  61. void error_register_warning(void (*f)(struct error *, ...));
  62. /** Register log function for NOTICE level */
  63. void error_register_notice(void (*f)(struct error *, ...));
  64. /** Register log function for DEBUG level */
  65. void error_register_debug(void (*f)(struct error *, ...));
  66. /** Call this macro to log EMERG events */
  67. #define EMERG(num, text, ...) do { \
  68. if(g_error_fct.emerg) { \
  69. struct error e = error_generate(num, ERROR_SEVERITY_EMERG, \
  70. (text), \
  71. (__FILE__),\
  72. __LINE__); \
  73. g_error_fct.emerg(&e, ##__VA_ARGS__); \
  74. } \
  75. } while(0)
  76. /** Call this macro to log ERROR events */
  77. #define ERROR(num, text, ...) do { \
  78. if(g_error_fct.error) { \
  79. struct error e = error_generate(num, ERROR_SEVERITY_ERROR, \
  80. (text), \
  81. (__FILE__),\
  82. __LINE__); \
  83. g_error_fct.error(&e, ##__VA_ARGS__); \
  84. } \
  85. } while(0)
  86. /** Call this macro to log WARNING events */
  87. #define WARNING(num, text, ...) do { \
  88. if(g_error_fct.warning) { \
  89. struct error e = error_generate(num, ERROR_SEVERITY_WARNING, \
  90. (text), \
  91. (__FILE__),\
  92. __LINE__); \
  93. g_error_fct.warning(&e, ##__VA_ARGS__); \
  94. } \
  95. } while(0)
  96. /** Call this macro to log NOTICE events */
  97. #define NOTICE(num, text, ...) do { \
  98. if(g_error_fct.notice) { \
  99. struct error e = error_generate(num, ERROR_SEVERITY_NOTICE, \
  100. (text), \
  101. (__FILE__),\
  102. __LINE__); \
  103. g_error_fct.notice(&e, ##__VA_ARGS__); \
  104. } \
  105. } while(0)
  106. /** Call this macro to log DEBUG events */
  107. #define DEBUG(num, text, ...) do { \
  108. if(g_error_fct.debug) { \
  109. struct error e = error_generate(num, ERROR_SEVERITY_DEBUG, \
  110. (text), \
  111. (__FILE__),\
  112. __LINE__); \
  113. g_error_fct.debug(&e, ##__VA_ARGS__); \
  114. } \
  115. } while(0)
  116. #endif /* _ERROR_H_ */