jack: remove unnecessary GPL include from LGPL code
[jack2.git] / android / JackError.cpp
blobe1ba18bc4a871d49b925ad9b0860c48796e4e9a9
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
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "JackError.h"
26 #include "JackGlobals.h"
27 #include "JackMessageBuffer.h"
29 #define LOG_BUF_SIZE 1024
30 #undef LOG_TAG
31 #ifdef SERVER_SIDE
32 #define LOG_TAG "JackAudioServer"
33 #else
34 #define LOG_TAG "JackAudioClient"
35 #endif
36 #include <utils/Log.h>
38 using namespace Jack;
40 static bool change_thread_log_function(jack_log_function_t log_function)
42 return (jack_tls_get(JackGlobals::fKeyLogFunction) == NULL
43 && jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function));
46 SERVER_EXPORT int set_threaded_log_function()
48 return change_thread_log_function(JackMessageBufferAdd);
51 void jack_log_function(int level, const char *message)
53 void (* log_callback)(const char *);
55 switch (level)
57 case LOG_LEVEL_INFO:
58 log_callback = jack_info_callback;
59 break;
60 case LOG_LEVEL_ERROR:
61 log_callback = jack_error_callback;
62 break;
63 default:
64 return;
67 log_callback(message);
70 static void jack_format_and_log(int level, const char *prefix, const char *fmt, va_list ap)
72 char buffer[256];
73 size_t len;
74 jack_log_function_t log_function;
76 if (prefix != NULL) {
77 len = strlen(prefix);
78 assert(len < 256);
79 memcpy(buffer, prefix, len);
80 } else {
81 len = 0;
84 vsnprintf(buffer + len, sizeof(buffer) - len, fmt, ap);
86 log_function = (jack_log_function_t)jack_tls_get(JackGlobals::fKeyLogFunction);
88 /* if log function is not overridden for thread, use default one */
89 if (log_function == NULL)
91 log_function = jack_log_function;
92 //log_function(LOG_LEVEL_INFO, "------ Using default log function");
94 else
96 //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
99 log_function(level, buffer);
102 SERVER_EXPORT void jack_error(const char *fmt, ...)
104 va_list ap;
105 char buf[LOG_BUF_SIZE];
106 va_start(ap, fmt);
107 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
108 va_end(ap);
109 __android_log_write(ANDROID_LOG_ERROR, LOG_TAG, buf);
112 SERVER_EXPORT void jack_info(const char *fmt, ...)
114 va_list ap;
115 char buf[LOG_BUF_SIZE];
116 va_start(ap, fmt);
117 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
118 va_end(ap);
119 __android_log_write(ANDROID_LOG_INFO, LOG_TAG, buf);
122 SERVER_EXPORT void jack_log(const char *fmt,...)
124 va_list ap;
125 char buf[LOG_BUF_SIZE];
126 if (JackGlobals::fVerbose) {
127 va_start(ap, fmt);
128 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
129 va_end(ap);
130 __android_log_write(ANDROID_LOG_VERBOSE, LOG_TAG, buf);
134 SERVER_EXPORT void default_jack_error_callback(const char *desc)
136 fprintf(stderr, "%s\n", desc);
137 fflush(stderr);
140 SERVER_EXPORT void default_jack_info_callback(const char *desc)
142 fprintf(stdout, "%s\n", desc);
143 fflush(stdout);
146 SERVER_EXPORT void silent_jack_error_callback(const char *desc)
149 SERVER_EXPORT void silent_jack_info_callback(const char *desc)
152 SERVER_EXPORT void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
153 SERVER_EXPORT void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;