Clarification about jack_port_get_latency_range().
[jack2.git] / common / JackError.cpp
blobb0a9fe3a21bce31af3727879d7bfd857b3fac23f
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 Copyright (C) 2008 Nedko Arnaudov
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.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include "JackError.h"
25 #include "JackGlobals.h"
26 #include "JackMessageBuffer.h"
28 using namespace Jack;
30 static bool change_thread_log_function(jack_log_function_t log_function)
32 return (jack_tls_get(JackGlobals::fKeyLogFunction) == NULL
33 && jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function));
36 SERVER_EXPORT int set_threaded_log_function()
38 return change_thread_log_function(JackMessageBufferAdd);
41 void jack_log_function(int level, const char *message)
43 void (* log_callback)(const char *);
45 switch (level)
47 case LOG_LEVEL_INFO:
48 log_callback = jack_info_callback;
49 break;
50 case LOG_LEVEL_ERROR:
51 log_callback = jack_error_callback;
52 break;
53 default:
54 return;
57 log_callback(message);
60 static void jack_format_and_log(int level, const char *prefix, const char *fmt, va_list ap)
62 char buffer[256];
63 size_t len;
64 jack_log_function_t log_function;
66 if (prefix != NULL) {
67 len = strlen(prefix);
68 assert(len < 256);
69 memcpy(buffer, prefix, len);
70 } else {
71 len = 0;
74 vsnprintf(buffer + len, sizeof(buffer) - len, fmt, ap);
76 log_function = (jack_log_function_t)jack_tls_get(JackGlobals::fKeyLogFunction);
78 /* if log function is not overridden for thread, use default one */
79 if (log_function == NULL)
81 log_function = jack_log_function;
82 //log_function(LOG_LEVEL_INFO, "------ Using default log function");
84 else
86 //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
89 log_function(level, buffer);
92 SERVER_EXPORT void jack_error(const char *fmt, ...)
94 va_list ap;
95 va_start(ap, fmt);
96 jack_format_and_log(LOG_LEVEL_ERROR, NULL, fmt, ap);
97 va_end(ap);
100 SERVER_EXPORT void jack_info(const char *fmt, ...)
102 va_list ap;
103 va_start(ap, fmt);
104 jack_format_and_log(LOG_LEVEL_INFO, NULL, fmt, ap);
105 va_end(ap);
108 SERVER_EXPORT void jack_log(const char *fmt,...)
110 if (JackGlobals::fVerbose) {
111 va_list ap;
112 va_start(ap, fmt);
113 jack_format_and_log(LOG_LEVEL_INFO, "Jack: ", fmt, ap);
114 va_end(ap);
118 SERVER_EXPORT void default_jack_error_callback(const char *desc)
120 fprintf(stderr, "%s\n", desc);
121 fflush(stderr);
124 SERVER_EXPORT void default_jack_info_callback(const char *desc)
126 fprintf(stdout, "%s\n", desc);
127 fflush(stdout);
130 SERVER_EXPORT void silent_jack_error_callback(const char *desc)
133 SERVER_EXPORT void silent_jack_info_callback(const char *desc)
136 SERVER_EXPORT void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
137 SERVER_EXPORT void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;