msg.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  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 3 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, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef WL_MSG_H
  18. #define WL_MSG_H
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include "misc.h"
  22. enum {
  23. MSG_ERROR = 0,
  24. MSG_WARNING,
  25. MSG_INFO,
  26. MSG_DEBUG,
  27. MSG_LEVEL_MAX
  28. };
  29. void msg(int level, const char *format, ...);
  30. void set_loglevel(int level);
  31. void hexdump(const char *p, unsigned int len);
  32. static inline void debug_printf(const char* fmt, ...)
  33. {
  34. va_list arg_list;
  35. va_start(arg_list, fmt);
  36. msg(MSG_INFO, fmt);
  37. va_end(arg_list);
  38. }
  39. // a simplistic ASSERT based on MSG_ERROR
  40. #define ASSERT(cond) ASSERT_((cond), __FILE__, __LINE__)
  41. #define ASSERT_(cond, file, line) ASSERT__(cond, file, line)
  42. #define ASSERT__(cond, file, line) \
  43. do { \
  44. if (!(cond)) { \
  45. msg(MSG_ERROR, "assert failure in: " \
  46. #file " line:" #line \
  47. " for: " #cond "\n"); \
  48. for (;;) { \
  49. } \
  50. } \
  51. } while (0)
  52. // DP = Debug Print
  53. #define DP(on, varformat) (on) ? debug_printf varformat : (void) 0
  54. // DX = Debug Fail
  55. #define DX() DP(1, ("X %s line %d (%s())\n", __BASE_FILE__, __LINE__, __FUNCTION__))
  56. #endif /* WL_MSG_H */