se_trace.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. /*
  32. *This file wrapper some trace output.
  33. */
  34. #ifndef _SE_DEBUG_H_
  35. #define _SE_DEBUG_H_
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. typedef enum
  39. {
  40. SE_TRACE_ERROR,
  41. SE_TRACE_WARNING,
  42. SE_TRACE_NOTICE,
  43. SE_TRACE_DEBUG
  44. } se_trace_t;
  45. #ifndef SE_DEBUG_LEVEL
  46. /* Each module need define their own SE_DEBUG_LEVEL */
  47. #define SE_DEBUG_LEVEL SE_TRACE_ERROR
  48. #endif
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. int se_trace_internal(int debug_level, const char *fmt, ...);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. /* For libraries, we usually define DISABLE_TRACE to disable any trace. */
  57. /* For apps, we usually enable trace. */
  58. #ifdef DISABLE_TRACE
  59. #define SE_TRACE(...)
  60. #define se_trace(...)
  61. #else /* DISABLE_TRACE */
  62. #define se_trace(debug_level, fmt, ...) \
  63. do { \
  64. if(debug_level <= SE_DEBUG_LEVEL) \
  65. se_trace_internal(debug_level, fmt, ##__VA_ARGS__); \
  66. }while(0)
  67. /* For compatibility, SE_TRACE/se_trace is used in old code. */
  68. /* New code should use SE_TRACE_DEBUG, SE_TRACE_NOTICE, SE_TRACE_WARNING, SE_TRACE_ERROR */
  69. #define SE_TRACE(debug_level, fmt, ...) \
  70. se_trace(debug_level, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  71. #endif/* DISABLE_TRACE */
  72. /* SE_TRACE_DEBUG and SE_TRACE_NOTICE print the debug information plus message. */
  73. #define SE_TRACE_DEBUG(fmt, ...) se_trace(SE_TRACE_DEBUG, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  74. #define SE_TRACE_NOTICE(fmt, ...) se_trace(SE_TRACE_NOTICE, "[%s %s:%d] " fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
  75. /* SE_TRACE_WARNING and SE_TRACE_ERROR only print message. */
  76. #define SE_TRACE_WARNING(fmt, ...) se_trace(SE_TRACE_WARNING, fmt, ##__VA_ARGS__)
  77. #define SE_TRACE_ERROR(fmt, ...) se_trace(SE_TRACE_ERROR, fmt, ##__VA_ARGS__)
  78. #endif