root/trunk/PublicUtility/CADebugMacros.h

Revision 1, 13.5 kB (checked in by gbooker, 3 years ago)

Initial Import

Line 
1 /*      Copyright:      © Copyright 2004 Apple Computer, Inc. All rights reserved.
2
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.
8
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.
23
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.
29
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.
37 */
38 /*=============================================================================
39         CADebugMacros.h
40
41 =============================================================================*/
42 #if !defined(__CADebugMacros_h__)
43 #define __CADebugMacros_h__
44
45 //=============================================================================
46 //      CADebugMacros
47 //=============================================================================
48
49 //#define       CoreAudio_StopOnFailure                 1
50 //#define       CoreAudio_TimeStampMessages             1
51 //#define       CoreAudio_ThreadStampMessages   1
52 //#define       CoreAudio_FlushDebugMessages    1
53
54 #define CA4CCToCString(the4CC)  { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
55
56 #if     DEBUG || CoreAudio_Debug
57        
58         // can be used to break into debugger immediately, also see CADebugger
59         #define BusError()              (*(long *)0 = 0)
60        
61         //      basic debugging print routines
62         #if     TARGET_OS_MAC && !TARGET_API_MAC_CARBON
63                 extern pascal void DebugStr(const unsigned char* debuggerMsg);
64                 #define DebugMessage(msg)       DebugStr("\p"msg)
65                 #define DebugMessageN1(msg, N1)
66                 #define DebugMessageN2(msg, N1, N2)
67                 #define DebugMessageN3(msg, N1, N2, N3)
68         #else
69                 #include "CADebugPrintf.h"
70                
71                 #if     CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog
72                         #define FlushRtn        ;fflush(DebugPrintfFile)
73                 #else
74                         #define FlushRtn
75                 #endif
76                
77                 #if             CoreAudio_ThreadStampMessages
78                         #include <pthread.h>
79                         #include "CAHostTimeBase.h"
80                         #define DebugMessage(msg)                                                                               DebugPrintfRtn(DebugPrintfFile, "%p %.4f: %s\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
81                         #define DebugMessageN1(msg, N1)                                                                 DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
82                         #define DebugMessageN2(msg, N1, N2)                                                             DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
83                         #define DebugMessageN3(msg, N1, N2, N3)                                                 DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
84                         #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
85                         #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
86                         #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
87                         #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
88                         #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
89                         #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
90                 #elif   CoreAudio_TimeStampMessages
91                         #include "CAHostTimeBase.h"
92                         #define DebugMessage(msg)                                                                               DebugPrintfRtn(DebugPrintfFile, "%.4f: %s\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
93                         #define DebugMessageN1(msg, N1)                                                                 DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
94                         #define DebugMessageN2(msg, N1, N2)                                                             DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
95                         #define DebugMessageN3(msg, N1, N2, N3)                                                 DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
96                         #define DebugMessageN4(msg, N1, N2, N3, N4)                                             DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
97                         #define DebugMessageN5(msg, N1, N2, N3, N4, N5)                                 DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
98                         #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)                             DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
99                         #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)                 DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
100                         #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)             DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
101                         #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg"\n", ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
102                 #else
103                         #define DebugMessage(msg)                                                                               DebugPrintfRtn(DebugPrintfFile, "%s\n", msg) FlushRtn
104                         #define DebugMessageN1(msg, N1)                                                                 DebugPrintfRtn(DebugPrintfFile, msg"\n", N1) FlushRtn
105                         #define DebugMessageN2(msg, N1, N2)                                                             DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2) FlushRtn
106                         #define DebugMessageN3(msg, N1, N2, N3)                                                 DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3) FlushRtn
107                         #define DebugMessageN4(msg, N1, N2, N3, N4)                                             DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4) FlushRtn
108                         #define DebugMessageN5(msg, N1, N2, N3, N4, N5)                                 DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4, N5) FlushRtn
109                         #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)                             DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4, N5, N6) FlushRtn
110                         #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)                 DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4, N5, N6, N7) FlushRtn
111                         #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)             DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
112                         #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, msg"\n", N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
113                 #endif
114         #endif
115         void    DebugPrint(const char *fmt, ...);       // can be used like printf
116         #define DEBUGPRINT(msg) DebugPrint msg          // have to double-parenthesize arglist (see Debugging.h)
117         #if VERBOSE
118                 #define vprint(msg) DEBUGPRINT(msg)
119         #else
120                 #define vprint(msg)
121         #endif
122        
123         #if     CoreAudio_StopOnFailure
124                 #include "CADebugger.h"
125                 #define STOP    CADebuggerStop()
126         #else
127                 #define STOP
128         #endif
129
130 #else
131         #define DebugMessage(msg)
132         #define DebugMessageN1(msg, N1)
133         #define DebugMessageN2(msg, N1, N2)
134         #define DebugMessageN3(msg, N1, N2, N3)
135         #define DebugMessageN4(msg, N1, N2, N3, N4)
136         #define DebugMessageN5(msg, N1, N2, N3, N4, N5)
137         #define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)
138         #define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)
139         #define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)
140         #define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9)
141         #define DEBUGPRINT(msg)
142         #define vprint(msg)
143         #define STOP
144 #endif
145
146 void    LogError(const char *fmt, ...);                 // writes to syslog (and stderr if debugging)
147
148 #define Assert(inCondition, inMessage)                                                                                                  \
149                         if(!(inCondition))                                                                                                                      \
150                         {                                                                                                                                                       \
151                                 DebugMessage(inMessage);                                                                                                \
152                                 STOP;                                                                                                                                   \
153                         }
154
155 #define AssertNoError(inError, inMessage)                                                                                               \
156                         {                                                                                                                                                       \
157                                 SInt32 __E__err = (inError);                                                                                    \
158                                 if(__E__err != 0)                                                                                                               \
159                                 {                                                                                                                                               \
160                                         char __4CC_string[5];                                                                                           \
161                                         *((SInt32*)__4CC_string) = __E__err;                                                            \
162                                         __4CC_string[4] = 0;                                                                                            \
163                                         DebugMessageN2(inMessage ", Error: %ld (%s)", __E__err, __4CC_string);          \
164                                         STOP;                                                                                                                           \
165                                 }                                                                                                                                               \
166                         }
167
168 #define AssertNoKernelError(inError, inMessage)                                                                                 \
169                         {                                                                                                                                                       \
170                                 unsigned int __E__err = (unsigned int)(inError);                                                \
171                                 if(__E__err != 0)                                                                                                               \
172                                 {                                                                                                                                               \
173                                         DebugMessageN1(inMessage ", Error: 0x%X", __E__err);                            \
174                                         STOP;                                                                                                                           \
175                                 }                                                                                                                                               \
176                         }
177
178 #define FailIf(inCondition, inHandler, inMessage)                                                                               \
179                         if(inCondition)                                                                                                                         \
180                         {                                                                                                                                                       \
181                                 DebugMessage(inMessage);                                                                                                \
182                                 STOP;                                                                                                                                   \
183                                 goto inHandler;                                                                                                                 \
184                         }
185
186 #define FailWithAction(inCondition, inAction, inHandler, inMessage)                                             \
187                         if(inCondition)                                                                                                                         \
188                         {                                                                                                                                                       \
189                                 DebugMessage(inMessage);                                                                                                \
190                                 STOP;                                                                                                                                   \
191                                 { inAction; }                                                                                                                   \
192                                 goto inHandler;                                                                                                                 \
193                         }
194
195 #if defined(__cplusplus)
196
197 #define ThrowIf(inCondition, inException, inMessage)                                                                    \
198                         if(inCondition)                                                                                                                         \
199                         {                                                                                                                                                       \
200                                 DebugMessage(inMessage);                                                                                                \
201                                 STOP;                                                                                                                                   \
202                                 throw (inException);                                                                                                    \
203                         }
204
205 #define ThrowIfNULL(inPointer, inException, inMessage)                                                                  \
206                         if((inPointer) == NULL)                                                                                                         \
207                         {                                                                                                                                                       \
208                                 DebugMessage(inMessage);                                                                                                \
209                                 STOP;                                                                                                                                   \
210                                 throw (inException);                                                                                                    \
211                         }
212
213 #define ThrowIfKernelError(inKernelError, inException, inMessage)                                               \
214                         {                                                                                                                                                       \
215                                 kern_return_t __E__err = (inKernelError);                                                               \
216                                 if(__E__err != 0)                                                                                                               \
217                                 {                                                                                                                                               \
218                                         DebugMessageN1(inMessage ", Error: 0x%X", __E__err);                            \
219                                         STOP;                                                                                                                           \
220                                         throw (inException);                                                                                            \
221                                 }                                                                                                                                               \
222                         }
223
224 #define ThrowIfError(inError, inException, inMessage)                                                                   \
225                         {                                                                                                                                                       \
226                                 SInt32 __E__err = (inError);                                                                                    \
227                                 if(__E__err != 0)                                                                                                               \
228                                 {                                                                                                                                               \
229                                         char __4CC_string[5];                                                                                           \
230                                         *((SInt32*)__4CC_string) = __E__err;                                                            \
231                                         __4CC_string[4] = 0;                                                                                            \
232                                         DebugMessageN2(inMessage ", Error: %ld (%s)", __E__err, __4CC_string);          \
233                                         STOP;                                                                                                                           \
234                                         throw (inException);                                                                                            \
235                                 }                                                                                                                                               \
236                         }
237
238 #define ThrowError(inError, inException, inMessage)                                                                             \
239                         {                                                                                                                                                       \
240                                 SInt32 __E__err = (inError);                                                                                    \
241                                 char __4CC_string[5];                                                                                                   \
242                                 *((SInt32*)__4CC_string) = __E__err;                                                                    \
243                                 __4CC_string[4] = 0;                                                                                                    \
244                                 DebugMessageN2(inMessage ", Error: %ld (%s)", __E__err, __4CC_string);  \
245                                 STOP;                                                                                                                                   \
246                                 throw (inException);                                                                                                    \
247                         }
248
249 #define SubclassResponsibility(inMethodName, inException)                                                               \
250                         {                                                                                                                                                       \
251                                 DebugMessage(inMethodName": Subclasses must implement this method");    \
252                                 throw (inException);                                                                                                    \
253                         }
254
255 #endif  //      defined(__cplusplus)
256
257 #endif
Note: See TracBrowser for help on using the browser.