41 #if !defined(__CADebugMacros_h__)
42 #define __CADebugMacros_h__
48 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
49 #include <CoreAudio/CoreAudioTypes.h>
51 #include "CoreAudioTypes.h"
63 #if TARGET_RT_BIG_ENDIAN
64 #define CA4CCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
65 #define CACopy4CCToCString(theCString, the4CC) { theCString[0] = ((char*)&the4CC)[0]; theCString[1] = ((char*)&the4CC)[1]; theCString[2] = ((char*)&the4CC)[2]; theCString[3] = ((char*)&the4CC)[3]; theCString[4] = 0; }
67 #define CA4CCToCString(the4CC) { ((char*)&the4CC)[3], ((char*)&the4CC)[2], ((char*)&the4CC)[1], ((char*)&the4CC)[0], 0 }
68 #define CACopy4CCToCString(theCString, the4CC) { theCString[0] = ((char*)&the4CC)[3]; theCString[1] = ((char*)&the4CC)[2]; theCString[2] = ((char*)&the4CC)[1]; theCString[3] = ((char*)&the4CC)[0]; theCString[4] = 0; }
74 #define SizeOf32(X) ((UInt32)sizeof(X))
79 #define OffsetOf32(X, Y) ((UInt32)offsetof(X, Y))
84 #define ToUInt32(X) ((UInt32)(X))
86 #pragma mark Basic Definitions
88 #if DEBUG || CoreAudio_Debug
91 #define BusError() (*(long *)0 = 0)
94 #if TARGET_OS_MAC && !TARGET_API_MAC_CARBON
95 extern void DebugStr(
const unsigned char* debuggerMsg);
96 #define DebugMessage(msg) DebugStr("\p"msg)
97 #define DebugMessageN1(msg, N1)
98 #define DebugMessageN2(msg, N1, N2)
99 #define DebugMessageN3(msg, N1, N2, N3)
101 #include "CADebugPrintf.h"
103 #if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
104 #define FlushRtn ,fflush(DebugPrintfFile)
109 #if CoreAudio_ThreadStampMessages
111 #include "CAHostTimeBase.h"
112 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: %s"DebugPrintfLineEnding, pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
113 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
114 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
115 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
116 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
117 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
118 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
119 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
120 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
121 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFileComma "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
122 #elif CoreAudio_TimeStampMessages
123 #include "CAHostTimeBase.h"
124 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFileComma "%.4f: %s"DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
125 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
126 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
127 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
128 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
129 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
130 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
131 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
132 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
133 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFileComma "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
135 #define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFileComma "%s"DebugPrintfLineEnding, msg) FlushRtn
136 #define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1) FlushRtn
137 #define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2) FlushRtn
138 #define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3) FlushRtn
139 #define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4) FlushRtn
140 #define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4, N5) FlushRtn
141 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6) FlushRtn
142 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7) FlushRtn
143 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
144 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFileComma msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
147 void DebugPrint(
const char *fmt, ...);
149 #define DEBUGPRINT(msg) DebugPrint msg // have to double-parenthesize arglist (see Debugging.h)
152 #define vprint(msg) DEBUGPRINT(msg)
157 #if CoreAudio_StopOnFailure
158 #include "CADebugger.h"
159 #define STOP CADebuggerStop()
165 #define DebugMessage(msg)
166 #define DebugMessageN1(msg, N1)
167 #define DebugMessageN2(msg, N1, N2)
168 #define DebugMessageN3(msg, N1, N2, N3)
169 #define DebugMessageN4(msg, N1, N2, N3, N4)
170 #define DebugMessageN5(msg, N1, N2, N3, N4, N5)
171 #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)
172 #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)
173 #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)
174 #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9)
176 #define DEBUGPRINT(msg)
182 void LogError(
const char *fmt, ...);
183 void LogWarning(
const char *fmt, ...);
185 #if DEBUG || CoreAudio_Debug
187 #pragma mark Debug Macros
189 #define Assert(inCondition, inMessage) \
192 DebugMessage(inMessage); \
196 #define AssertNoError(inError, inMessage) \
198 SInt32 __Err = (inError); \
201 char __4CC[5] = CA4CCToCString(__Err); \
202 DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
207 #define AssertNoKernelError(inError, inMessage) \
209 unsigned int __Err = (unsigned int)(inError); \
212 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
217 #define FailIf(inCondition, inHandler, inMessage) \
220 DebugMessage(inMessage); \
225 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
228 DebugMessage(inMessage); \
234 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
235 if((inPointer) == NULL) \
237 DebugMessage(inMessage); \
243 #define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
245 unsigned int __Err = (inKernelError); \
248 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
255 #define FailIfError(inError, inAction, inHandler, inMessage) \
257 SInt32 __Err = (inError); \
260 char __4CC[5] = CA4CCToCString(__Err); \
261 DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
268 #if defined(__cplusplus)
270 #define Throw(inException) STOP; throw (inException)
272 #define ThrowIf(inCondition, inException, inMessage) \
275 DebugMessage(inMessage); \
276 Throw(inException); \
279 #define ThrowIfNULL(inPointer, inException, inMessage) \
280 if((inPointer) == NULL) \
282 DebugMessage(inMessage); \
283 Throw(inException); \
286 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
288 unsigned int __Err = (inKernelError); \
291 DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
292 Throw(inException); \
296 #define ThrowIfError(inError, inException, inMessage) \
298 SInt32 __Err = (inError); \
301 char __4CC[5] = CA4CCToCString(__Err); \
302 DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
303 Throw(inException); \
308 #define ThrowIfWinError(inError, inException, inMessage) \
310 HRESULT __Err = (inError); \
313 DebugMessageN2(inMessage ", Code: %d, Facility: 0x%X", HRESULT_CODE(__Err), HRESULT_FACILITY(__Err)); \
314 Throw(inException); \
319 #define SubclassResponsibility(inMethodName, inException) \
321 DebugMessage(inMethodName": Subclasses must implement this method"); \
322 Throw(inException); \
325 #endif // defined(__cplusplus)
329 #pragma mark Release Macros
331 #define Assert(inCondition, inMessage) \
337 #define AssertNoError(inError, inMessage) \
339 SInt32 __Err = (inError); \
346 #define AssertNoKernelError(inError, inMessage) \
348 unsigned int __Err = (unsigned int)(inError); \
355 #define FailIf(inCondition, inHandler, inMessage) \
362 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
370 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
371 if((inPointer) == NULL) \
378 #define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
379 if((inKernelError) != 0) \
386 #define FailIfError(inError, inAction, inHandler, inMessage) \
394 #if defined(__cplusplus)
396 #define Throw(inException) STOP; throw (inException)
398 #define ThrowIf(inCondition, inException, inMessage) \
401 Throw(inException); \
404 #define ThrowIfNULL(inPointer, inException, inMessage) \
405 if((inPointer) == NULL) \
407 Throw(inException); \
410 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
412 unsigned int __Err = (inKernelError); \
415 Throw(inException); \
419 #define ThrowIfError(inError, inException, inMessage) \
421 SInt32 __Err = (inError); \
424 Throw(inException); \
429 #define ThrowIfWinError(inError, inException, inMessage) \
431 HRESULT __Err = (inError); \
434 Throw(inException); \
439 #define SubclassResponsibility(inMethodName, inException) \
441 Throw(inException); \
444 #endif // defined(__cplusplus)
446 #endif // DEBUG || CoreAudio_Debug