error.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. voltlogger_oscilloscope
  3. Copyright (C) 2015 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
  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 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef __CLSYNC_ERROR_H
  16. #define __CLSYNC_ERROR_H
  17. #define BACKTRACE_LENGTH 256
  18. #ifdef _DEBUG_FORCE
  19. # define DEBUGLEVEL_LIMIT 255
  20. #else
  21. # define DEBUGLEVEL_LIMIT 9
  22. #endif
  23. extern void _critical( const char *const function_name, const char *fmt, ...);
  24. #define critical(...) _critical(__FUNCTION__, __VA_ARGS__)
  25. #define critical_on(cond) {debug(30, "critical_on: checking: %s", TOSTR(cond)); if (unlikely(cond)) {critical("Assert: "TOSTR(cond));}}
  26. extern void _error(const char *const function_name, const char *fmt, ...);
  27. #define error(...) _error(__FUNCTION__, __VA_ARGS__)
  28. #define error_on(cond) {if (unlikely(cond)) {error("Error: ("TOSTR(cond)") != 0");}}
  29. extern void _warning(const char *const function_name, const char *fmt, ...);
  30. #define warning(...) _warning(__FUNCTION__, __VA_ARGS__)
  31. extern void _info(const char *const function_name, const char *fmt, ...);
  32. #define info(...) _info(__FUNCTION__, __VA_ARGS__)
  33. #ifdef _DEBUG_SUPPORT
  34. extern void _debug(int debug_level, const char *const function_name, const char *fmt, ...);
  35. # define debug(debug_level, ...) {if (debug_level < DEBUGLEVEL_LIMIT) _debug(debug_level, __FUNCTION__, __VA_ARGS__);}
  36. # define error_or_debug(debug_level, ...) ((debug_level)<0 ? _error(__FUNCTION__, __VA_ARGS__) : _debug(debug_level, __FUNCTION__, __VA_ARGS__))
  37. #else
  38. # define debug(debug_level, ...) {}
  39. # define error_or_debug(debug_level, ...) ((debug_level)<0 ? _error(__FUNCTION__, __VA_ARGS__) : (void)0)
  40. #endif
  41. #define debug_call(debug_level, code) debug(debug_level, "%s -> %i", TOSTR(code), code)
  42. #define critical_or_warning(cond, ...) ((cond) ? _critical : _warning)(__FUNCTION__, __VA_ARGS__)
  43. enum ipc_type {
  44. IPCT_PRIVATE,
  45. IPCT_SHARED,
  46. };
  47. typedef enum ipc_type ipc_type_t;
  48. extern void error_init(void *_outputmethod, int *_quiet, int *_verbose, int *_debug);
  49. extern void error_init_ipc(ipc_type_t ipc_type);
  50. extern void error_deinit();
  51. enum outputmethod {
  52. OM_STDERR = 0,
  53. OM_STDOUT,
  54. OM_SYSLOG,
  55. OM_MAX
  56. };
  57. typedef enum outputmethod outputmethod_t;
  58. #endif