trace.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #ifndef OPENER_TRACE_H_
  7. #define OPENER_TRACE_H_
  8. #include <opener_user_conf.h>
  9. /** @file trace.h
  10. * @brief Tracing infrastructure for OpENer
  11. */
  12. #ifdef OPENER_WITH_TRACES
  13. /** @def OPENER_TRACE_LEVEL_ERROR Enable tracing of error messages. This is the
  14. * default if no trace level is given.
  15. */
  16. #define OPENER_TRACE_LEVEL_ERROR 0x01
  17. /** @def OPENER_TRACE_LEVEL_WARNING Enable tracing of warning messages */
  18. #define OPENER_TRACE_LEVEL_WARNING 0x02
  19. /** @def OPENER_TRACE_LEVEL_WARNING Enable tracing of state messages */
  20. #define OPENER_TRACE_LEVEL_STATE 0x04
  21. /** @def OPENER_TRACE_LEVEL_INFO Enable tracing of info messages*/
  22. #define OPENER_TRACE_LEVEL_INFO 0x08
  23. #ifndef OPENER_TRACE_LEVEL
  24. #ifdef WIN32
  25. #pragma message( \
  26. "OPENER_TRACE_LEVEL was not defined setting it to OPENER_TRACE_LEVEL_ERROR")
  27. #else
  28. #warning \
  29. OPENER_TRACE_LEVEL was not defined setting it to OPENER_TRACE_LEVEL_ERROR
  30. #endif
  31. #define OPENER_TRACE_LEVEL OPENER_TRACE_LEVEL_ERROR
  32. #endif
  33. /* @def OPENER_TRACE_ENABLED Can be used for conditional code compilation */
  34. #define OPENER_TRACE_ENABLED
  35. /** @def OPENER_TRACE_ERR(...) Trace error messages.
  36. * In order to activate this trace level set the OPENER_TRACE_LEVEL_ERROR flag
  37. * in OPENER_TRACE_LEVEL.
  38. */
  39. #define OPENER_TRACE_ERR(...) \
  40. do { \
  41. if (OPENER_TRACE_LEVEL_ERROR & OPENER_TRACE_LEVEL) {LOG_TRACE(__VA_ARGS__);} \
  42. } while (0)
  43. /** @def OPENER_TRACE_WARN(...) Trace warning messages.
  44. * In order to activate this trace level set the OPENER_TRACE_LEVEL_WARNING
  45. * flag in OPENER_TRACE_LEVEL.
  46. */
  47. #define OPENER_TRACE_WARN(...) \
  48. do { \
  49. if (OPENER_TRACE_LEVEL_WARNING & OPENER_TRACE_LEVEL) { \
  50. LOG_TRACE(__VA_ARGS__);} \
  51. } while (0)
  52. /** @def OPENER_TRACE_STATE(...) Trace state messages.
  53. * In order to activate this trace level set the OPENER_TRACE_LEVEL_STATE flag
  54. * in OPENER_TRACE_LEVEL.
  55. */
  56. #define OPENER_TRACE_STATE(...) \
  57. do { \
  58. if (OPENER_TRACE_LEVEL_STATE & OPENER_TRACE_LEVEL) {LOG_TRACE(__VA_ARGS__);} \
  59. } while (0)
  60. /** @def OPENER_TRACE_INFO(...) Trace information messages.
  61. * In order to activate this trace level set the OPENER_TRACE_LEVEL_INFO flag
  62. * in OPENER_TRACE_LEVEL.
  63. */
  64. #define OPENER_TRACE_INFO(...) \
  65. do { \
  66. if (OPENER_TRACE_LEVEL_INFO & OPENER_TRACE_LEVEL) {LOG_TRACE(__VA_ARGS__);} \
  67. } while (0)
  68. #else
  69. /* define the tracing macros empty in order to save space */
  70. #define OPENER_TRACE_ERR(...)
  71. #define OPENER_TRACE_WARN(...)
  72. #define OPENER_TRACE_STATE(...)
  73. #define OPENER_TRACE_INFO(...)
  74. #endif
  75. /* TRACING *******************************************************************/
  76. #endif /*OPENER_TRACE_H_*/