trace.h 3.3 KB

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