pa_debugprint.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef PA_LOG_H
  2. #define PA_LOG_H
  3. /*
  4. * Log file redirector function
  5. * Copyright (c) 1999-2006 Ross Bencina, Phil Burk
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files
  9. * (the "Software"), to deal in the Software without restriction,
  10. * including without limitation the rights to use, copy, modify, merge,
  11. * publish, distribute, sublicense, and/or sell copies of the Software,
  12. * and to permit persons to whom the Software is furnished to do so,
  13. * subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  23. * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. /*
  27. * The text above constitutes the entire PortAudio license; however,
  28. * the PortAudio community also makes the following non-binding requests:
  29. *
  30. * Any person wishing to distribute modifications to the Software is
  31. * requested to send the modifications to the original developer so that
  32. * they can be incorporated into the canonical version. It is also
  33. * requested that these non-binding requests be included along with the
  34. * license above.
  35. */
  36. /** @file
  37. @ingroup common_src
  38. */
  39. #ifdef __cplusplus
  40. extern "C"
  41. {
  42. #endif /* __cplusplus */
  43. void PaUtil_DebugPrint( const char *format, ... );
  44. /*
  45. The basic format for log messages is described below. If you need to
  46. add any log messages, please follow this format.
  47. Function entry (void function):
  48. "FunctionName called.\n"
  49. Function entry (non void function):
  50. "FunctionName called:\n"
  51. "\tParam1Type param1: param1Value\n"
  52. "\tParam2Type param2: param2Value\n" (etc...)
  53. Function exit (no return value):
  54. "FunctionName returned.\n"
  55. Function exit (simple return value):
  56. "FunctionName returned:\n"
  57. "\tReturnType: returnValue\n"
  58. If the return type is an error code, the error text is displayed in ()
  59. If the return type is not an error code, but has taken a special value
  60. because an error occurred, then the reason for the error is shown in []
  61. If the return type is a struct ptr, the struct is dumped.
  62. See the code below for examples
  63. */
  64. /** PA_DEBUG() provides a simple debug message printing facility. The macro
  65. passes it's argument to a printf-like function called PaUtil_DebugPrint()
  66. which prints to stderr and always flushes the stream after printing.
  67. Because preprocessor macros cannot directly accept variable length argument
  68. lists, calls to the macro must include an additional set of parenthesis, eg:
  69. PA_DEBUG(("errorno: %d", 1001 ));
  70. */
  71. #ifdef PA_ENABLE_DEBUG_OUTPUT
  72. #define PA_DEBUG(x) PaUtil_DebugPrint x ;
  73. #else
  74. #define PA_DEBUG(x)
  75. #endif
  76. #ifdef PA_LOG_API_CALLS
  77. #define PA_LOGAPI(x) PaUtil_DebugPrint x
  78. #define PA_LOGAPI_ENTER(functionName) PaUtil_DebugPrint( functionName " called.\n" )
  79. #define PA_LOGAPI_ENTER_PARAMS(functionName) PaUtil_DebugPrint( functionName " called:\n" )
  80. #define PA_LOGAPI_EXIT(functionName) PaUtil_DebugPrint( functionName " returned.\n" )
  81. #define PA_LOGAPI_EXIT_PAERROR( functionName, result ) \
  82. PaUtil_DebugPrint( functionName " returned:\n" ); \
  83. PaUtil_DebugPrint("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) )
  84. #define PA_LOGAPI_EXIT_T( functionName, resultFormatString, result ) \
  85. PaUtil_DebugPrint( functionName " returned:\n" ); \
  86. PaUtil_DebugPrint("\t" resultFormatString "\n", result )
  87. #define PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( functionName, positiveResultFormatString, result ) \
  88. PaUtil_DebugPrint( functionName " returned:\n" ); \
  89. if( result > 0 ) \
  90. PaUtil_DebugPrint("\t" positiveResultFormatString "\n", result ); \
  91. else \
  92. PaUtil_DebugPrint("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) )
  93. #else
  94. #define PA_LOGAPI(x)
  95. #define PA_LOGAPI_ENTER(functionName)
  96. #define PA_LOGAPI_ENTER_PARAMS(functionName)
  97. #define PA_LOGAPI_EXIT(functionName)
  98. #define PA_LOGAPI_EXIT_PAERROR( functionName, result )
  99. #define PA_LOGAPI_EXIT_T( functionName, resultFormatString, result )
  100. #define PA_LOGAPI_EXIT_PAERROR_OR_T_RESULT( functionName, positiveResultFormatString, result )
  101. #endif
  102. typedef void (*PaUtilLogCallback ) (const char *log);
  103. /**
  104. Install user provided log function
  105. */
  106. void PaUtil_SetDebugPrintFunction(PaUtilLogCallback cb);
  107. #ifdef __cplusplus
  108. }
  109. #endif /* __cplusplus */
  110. #endif /* PA_LOG_H */