SVG of thorsten's editor track/bus list icons
[ardour2.git] / libs / appleutility / CADebugMacros.h
blob1abae40187d1e841e8f319578b67f299353ac6a0
1 /* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
3 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
4 ("Apple") in consideration of your agreement to the following terms, and your
5 use, installation, modification or redistribution of this Apple software
6 constitutes acceptance of these terms. If you do not agree with these terms,
7 please do not use, install, modify or redistribute this Apple software.
9 In consideration of your agreement to abide by the following terms, and subject
10 to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
11 copyrights in this original Apple software (the "Apple Software"), to use,
12 reproduce, modify and redistribute the Apple Software, with or without
13 modifications, in source and/or binary forms; provided that if you redistribute
14 the Apple Software in its entirety and without modifications, you must retain
15 this notice and the following text and disclaimers in all such redistributions of
16 the Apple Software. Neither the name, trademarks, service marks or logos of
17 Apple Computer, Inc. may be used to endorse or promote products derived from the
18 Apple Software without specific prior written permission from Apple. Except as
19 expressly stated in this notice, no other rights or licenses, express or implied,
20 are granted by Apple herein, including but not limited to any patent rights that
21 may be infringed by your derivative works or by other works in which the Apple
22 Software may be incorporated.
24 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
25 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
26 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
28 COMBINATION WITH YOUR PRODUCTS.
30 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
34 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
35 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
36 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 /*=============================================================================
39 CADebugMacros.h
41 =============================================================================*/
42 #if !defined(__CADebugMacros_h__)
43 #define __CADebugMacros_h__
45 //=============================================================================
46 // CADebugMacros
47 //=============================================================================
49 //#define CoreAudio_StopOnFailure 1
50 //#define CoreAudio_TimeStampMessages 1
51 //#define CoreAudio_ThreadStampMessages 1
52 //#define CoreAudio_FlushDebugMessages 1
54 #define CA4CCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
56 #pragma mark Basic Definitions
58 #if DEBUG || CoreAudio_Debug
60 // can be used to break into debugger immediately, also see CADebugger
61 #define BusError() (*(long *)0 = 0)
63 // basic debugging print routines
64 #if TARGET_OS_MAC && !TARGET_API_MAC_CARBON
65 extern pascal void DebugStr(const unsigned char* debuggerMsg);
66 #define DebugMessage(msg) DebugStr("\p"msg)
67 #define DebugMessageN1(msg, N1)
68 #define DebugMessageN2(msg, N1, N2)
69 #define DebugMessageN3(msg, N1, N2, N3)
70 #else
71 #include "CADebugPrintf.h"
73 #if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
74 #define FlushRtn ;fflush(DebugPrintfFile)
75 #else
76 #define FlushRtn
77 #endif
79 #if CoreAudio_ThreadStampMessages
80 #include <pthread.h>
81 #include "CAHostTimeBase.h"
82 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: %s"DebugPrintfLineEnding, pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
83 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
84 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
85 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
86 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
87 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
88 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
89 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
90 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
91 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
92 #elif CoreAudio_TimeStampMessages
93 #include "CAHostTimeBase.h"
94 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%.4f: %s"DebugPrintfLineEnding, pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
95 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
96 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
97 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
98 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
99 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
100 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
101 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
102 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
103 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
104 #else
105 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%s"DebugPrintfLineEnding, msg) FlushRtn
106 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1) FlushRtn
107 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2) FlushRtn
108 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3) FlushRtn
109 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4) FlushRtn
110 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5) FlushRtn
111 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6) FlushRtn
112 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7) FlushRtn
113 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
114 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
115 #endif
116 #endif
117 void DebugPrint(const char *fmt, ...); // can be used like printf
118 #define DEBUGPRINT(msg) DebugPrint msg // have to double-parenthesize arglist (see Debugging.h)
119 #if VERBOSE
120 #define vprint(msg) DEBUGPRINT(msg)
121 #else
122 #define vprint(msg)
123 #endif
125 #if CoreAudio_StopOnFailure
126 #include "CADebugger.h"
127 #define STOP CADebuggerStop()
128 #else
129 #define STOP
130 #endif
132 #else
133 #define DebugMessage(msg)
134 #define DebugMessageN1(msg, N1)
135 #define DebugMessageN2(msg, N1, N2)
136 #define DebugMessageN3(msg, N1, N2, N3)
137 #define DebugMessageN4(msg, N1, N2, N3, N4)
138 #define DebugMessageN5(msg, N1, N2, N3, N4, N5)
139 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)
140 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)
141 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)
142 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9)
143 #define DEBUGPRINT(msg)
144 #define vprint(msg)
145 #define STOP
146 #endif
148 void LogError(const char *fmt, ...); // writes to syslog (and stderr if debugging)
149 void LogWarning(const char *fmt, ...); // writes to syslog (and stderr if debugging)
151 #if DEBUG || CoreAudio_Debug
153 #pragma mark Debug Macros
155 #define Assert(inCondition, inMessage) \
156 if(!(inCondition)) \
158 DebugMessage(inMessage); \
159 STOP; \
162 #define AssertNoError(inError, inMessage) \
164 SInt32 __Err = (inError); \
165 if(__Err != 0) \
167 char __4CC[5] = CA4CCToCString(__Err); \
168 DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
169 STOP; \
173 #define AssertNoKernelError(inError, inMessage) \
175 unsigned int __Err = (unsigned int)(inError); \
176 if(__Err != 0) \
178 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
179 STOP; \
183 #define FailIf(inCondition, inHandler, inMessage) \
184 if(inCondition) \
186 DebugMessage(inMessage); \
187 STOP; \
188 goto inHandler; \
191 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
192 if(inCondition) \
194 DebugMessage(inMessage); \
195 STOP; \
196 { inAction; } \
197 goto inHandler; \
200 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
201 if((inPointer) == NULL) \
203 DebugMessage(inMessage); \
204 STOP; \
205 { inAction; } \
206 goto inHandler; \
209 #define FailIfKernelError(inKernelError, inException, inMessage) \
211 kern_return_t __Err = (inKernelError); \
212 if(__Err != 0) \
214 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
215 STOP; \
216 { inAction; } \
217 goto inHandler; \
221 #define FailIfError(inError, inException, inMessage) \
223 SInt32 __Err = (inError); \
224 if(__Err != 0) \
226 char __4CC[5] = CA4CCToCString(__Err); \
227 DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
228 STOP; \
229 { inAction; } \
230 goto inHandler; \
234 #if defined(__cplusplus)
236 #define Throw(inException) STOP; throw (inException)
238 #define ThrowIf(inCondition, inException, inMessage) \
239 if(inCondition) \
241 DebugMessage(inMessage); \
242 Throw(inException); \
245 #define ThrowIfNULL(inPointer, inException, inMessage) \
246 if((inPointer) == NULL) \
248 DebugMessage(inMessage); \
249 Throw(inException); \
252 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
254 kern_return_t __Err = (inKernelError); \
255 if(__Err != 0) \
257 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
258 Throw(inException); \
262 #define ThrowIfError(inError, inException, inMessage) \
264 SInt32 __Err = (inError); \
265 if(__Err != 0) \
267 char __4CC[5] = CA4CCToCString(__Err); \
268 DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
269 Throw(inException); \
273 #if TARGET_OS_WIN32
274 #define ThrowIfWinError(inError, inException, inMessage) \
276 HRESULT __Err = (inError); \
277 if(FAILED(__Err)) \
279 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
280 Throw(inException); \
283 #endif
285 #define SubclassResponsibility(inMethodName, inException) \
287 DebugMessage(inMethodName": Subclasses must implement this method"); \
288 Throw(inException); \
291 #endif // defined(__cplusplus)
293 #else
295 #pragma mark Release Macros
297 #define Assert(inCondition, inMessage) \
298 if(!(inCondition)) \
300 STOP; \
303 #define AssertNoError(inError, inMessage) \
305 SInt32 __Err = (inError); \
306 if(__Err != 0) \
308 STOP; \
312 #define AssertNoKernelError(inError, inMessage) \
314 unsigned int __Err = (unsigned int)(inError); \
315 if(__Err != 0) \
317 STOP; \
321 #define FailIf(inCondition, inHandler, inMessage) \
322 if(inCondition) \
324 STOP; \
325 goto inHandler; \
328 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
329 if(inCondition) \
331 STOP; \
332 { inAction; } \
333 goto inHandler; \
336 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
337 if((inPointer) == NULL) \
339 STOP; \
340 { inAction; } \
341 goto inHandler; \
344 #define FailIfKernelError(inKernelError, inException, inMessage) \
345 if((inKernelError) != 0) \
347 STOP; \
348 { inAction; } \
349 goto inHandler; \
352 #define FailIfError(inError, inException, inMessage) \
353 if((inError) != 0) \
355 STOP; \
356 { inAction; } \
357 goto inHandler; \
360 #if defined(__cplusplus)
362 #define Throw(inException) STOP; throw (inException)
364 #define ThrowIf(inCondition, inException, inMessage) \
365 if(inCondition) \
367 Throw(inException); \
370 #define ThrowIfNULL(inPointer, inException, inMessage) \
371 if((inPointer) == NULL) \
373 Throw(inException); \
376 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
378 kern_return_t __Err = (inKernelError); \
379 if(__Err != 0) \
381 Throw(inException); \
385 #define ThrowIfError(inError, inException, inMessage) \
387 SInt32 __Err = (inError); \
388 if(__Err != 0) \
390 Throw(inException); \
394 #if TARGET_OS_WIN32
395 #define ThrowIfWinError(inError, inException, inMessage) \
397 HRESULT __Err = (inError); \
398 if(FAILED(__Err)) \
400 Throw(inException); \
403 #endif
405 #define SubclassResponsibility(inMethodName, inException) \
407 Throw(inException); \
410 #endif // defined(__cplusplus)
412 #endif // DEBUG || CoreAudio_Debug
414 #endif