1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*
* TDebug.java
*
* This file is part of Tritonus: http://www.tritonus.org/
*/
/*
* Copyright (c) 1999 - 2002 by Matthias Pfisterer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
|<--- this code is formatted to fit into 80 columns --->|
*/
package org.tritonus.share;
import java.io.PrintStream;
import java.util.StringTokenizer;
import java.security.AccessControlException;
public class TDebug
{
public static boolean SHOW_ACCESS_CONTROL_EXCEPTIONS = false;
private static final String PROPERTY_PREFIX = "tritonus.";
// The stream we output to
public static PrintStream m_printStream = System.out;
private static String indent="";
// meta-general
public static boolean TraceAllExceptions = getBooleanProperty("TraceAllExceptions");
public static boolean TraceAllWarnings = getBooleanProperty("TraceAllWarnings");
// general
public static boolean TraceInit = getBooleanProperty("TraceInit");
public static boolean TraceCircularBuffer = getBooleanProperty("TraceCircularBuffer");
public static boolean TraceService = getBooleanProperty("TraceService");
// sampled common implementation
public static boolean TraceAudioSystem = getBooleanProperty("TraceAudioSystem");
public static boolean TraceAudioConfig = getBooleanProperty("TraceAudioConfig");
public static boolean TraceAudioInputStream = getBooleanProperty("TraceAudioInputStream");
public static boolean TraceMixerProvider = getBooleanProperty("TraceMixerProvider");
public static boolean TraceControl = getBooleanProperty("TraceControl");
public static boolean TraceLine = getBooleanProperty("TraceLine");
public static boolean TraceDataLine = getBooleanProperty("TraceDataLine");
public static boolean TraceMixer = getBooleanProperty("TraceMixer");
public static boolean TraceSourceDataLine = getBooleanProperty("TraceSourceDataLine");
public static boolean TraceTargetDataLine = getBooleanProperty("TraceTargetDataLine");
public static boolean TraceClip = getBooleanProperty("TraceClip");
public static boolean TraceAudioFileReader = getBooleanProperty("TraceAudioFileReader");
public static boolean TraceAudioFileWriter = getBooleanProperty("TraceAudioFileWriter");
public static boolean TraceAudioConverter = getBooleanProperty("TraceAudioConverter");
public static boolean TraceAudioOutputStream = getBooleanProperty("TraceAudioOutputStream");
// sampled specific implementation
public static boolean TraceEsdNative = getBooleanProperty("TraceEsdNative");
public static boolean TraceEsdStreamNative = getBooleanProperty("TraceEsdStreamNative");
public static boolean TraceEsdRecordingStreamNative = getBooleanProperty("TraceEsdRecordingStreamNative");
public static boolean TraceAlsaNative = getBooleanProperty("TraceAlsaNative");
public static boolean TraceAlsaMixerNative = getBooleanProperty("TraceAlsaMixerNative");
public static boolean TraceAlsaPcmNative = getBooleanProperty("TraceAlsaPcmNative");
public static boolean TraceMixingAudioInputStream = getBooleanProperty("TraceMixingAudioInputStream");
public static boolean TraceOggNative = getBooleanProperty("TraceOggNative");
public static boolean TraceVorbisNative = getBooleanProperty("TraceVorbisNative");
// midi common implementation
public static boolean TraceMidiSystem = getBooleanProperty("TraceMidiSystem");
public static boolean TraceMidiConfig = getBooleanProperty("TraceMidiConfig");
public static boolean TraceMidiDeviceProvider = getBooleanProperty("TraceMidiDeviceProvider");
public static boolean TraceSequencer = getBooleanProperty("TraceSequencer");
public static boolean TraceMidiDevice = getBooleanProperty("TraceMidiDevice");
// midi specific implementation
public static boolean TraceAlsaSeq = getBooleanProperty("TraceAlsaSeq");
public static boolean TraceAlsaSeqDetails = getBooleanProperty("TraceAlsaSeqDetails");
public static boolean TraceAlsaSeqNative = getBooleanProperty("TraceAlsaSeqNative");
public static boolean TracePortScan = getBooleanProperty("TracePortScan");
public static boolean TraceAlsaMidiIn = getBooleanProperty("TraceAlsaMidiIn");
public static boolean TraceAlsaMidiOut = getBooleanProperty("TraceAlsaMidiOut");
public static boolean TraceAlsaMidiChannel = getBooleanProperty("TraceAlsaMidiChannel");
// misc
public static boolean TraceAlsaCtlNative = getBooleanProperty("TraceAlsaCtlNative");
public static boolean TraceCdda = getBooleanProperty("TraceCdda");
public static boolean TraceCddaNative = getBooleanProperty("TraceCddaNative");
// make this method configurable to write to file, write to stderr,...
public static void out(String strMessage)
{
if (strMessage.length()>0 && strMessage.charAt(0)=='<') {
if (indent.length()>2) {
indent=indent.substring(2);
} else {
indent="";
}
}
String newMsg=null;
if (indent!="" && strMessage.indexOf("\n")>=0) {
newMsg="";
StringTokenizer tokenizer=new StringTokenizer(strMessage, "\n");
while (tokenizer.hasMoreTokens()) {
newMsg+=indent+tokenizer.nextToken()+"\n";
}
} else {
newMsg=indent+strMessage;
}
m_printStream.println(newMsg);
if (strMessage.length()>0 && strMessage.charAt(0)=='>') {
indent+=" ";
}
}
public static void out(Throwable throwable)
{
throwable.printStackTrace(m_printStream);
}
public static void assertion(boolean bAssertion)
{
if (!bAssertion)
{
throw new AssertException();
}
}
public static class AssertException
extends RuntimeException
{
public AssertException()
{
}
public AssertException(String sMessage)
{
super(sMessage);
}
}
private static boolean getBooleanProperty(String strName)
{
String strPropertyName = PROPERTY_PREFIX + strName;
String strValue = "false";
try
{
strValue = System.getProperty(strPropertyName, "false");
}
catch (AccessControlException e)
{
if (SHOW_ACCESS_CONTROL_EXCEPTIONS)
{
out(e);
}
}
// TDebug.out("property: " + strPropertyName + "=" + strValue);
boolean bValue = strValue.toLowerCase().equals("true");
// TDebug.out("bValue: " + bValue);
return bValue;
}
}
/*** TDebug.java ***/
|