bluetooth/btstack/inc/debug.h
changeset 51 20ac952a623c
parent 0 29b1cd4cb562
equal deleted inserted replaced
48:22de2e391156 51:20ac952a623c
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    25 
    25 
    26 #include <e32std.h>
    26 #include <e32std.h>
    27 #include <f32file.h>
    27 #include <f32file.h>
    28 #include <comms-infras/commsdebugutility.h>
    28 #include <comms-infras/commsdebugutility.h>
    29 
    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
    30 // Borrowed from comms-framework - experimental ASSERT variants that
    36 // breakpt at the scene of the crime.
    31 // breakpt at the scene of the crime.
    37 #ifdef _DEBUG
    32 #ifdef _DEBUG
    38 #if defined (__WINS__)
    33 #if defined (__WINS__)
    39 #undef __ASSERT_DEBUG
    34 #undef __ASSERT_DEBUG
    43 #define __ASSERT_ALWAYS(c,p) (void)((c)||(About_To_Panic_Thread(),p,0))
    38 #define __ASSERT_ALWAYS(c,p) (void)((c)||(About_To_Panic_Thread(),p,0))
    44 #endif
    39 #endif
    45 #endif
    40 #endif
    46 
    41 
    47 
    42 
    48 class CBlogger;
       
    49 class CDeltaTimer;
    43 class CDeltaTimer;
    50 class CDebugControlInterface;
    44 class CDebugControlInterface;
    51 class CAvdtpLogEngine;
    45 class CAvdtpLogEngine;
    52 class CAvctpLogEngine;
    46 class CAvctpLogEngine;
    53 
    47 
    54 struct SBtTls
    48 struct SBtTls
    55 	{
    49 	{
    56 public:
    50 public:
    57 	CDeltaTimer*			iTimer;	// always needed: not owned
    51 	CDeltaTimer*			iTimer;	// always needed: not owned
    58 	TUint					iPort;	// the serial port we are on - for logging only
    52 	TUint					iPort;	// the serial port we are on - for logging only
    59 	CBlogger*				iBlogger;	// for logging only	
       
    60 	CDebugControlInterface* iDebugCtrlIF;
    53 	CDebugControlInterface* iDebugCtrlIF;
    61 	CAvdtpLogEngine*		iAvdtpLogEngine;
    54 	CAvdtpLogEngine*		iAvdtpLogEngine;
    62 	CAvctpLogEngine*		iAvctpLogEngine;	
    55 	CAvctpLogEngine*		iAvctpLogEngine;	
    63 	};
    56 	};
    64 
    57 
   110 static const TUint KL2CAPDebugInvalidL2CAPLengthInConnect= 3; //< Set the L2CAP length wrong
   103 static const TUint KL2CAPDebugInvalidL2CAPLengthInConnect= 3; //< Set the L2CAP length wrong
   111 static const TUint KL2CAPDebugInvalidL2CAPLengthInData=4;//< Set the L2CAP length wrong
   104 static const TUint KL2CAPDebugInvalidL2CAPLengthInData=4;//< Set the L2CAP length wrong
   112 
   105 
   113 #ifndef LOGGER_H
   106 #ifndef LOGGER_H
   114 
   107 
   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()
   108 inline void __BTDEBUGGER()
   169 // needed to call __DEBUGGER inside an __ASSERT
   109 // needed to call __DEBUGGER inside an __ASSERT
   170 	{
   110 	{
   171 	__DEBUGGER()
   111 	__DEBUGGER()
   172 	}
   112 	}
   173 
   113 
   174 #ifdef __FLOGGING__
   114 #endif // LOGGER_H
   175 #define FLOG(a) {FPrint(a);}
       
   176 #define FTRACE(a) {a;}
       
   177 
   115 
   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 
   116 
   252 #define __PANIC_UNEXPECTED_CALL __ASSERT_DEBUG(NULL, User::Invariant());
   117 #define __PANIC_UNEXPECTED_CALL __ASSERT_DEBUG(NULL, User::Invariant());
   253 
   118 
   254 #endif // __BT_DEBUG_H__
   119 #endif // __BT_DEBUG_H__