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
/*=============================================================================
41
=============================================================================*/
42
#if !defined(__CADebugMacros_h__)
43
#define __CADebugMacros_h__
45
//=============================================================================
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)
71
#include "CADebugPrintf.h"
73
#if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
74
#define FlushRtn ;fflush(DebugPrintfFile)
79
#if CoreAudio_ThreadStampMessages
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
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
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)
120
#define vprint(msg) DEBUGPRINT(msg)
125
#if CoreAudio_StopOnFailure
126
#include "CADebugger.h"
127
#define STOP CADebuggerStop()
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)
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) \
158
DebugMessage(inMessage); \
162
#define AssertNoError(inError, inMessage) \
164
SInt32 __Err = (inError); \
167
char __4CC[5] = CA4CCToCString(__Err); \
168
DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
173
#define AssertNoKernelError(inError, inMessage) \
175
unsigned int __Err = (unsigned int)(inError); \
178
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
183
#define FailIf(inCondition, inHandler, inMessage) \
186
DebugMessage(inMessage); \
191
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
194
DebugMessage(inMessage); \
200
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
201
if((inPointer) == NULL) \
203
DebugMessage(inMessage); \
209
#define FailIfKernelError(inKernelError, inException, inMessage) \
211
kern_return_t __Err = (inKernelError); \
214
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
221
#define FailIfError(inError, inException, inMessage) \
223
SInt32 __Err = (inError); \
226
char __4CC[5] = CA4CCToCString(__Err); \
227
DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
234
#if defined(__cplusplus)
236
#define Throw(inException) STOP; throw (inException)
238
#define ThrowIf(inCondition, inException, inMessage) \
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); \
257
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
258
Throw(inException); \
262
#define ThrowIfError(inError, inException, inMessage) \
264
SInt32 __Err = (inError); \
267
char __4CC[5] = CA4CCToCString(__Err); \
268
DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
269
Throw(inException); \
274
#define ThrowIfWinError(inError, inException, inMessage) \
276
HRESULT __Err = (inError); \
279
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
280
Throw(inException); \
285
#define SubclassResponsibility(inMethodName, inException) \
287
DebugMessage(inMethodName": Subclasses must implement this method"); \
288
Throw(inException); \
291
#endif // defined(__cplusplus)
295
#pragma mark Release Macros
297
#define Assert(inCondition, inMessage) \
303
#define AssertNoError(inError, inMessage) \
305
SInt32 __Err = (inError); \
312
#define AssertNoKernelError(inError, inMessage) \
314
unsigned int __Err = (unsigned int)(inError); \
321
#define FailIf(inCondition, inHandler, inMessage) \
328
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
336
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
337
if((inPointer) == NULL) \
344
#define FailIfKernelError(inKernelError, inException, inMessage) \
345
if((inKernelError) != 0) \
352
#define FailIfError(inError, inException, inMessage) \
360
#if defined(__cplusplus)
362
#define Throw(inException) STOP; throw (inException)
364
#define ThrowIf(inCondition, inException, inMessage) \
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); \
381
Throw(inException); \
385
#define ThrowIfError(inError, inException, inMessage) \
387
SInt32 __Err = (inError); \
390
Throw(inException); \
395
#define ThrowIfWinError(inError, inException, inMessage) \
397
HRESULT __Err = (inError); \
400
Throw(inException); \
405
#define SubclassResponsibility(inMethodName, inException) \
407
Throw(inException); \
410
#endif // defined(__cplusplus)
412
#endif // DEBUG || CoreAudio_Debug