bluetooth/btstack/inc/debug.h
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Central place for nice debug-type macros & functions
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef BT_DEBUG_H
       
    19 #define BT_DEBUG_H
       
    20 
       
    21 #ifdef __USING_POLICING_ESOCK__
       
    22 #undef __USING_POLICING_ESOCK__
       
    23 #endif
       
    24 //#define __USING_POLICING_ESOCK__
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <f32file.h>
       
    28 #include <comms-infras/commsdebugutility.h>
       
    29 
       
    30 #ifdef __FLOG_ACTIVE	// = commsdbg logging on
       
    31 //#define BLOGGING__    //removed for MCL submission
       
    32 #define __FLOGGING__
       
    33 #endif // __FLOG_ACTIVE
       
    34 
       
    35 // Borrowed from comms-framework - experimental ASSERT variants that
       
    36 // breakpt at the scene of the crime.
       
    37 #ifdef _DEBUG
       
    38 #if defined (__WINS__)
       
    39 #undef __ASSERT_DEBUG
       
    40 inline void About_To_Panic_Thread() { __DEBUGGER() }
       
    41 #define __ASSERT_DEBUG(c,p) (void)((c)||(About_To_Panic_Thread(),p,0))
       
    42 #undef __ASSERT_ALWAYS
       
    43 #define __ASSERT_ALWAYS(c,p) (void)((c)||(About_To_Panic_Thread(),p,0))
       
    44 #endif
       
    45 #endif
       
    46 
       
    47 
       
    48 class CBlogger;
       
    49 class CDeltaTimer;
       
    50 class CDebugControlInterface;
       
    51 class CAvdtpLogEngine;
       
    52 class CAvctpLogEngine;
       
    53 
       
    54 struct SBtTls
       
    55 	{
       
    56 public:
       
    57 	CDeltaTimer*			iTimer;	// always needed: not owned
       
    58 	TUint					iPort;	// the serial port we are on - for logging only
       
    59 	CBlogger*				iBlogger;	// for logging only	
       
    60 	CDebugControlInterface* iDebugCtrlIF;
       
    61 	CAvdtpLogEngine*		iAvdtpLogEngine;
       
    62 	CAvctpLogEngine*		iAvctpLogEngine;	
       
    63 	};
       
    64 
       
    65 #define BTTLS static_cast<SBtTls*>(Dll::Tls())
       
    66 
       
    67 #ifdef __USING_POLICING_ESOCK__
       
    68 #else
       
    69 enum TCapabilityRequestType 
       
    70  	{
       
    71 	//Socket Capability
       
    72  	ESetOptCheck,
       
    73  	EGetOptCheck,
       
    74  	EIoctlCheck,
       
    75  	EBindCheck,
       
    76 	EListenCheck,
       
    77  	EConnectionCheck,
       
    78 	EWriteCheck,
       
    79  	EReceiveCheck,
       
    80 	EGetLocalNameCheck,
       
    81 	EGetRemoteNameCheck,
       
    82 
       
    83 	//HostResolver
       
    84 	EHRGetByNameCheck,
       
    85 	EHRGetByAddressCheck,
       
    86 	EHRSetHostNameCheck,
       
    87 	EHRGetHostNameCheck,
       
    88 
       
    89 	// NetDataBase
       
    90 	ENDQueryCheck,
       
    91 	ENDAddCheck,
       
    92 	ENDRemoveCheck,
       
    93 
       
    94 	// ServiceResolver
       
    95 	ESRGetByNameCheck,
       
    96 	ESRGetByNumberCheck,
       
    97 	ESRRegisterServiceCheck,
       
    98 	ESRRemoveServiceCheck,
       
    99 
       
   100 	//Cconnection
       
   101  	EReadCommdbCheck,
       
   102 	EControlCheck
       
   103  	};
       
   104 
       
   105 #endif
       
   106 
       
   107 
       
   108 static const TInt KL2CAPDebugOptionMask = 0xFFFF; //< SetOpt for debugging modes in L2CAP
       
   109 static const TUint KL2CAPDebugSendRequestsTwice = 1; //< Send L2CAP requests twice
       
   110 static const TUint KL2CAPDebugInvalidL2CAPLengthInConnect= 3; //< Set the L2CAP length wrong
       
   111 static const TUint KL2CAPDebugInvalidL2CAPLengthInData=4;//< Set the L2CAP length wrong
       
   112 
       
   113 #ifndef LOGGER_H
       
   114 
       
   115 _LIT(KLogFile,"btlog0.txt");
       
   116 const TInt KLogIndexOffset=5;
       
   117 _LIT(KLogDirFullName,"c:\\logs\\bt\\");
       
   118 _LIT(KLogDir,"BT");
       
   119 
       
   120 //#define COMMENT SLASH(/)
       
   121 #define COMMENT
       
   122 //#define SLASH(s) /##s
       
   123 #ifndef BLOGGING__
       
   124 // define empty blogging macro stubs
       
   125 #define BLOGGER                    COMMENT
       
   126 #define BLOG(layer,verbosity,type,blog_call,cbloggette_type) COMMENT
       
   127 //------- Blogging for BT Qual ------------
       
   128 #define LLQBLOG(type,blog_call)     COMMENT
       
   129 #define L2QBLOG(type,blog_call)     COMMENT
       
   130 #define RFQBLOG(type,blog_call)     COMMENT
       
   131 //------- Loud Blogging Calls -------------
       
   132 #define LLLBLOG(type,blog_call)     COMMENT
       
   133 #define L2LBLOG(type,blog_call)     COMMENT
       
   134 #define RFLBLOG(type,blog_call)     COMMENT
       
   135 //------- Generic Blogging calls ----------
       
   136 #define LLBLOG(verbosity,type,blog_call)      COMMENT
       
   137 #define L2BLOG(verbosity,type,blog_call)      COMMENT
       
   138 #define RFBLOG(verbosity,type,blog_call)      COMMENT
       
   139 #else   // define blogging calls
       
   140 #define BLOGGER BTTLS->iBlogger
       
   141 #define BLOG(layer,verbosity,type,blog_call,cbloggette_type) \
       
   142 	{ \
       
   143 	CBlogger* pBlog = BLOGGER;  \
       
   144 	CBloggette* pBloggette;\
       
   145 	if((pBlog->LoggingMask(layer,verbosity))&(type))  \
       
   146 		{  \
       
   147 		pBloggette=(pBlog->GetLayerBloggette(layer)); \
       
   148 		(STATIC_CAST(cbloggette_type*,pBloggette))->blog_call;  \
       
   149 		}  \
       
   150 	}
       
   151 // the blog_call should look like Log(KMyFormatingLit,var1,var2,varbla);
       
   152 // or L2BLOG(KVerbose,Log(KL2ConnLit, connH, addr));
       
   153 // or L2BLOG(KVerbose,ConnLog(connH,addr));
       
   154 //------- Blogging for BT Qual ------------
       
   155 #define LLQBLOG(type,blog_call) BLOG(KBlogLayerLinkLayer,KBlogVerbosityBTQualLevel,type,blog_call, CLLBloggette)
       
   156 #define L2QBLOG(type,blog_call) BLOG(KBlogLayerL2CAP,KBlogVerbosityBTQualLevel,type,blog_call, CL2Bloggette)
       
   157 #define RFQBLOG(type,blog_call) BLOG(KBlogLayerRFComm,KBlogVerbosityBTQualLevel,type,blog_call, CRFBloggette)
       
   158 //------- Loud Blogging Calls -------------
       
   159 #define LLLBLOG(type,blog_call) BLOG(KBlogLayerLinkLayer,KBlogVerbosityLoud,type,blog_call,CLLBloggette)
       
   160 #define L2LBLOG(type,blog_call) BLOG(KBlogLayerL2CAP,KBlogVerbosityLoud,type,blog_call, CL2Bloggette)
       
   161 #define RFLBLOG(type,blog_call) BLOG(KBlogLayerRFComm,KBlogVerbosityLoud,type,blog_call, CRFBloggette)
       
   162 //------- Generic Blogging calls ----------
       
   163 #define LLBLOG(verbosity,type,blog_call) BLOG(KBlogLayerLinkLayer,verbosity,type,blog_call,CLLBloggette)
       
   164 #define L2BLOG(verbosity,type,blog_call) BLOG(KBlogLayerL2CAP,verbosity,type,blog_call,CL2Bloggette)
       
   165 #define RFBLOG(verbosity,type,blog_call) BLOG(KBlogLayerRFComm,verbosity,type,blog_call,CRFBloggette)
       
   166 #endif
       
   167   
       
   168 inline void __BTDEBUGGER()
       
   169 // needed to call __DEBUGGER inside an __ASSERT
       
   170 	{
       
   171 	__DEBUGGER()
       
   172 	}
       
   173 
       
   174 #ifdef __FLOGGING__
       
   175 #define FLOG(a) {FPrint(a);}
       
   176 #define FTRACE(a) {a;}
       
   177 
       
   178 inline void FPrint(const TRefByValue<const TDesC> aFmt, ...)
       
   179 	{
       
   180 	VA_LIST list;
       
   181 	VA_START(list,aFmt);
       
   182 	TBuf<32> logFile(KLogFile);
       
   183 #ifdef BLOGGING__
       
   184 	// the Blogger holds the flogging file index since it is pointed by the TLS
       
   185 	CBlogger* pBlog = BLOGGER;
       
   186 	logFile[KLogIndexOffset]=TText('0'+(TInt)pBlog->GetFloggerInfo());	
       
   187 #else
       
   188 	logFile[KLogIndexOffset]=TText('0'+BTTLS->iPort);
       
   189 #endif
       
   190 	RFileLogger::WriteFormat(KLogDir, logFile, EFileLoggingModeAppend, aFmt, list);
       
   191 #ifdef MEMTRACE
       
   192 	TInt size;
       
   193 	User::Heap().AllocSize(size);
       
   194 	
       
   195 	RFileLogger::WriteFormat(KLogDir, logFile, EFileLoggingModeAppend, _L("Mem usage: %d high: %d"), size, User::Heap().Size());
       
   196 #endif
       
   197 	}
       
   198 
       
   199 inline void FHex(const TUint8* aPtr, TInt aLen)
       
   200 	{
       
   201 	TBuf<32> logFile(KLogFile);
       
   202 	logFile[KLogIndexOffset]=TText('0'+BTTLS->iPort);
       
   203 	RFileLogger::HexDump(KLogDir, logFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen);
       
   204 	}
       
   205 
       
   206 inline void FHex(const TDesC8& aDes)
       
   207 	{
       
   208 	FHex(aDes.Ptr(), aDes.Length());
       
   209 	}
       
   210 
       
   211 
       
   212 #define SCO_LOG(a) FPrint(a);
       
   213 #define SCO_LOG_2(a, b) FPrint(a, b);
       
   214 #define SCO_LOG_3(a, b, c) FPrint(a, b, c);
       
   215 #define SCO_LOG_4(a, b, c, d) FPrint(a, b, c, d);
       
   216 #define SCO_LOG_5(a, b, c, d, e) FPrint(a, b, c, d, e);
       
   217 #define SCO_LOG_6(a, b, c, d, e, f) FPrint(a, b, c, d, e, f);
       
   218 #define SCO_LOG_ADDR(string, addr) { TBuf<20> addrbuf; addrbuf.Format(_L("%02x:%02x:%02x:%02x:%02x:%02x"), addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); SCO_LOG_2(string, &addrbuf); }
       
   219 
       
   220 #else // i.e. __FLOGGING__ undefined
       
   221 #define FLOG(a)
       
   222 #define FTRACE(a)
       
   223 
       
   224 #define SCO_LOG(a)
       
   225 #define SCO_LOG_2(a, b)
       
   226 #define SCO_LOG_3(a, b, c)
       
   227 #define SCO_LOG_4(a, b, c, d)
       
   228 #define SCO_LOG_5(a, b, c, d, e)
       
   229 #define SCO_LOG_6(a, b, c, d, e, f)
       
   230 #define SCO_LOG_ADDR(string, addr)
       
   231 
       
   232 
       
   233 inline void FPrint(const TRefByValue<const TDesC> /*aFmt*/,...) 
       
   234 	{
       
   235 #ifdef _DEBUG // to quell linker warnings
       
   236 	RFileLogger dummy;
       
   237 #endif
       
   238 	}
       
   239 
       
   240 inline void FHex(const TUint8* /*aPtr*/, TInt /*aLen*/)
       
   241 	{
       
   242 	}
       
   243 
       
   244 inline void FHex(const TDesC8& /*aDes*/)
       
   245 	{
       
   246 	}
       
   247 
       
   248 #endif //	__FLOGGING__
       
   249 
       
   250 #endif // #ifndef LOGGER_H
       
   251 
       
   252 #define __PANIC_UNEXPECTED_CALL __ASSERT_DEBUG(NULL, User::Invariant());
       
   253 
       
   254 #endif // __BT_DEBUG_H__