jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.0KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. Copyright (C) 2008 Nedko Arnaudov
  5. Copyright (C) 2013 Samsung Electronics
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation; either version 2.1 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include "JackError.h"
  21. #include "JackGlobals.h"
  22. #include "JackMessageBuffer.h"
  23. #define LOG_BUF_SIZE 1024
  24. #undef LOG_TAG
  25. #ifdef SERVER_SIDE
  26. #define LOG_TAG "JackAudioServer"
  27. #else
  28. #define LOG_TAG "JackAudioClient"
  29. #endif
  30. #include <utils/Log.h>
  31. using namespace Jack;
  32. static bool change_thread_log_function(jack_log_function_t log_function)
  33. {
  34. return (jack_tls_get(JackGlobals::fKeyLogFunction) == NULL
  35. && jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function));
  36. }
  37. SERVER_EXPORT int set_threaded_log_function()
  38. {
  39. return change_thread_log_function(JackMessageBufferAdd);
  40. }
  41. void jack_log_function(int level, const char *message)
  42. {
  43. void (* log_callback)(const char *);
  44. switch (level)
  45. {
  46. case LOG_LEVEL_INFO:
  47. log_callback = jack_info_callback;
  48. break;
  49. case LOG_LEVEL_ERROR:
  50. log_callback = jack_error_callback;
  51. break;
  52. default:
  53. return;
  54. }
  55. log_callback(message);
  56. }
  57. static void jack_format_and_log(int level, const char *prefix, const char *fmt, va_list ap)
  58. {
  59. char buffer[256];
  60. size_t len;
  61. jack_log_function_t log_function;
  62. if (prefix != NULL) {
  63. len = strlen(prefix);
  64. assert(len < 256);
  65. memcpy(buffer, prefix, len);
  66. } else {
  67. len = 0;
  68. }
  69. vsnprintf(buffer + len, sizeof(buffer) - len, fmt, ap);
  70. log_function = (jack_log_function_t)jack_tls_get(JackGlobals::fKeyLogFunction);
  71. /* if log function is not overridden for thread, use default one */
  72. if (log_function == NULL)
  73. {
  74. log_function = jack_log_function;
  75. //log_function(LOG_LEVEL_INFO, "------ Using default log function");
  76. }
  77. else
  78. {
  79. //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
  80. }
  81. log_function(level, buffer);
  82. }
  83. SERVER_EXPORT void jack_error(const char *fmt, ...)
  84. {
  85. va_list ap;
  86. char buf[LOG_BUF_SIZE];
  87. va_start(ap, fmt);
  88. vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
  89. va_end(ap);
  90. __android_log_write(ANDROID_LOG_ERROR, LOG_TAG, buf);
  91. }
  92. SERVER_EXPORT void jack_info(const char *fmt, ...)
  93. {
  94. va_list ap;
  95. char buf[LOG_BUF_SIZE];
  96. va_start(ap, fmt);
  97. vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
  98. va_end(ap);
  99. __android_log_write(ANDROID_LOG_INFO, LOG_TAG, buf);
  100. }
  101. SERVER_EXPORT void jack_log(const char *fmt,...)
  102. {
  103. va_list ap;
  104. char buf[LOG_BUF_SIZE];
  105. if (JackGlobals::fVerbose) {
  106. va_start(ap, fmt);
  107. vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
  108. va_end(ap);
  109. __android_log_write(ANDROID_LOG_VERBOSE, LOG_TAG, buf);
  110. }
  111. }
  112. SERVER_EXPORT void default_jack_error_callback(const char *desc)
  113. {
  114. fprintf(stderr, "%s\n", desc);
  115. fflush(stderr);
  116. }
  117. SERVER_EXPORT void default_jack_info_callback(const char *desc)
  118. {
  119. fprintf(stdout, "%s\n", desc);
  120. fflush(stdout);
  121. }
  122. SERVER_EXPORT void silent_jack_error_callback(const char *desc)
  123. {}
  124. SERVER_EXPORT void silent_jack_info_callback(const char *desc)
  125. {}
  126. SERVER_EXPORT void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
  127. SERVER_EXPORT void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;