1
2//
3// IrDADebugging.h
4//       A place control logging and asserts
5//
6// Todo: figure out pb's build styles
7//
8#ifndef __IrDADebugging__
9#define __IrDADebugging__
10
11#include <kern/macro_help.h>
12
13//#define hasTracing        1       // control irdalogs and irdalog.c
14//#define hasDebugging  1       // off for no asserts
15
16// todo: add a call to panic or use the kernel's assert macro instead?
17#if (hasDebugging > 0)
18//#define DebugLog(msg)             IOLog("IrDA: %s, %s, line %d, %s\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ , msg)
19//#define DebugLog(fmt, args...)     IOLog("IrDA: %s, %s, line %d, " fmt "\n", __FILE__, __PRETTY_FUNCTION__, __LINE__ , ## args)
20#define DebugLog(fmt, args...)     IOLog("IrDA: %s, %s, line %d: " fmt "\n", __FILE__, __FUNCTION__, __LINE__ , ## args)
21#define LOGIT(expr)                         \
22    IOLog("IrDA: Assertion \"%s\" failed!  File %s, function %s, line %d\n",    \
23	#expr, __FILE__, __FUNCTION__, __LINE__)
24#else
25#define LOGIT(expr) ((void)0)
26#define DebugLog(x...) ((void)0)
27#endif
28
29// per source module irdalog settings
30#define hasAppleSCCIrDATracing      1   // AppleSCCIrDA.cpp
31#define hasAppleUSBIrDATracing      1   // AppleUSBIrDA.cpp (not impl)
32#define hasIrDACommTracing      1   // IrDAComm.cpp
33#define hasCBufferSegTracing    1   // CBufferSegment.cpp
34#define hasIrEventTracing       1   // IrEvent.cpp
35#define hasIrGlueTracing        1   // IrGlue.cpp
36#define hasCTimerTracing        1   // CTimer.cpp
37
38#define hasIrStreamTracing      1   // IrStream.cpp
39#define hasIrDiscoveryTracing   1   // IrDiscovery.cpp
40#define hasLAPConnTracing       1   // IrLAPConn.cpp
41#define hasLAPTracing           1   // IrLAP.cpp
42#define hasLMPTracing           1   // IrLMP.cpp
43#define hasLAPConnTracing       1   // IrLAPConn.cpp
44#define hasLSAPConnTracing      1   // IrLSAPConn.cpp
45#define hasCIrDeviceTracing     2   // CIrDevice.cpp (full packet dump if > 1)
46#define hasIrQOSTracing         1   // IrQOS.cpp
47#define hasIASServiceTracing    1   // IrIASService.cpp
48#define hasIASServerTracing     1   // IrIASServer.cpp
49#define hasCListTracing         1   // CList.cpp
50//#define hasCDynamicArrayTracing   1   // CDynamicArray.cpp
51#define hasIASClientTracing     1   // IrIASClient.cpp
52#define hasIrLSAPTracing        1   // CIrLSAP.cpp
53
54#define hasTTPTracing           1   // ttp.cpp
55#define hasTTP2Tracing          1   // ttp2.cpp
56#define hasTTP3Tracing          1   // ttp3.cpp
57#define hasTTPLMPTracing        1   // ttplmp.cpp
58#define hasTTPPduTracing        1   // ttppdu.cpp
59#define hasIrCommTracing        1   // ircomm.cpp
60
61// consider moving this and/or making a real control for it, used by qos.cpp
62// the bits are:
63// 001  2400 baud           010 57.6        100 4mbit
64// 002  9600                020 115k
65// 004  19.2                040 .5 mbit
66// 008  38.4                080 1mbit
67//#define THROTTLE_SPEED    0x002e          // define to throttle
68
69#ifdef assert
70#undef assert           // nuke IOKit/kernel's assert
71#endif
72
73#define assert(expr)                    \
74    MACRO_BEGIN                         \
75	if (expr) { }                   \
76	else {                          \
77	    LOGIT(expr);                \
78	}                               \
79    MACRO_END
80
81#define require(expr, failed)           \
82    MACRO_BEGIN                         \
83	if (expr) { }                   \
84	else {                          \
85	    LOGIT(expr);                \
86	    goto failed;                \
87	}                               \
88    MACRO_END
89
90#define nrequire(expr, failed)          \
91    MACRO_BEGIN                         \
92	if (!(expr)) { }                \
93	else {                          \
94	    LOGIT(expr);                \
95	    goto failed;                \
96	}                               \
97    MACRO_END
98
99// Support old flavors of assert macros
100
101#define check(expr)                             assert(expr)
102#define ncheck(expr)                            assert(!(expr))
103#define XASSERT(expr)                           check(expr)
104#define XASSERTNOT(expr)                        ncheck(expr)
105#define XREQUIRE(expr, label)                   require(expr, label)
106#define XREQUIRENOT(expr, label)                nrequire(expr,label)
107
108#endif          //  __IrDADebugging__
109