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