Jamoma API  0.6.0.a19
CADebugMacros.h
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
2 
3  Disclaimer: IMPORTANT: This Apple software is supplied to you by
4  Apple Inc. ("Apple") in consideration of your agreement to the
5  following terms, and your use, installation, modification or
6  redistribution of this Apple software constitutes acceptance of these
7  terms. If you do not agree with these terms, please do not use,
8  install, modify or redistribute this Apple software.
9 
10  In consideration of your agreement to abide by the following terms, and
11  subject to these terms, Apple grants you a personal, non-exclusive
12  license, under Apple's copyrights in this original Apple software (the
13  "Apple Software"), to use, reproduce, modify and redistribute the Apple
14  Software, with or without modifications, in source and/or binary forms;
15  provided that if you redistribute the Apple Software in its entirety and
16  without modifications, you must retain this notice and the following
17  text and disclaimers in all such redistributions of the Apple Software.
18  Neither the name, trademarks, service marks or logos of Apple Inc.
19  may be used to endorse or promote products derived from the Apple
20  Software without specific prior written permission from Apple. Except
21  as expressly stated in this notice, no other rights or licenses, express
22  or implied, are granted by Apple herein, including but not limited to
23  any patent rights that may be infringed by your derivative works or by
24  other works in which the Apple Software may be incorporated.
25 
26  The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31 
32  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 #if !defined(__CADebugMacros_h__)
42 #define __CADebugMacros_h__
43 
44 //=============================================================================
45 // Includes
46 //=============================================================================
47 
48 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
49  #include <CoreAudio/CoreAudioTypes.h>
50 #else
51  #include "CoreAudioTypes.h"
52 #endif
53 
54 //=============================================================================
55 // CADebugMacros
56 //=============================================================================
57 
58 //#define CoreAudio_StopOnFailure 1
59 //#define CoreAudio_TimeStampMessages 1
60 //#define CoreAudio_ThreadStampMessages 1
61 //#define CoreAudio_FlushDebugMessages 1
62 
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; }
66 #else
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; }
69 #endif
70 
71 // This is a macro that does a sizeof and casts the result to a UInt32. This is useful for all the
72 // places where -wshorten64-32 catches assigning a sizeof expression to a UInt32.
73 // For want of a better place to park this, we'll park it here.
74 #define SizeOf32(X) ((UInt32)sizeof(X))
75 
76 // This is a macro that does a offsetof and casts the result to a UInt32. This is useful for all the
77 // places where -wshorten64-32 catches assigning an offsetof expression to a UInt32.
78 // For want of a better place to park this, we'll park it here.
79 #define OffsetOf32(X, Y) ((UInt32)offsetof(X, Y))
80 
81 // This macro casts the expression to a UInt32. It is called out specially to allow us to track casts
82 // that have been added purely to avert -wshorten64-32 warnings on 64 bit platforms.
83 // For want of a better place to park this, we'll park it here.
84 #define ToUInt32(X) ((UInt32)(X))
85 
86 #pragma mark Basic Definitions
87 
88 #if DEBUG || CoreAudio_Debug
89 
90  // can be used to break into debugger immediately, also see CADebugger
91  #define BusError() (*(long *)0 = 0)
92 
93  // basic debugging print routines
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)
100  #else
101  #include "CADebugPrintf.h"
102 
103  #if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
104  #define FlushRtn ,fflush(DebugPrintfFile)
105  #else
106  #define FlushRtn
107  #endif
108 
109  #if CoreAudio_ThreadStampMessages
110  #include <pthread.h>
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
134  #else
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
145  #endif
146  #endif
147  void DebugPrint(const char *fmt, ...); // can be used like printf
148  #ifndef DEBUGPRINT
149  #define DEBUGPRINT(msg) DebugPrint msg // have to double-parenthesize arglist (see Debugging.h)
150  #endif
151  #if VERBOSE
152  #define vprint(msg) DEBUGPRINT(msg)
153  #else
154  #define vprint(msg)
155  #endif
156 
157  #if CoreAudio_StopOnFailure
158  #include "CADebugger.h"
159  #define STOP CADebuggerStop()
160  #else
161  #define STOP
162  #endif
163 
164 #else
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)
175  #ifndef DEBUGPRINT
176  #define DEBUGPRINT(msg)
177  #endif
178  #define vprint(msg)
179  #define STOP
180 #endif
181 
182 void LogError(const char *fmt, ...); // writes to syslog (and stderr if debugging)
183 void LogWarning(const char *fmt, ...); // writes to syslog (and stderr if debugging)
184 
185 #if DEBUG || CoreAudio_Debug
186 
187 #pragma mark Debug Macros
188 
189 #define Assert(inCondition, inMessage) \
190  if(!(inCondition)) \
191  { \
192  DebugMessage(inMessage); \
193  STOP; \
194  }
195 
196 #define AssertNoError(inError, inMessage) \
197  { \
198  SInt32 __Err = (inError); \
199  if(__Err != 0) \
200  { \
201  char __4CC[5] = CA4CCToCString(__Err); \
202  DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
203  STOP; \
204  } \
205  }
206 
207 #define AssertNoKernelError(inError, inMessage) \
208  { \
209  unsigned int __Err = (unsigned int)(inError); \
210  if(__Err != 0) \
211  { \
212  DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
213  STOP; \
214  } \
215  }
216 
217 #define FailIf(inCondition, inHandler, inMessage) \
218  if(inCondition) \
219  { \
220  DebugMessage(inMessage); \
221  STOP; \
222  goto inHandler; \
223  }
224 
225 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
226  if(inCondition) \
227  { \
228  DebugMessage(inMessage); \
229  STOP; \
230  { inAction; } \
231  goto inHandler; \
232  }
233 
234 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
235  if((inPointer) == NULL) \
236  { \
237  DebugMessage(inMessage); \
238  STOP; \
239  { inAction; } \
240  goto inHandler; \
241  }
242 
243 #define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
244  { \
245  unsigned int __Err = (inKernelError); \
246  if(__Err != 0) \
247  { \
248  DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
249  STOP; \
250  { inAction; } \
251  goto inHandler; \
252  } \
253  }
254 
255 #define FailIfError(inError, inAction, inHandler, inMessage) \
256  { \
257  SInt32 __Err = (inError); \
258  if(__Err != 0) \
259  { \
260  char __4CC[5] = CA4CCToCString(__Err); \
261  DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
262  STOP; \
263  { inAction; } \
264  goto inHandler; \
265  } \
266  }
267 
268 #if defined(__cplusplus)
269 
270 #define Throw(inException) STOP; throw (inException)
271 
272 #define ThrowIf(inCondition, inException, inMessage) \
273  if(inCondition) \
274  { \
275  DebugMessage(inMessage); \
276  Throw(inException); \
277  }
278 
279 #define ThrowIfNULL(inPointer, inException, inMessage) \
280  if((inPointer) == NULL) \
281  { \
282  DebugMessage(inMessage); \
283  Throw(inException); \
284  }
285 
286 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
287  { \
288  unsigned int __Err = (inKernelError); \
289  if(__Err != 0) \
290  { \
291  DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
292  Throw(inException); \
293  } \
294  }
295 
296 #define ThrowIfError(inError, inException, inMessage) \
297  { \
298  SInt32 __Err = (inError); \
299  if(__Err != 0) \
300  { \
301  char __4CC[5] = CA4CCToCString(__Err); \
302  DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
303  Throw(inException); \
304  } \
305  }
306 
307 #if TARGET_OS_WIN32
308 #define ThrowIfWinError(inError, inException, inMessage) \
309  { \
310  HRESULT __Err = (inError); \
311  if(FAILED(__Err)) \
312  { \
313  DebugMessageN2(inMessage ", Code: %d, Facility: 0x%X", HRESULT_CODE(__Err), HRESULT_FACILITY(__Err)); \
314  Throw(inException); \
315  } \
316  }
317 #endif
318 
319 #define SubclassResponsibility(inMethodName, inException) \
320  { \
321  DebugMessage(inMethodName": Subclasses must implement this method"); \
322  Throw(inException); \
323  }
324 
325 #endif // defined(__cplusplus)
326 
327 #else
328 
329 #pragma mark Release Macros
330 
331 #define Assert(inCondition, inMessage) \
332  if(!(inCondition)) \
333  { \
334  STOP; \
335  }
336 
337 #define AssertNoError(inError, inMessage) \
338  { \
339  SInt32 __Err = (inError); \
340  if(__Err != 0) \
341  { \
342  STOP; \
343  } \
344  }
345 
346 #define AssertNoKernelError(inError, inMessage) \
347  { \
348  unsigned int __Err = (unsigned int)(inError); \
349  if(__Err != 0) \
350  { \
351  STOP; \
352  } \
353  }
354 
355 #define FailIf(inCondition, inHandler, inMessage) \
356  if(inCondition) \
357  { \
358  STOP; \
359  goto inHandler; \
360  }
361 
362 #define FailWithAction(inCondition, inAction, inHandler, inMessage) \
363  if(inCondition) \
364  { \
365  STOP; \
366  { inAction; } \
367  goto inHandler; \
368  }
369 
370 #define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
371  if((inPointer) == NULL) \
372  { \
373  STOP; \
374  { inAction; } \
375  goto inHandler; \
376  }
377 
378 #define FailIfKernelError(inKernelError, inAction, inHandler, inMessage) \
379  if((inKernelError) != 0) \
380  { \
381  STOP; \
382  { inAction; } \
383  goto inHandler; \
384  }
385 
386 #define FailIfError(inError, inAction, inHandler, inMessage) \
387  if((inError) != 0) \
388  { \
389  STOP; \
390  { inAction; } \
391  goto inHandler; \
392  }
393 
394 #if defined(__cplusplus)
395 
396 #define Throw(inException) STOP; throw (inException)
397 
398 #define ThrowIf(inCondition, inException, inMessage) \
399  if(inCondition) \
400  { \
401  Throw(inException); \
402  }
403 
404 #define ThrowIfNULL(inPointer, inException, inMessage) \
405  if((inPointer) == NULL) \
406  { \
407  Throw(inException); \
408  }
409 
410 #define ThrowIfKernelError(inKernelError, inException, inMessage) \
411  { \
412  unsigned int __Err = (inKernelError); \
413  if(__Err != 0) \
414  { \
415  Throw(inException); \
416  } \
417  }
418 
419 #define ThrowIfError(inError, inException, inMessage) \
420  { \
421  SInt32 __Err = (inError); \
422  if(__Err != 0) \
423  { \
424  Throw(inException); \
425  } \
426  }
427 
428 #if TARGET_OS_WIN32
429 #define ThrowIfWinError(inError, inException, inMessage) \
430  { \
431  HRESULT __Err = (inError); \
432  if(FAILED(__Err)) \
433  { \
434  Throw(inException); \
435  } \
436  }
437 #endif
438 
439 #define SubclassResponsibility(inMethodName, inException) \
440  { \
441  Throw(inException); \
442  }
443 
444 #endif // defined(__cplusplus)
445 
446 #endif // DEBUG || CoreAudio_Debug
447 
448 #endif