usbengines/usbotgwatcher/inc/debug.h
branchRCL_3
changeset 65 a44cdf4b4bf0
parent 0 1e05558e2206
child 21 ff9df6630274
child 26 0ae0f29418cd
--- a/usbengines/usbotgwatcher/inc/debug.h	Fri Feb 19 23:50:32 2010 +0200
+++ b/usbengines/usbotgwatcher/inc/debug.h	Fri Mar 12 15:48:40 2010 +0200
@@ -1,118 +1,161 @@
 /*
-* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+* This material, including documentation and any related computer
+* programs, is protected by copyright controlled by Nokia. All
+* rights are reserved. Copying, including reproducing, storing
+* adapting or translating, any or all of this material requires the
+* prior written consent of Nokia. This material also contains
+* confidential information which may not be disclosed to others
+* without the prior written consent of Nokia.
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
-* Description:  Central place for debug-type macros & functions
+* Description: Debug macros and declarations. 
 *
 */
 
+#ifndef DEBUG_H
+#define DEBUG_H
 
-#ifndef _USBWATCHER_DEBUG_H
-#define _USBWATCHER_DEBUG_H
+//////////////////////////////////////////////////////////////////////////////
+// Here are parameters need to be modified. 
+// Component name 
+#define MODULE_NAME "USBOTGWATCHER"
+//////////////////////////////////////////////////////////////////////////////
+
+
+// For handling unicode strings as L##MACRO is interpreted as LMACRO
+#define WIDEN2( x ) L##x
+#define WIDEN( x ) WIDEN2( x )
+
+_LIT( KUsbPanicModule, ""WIDEN( MODULE_NAME ) );
 
 #ifdef _DEBUG
 
-// Enable this to enable memory tracing
-//#define MEMTRACE
-
-// Following define is to enable OOM
-// situations in SRCS
-// SHOULD NEVER BE IN RELEASES.
-//#define TEST_OOM
-
-#ifdef __WINS__
-
-// File logging for WINS
-#define __FLOGGING__
+// Comment this line out if using real-time debugging
+//#define LOG_TO_FILE 
+// ===========================================================================
+#if defined ( LOG_TO_FILE )
+// ===========================================================================
+// Add corresponding libabry in mmp file
+// LIBRARY    flogger.lib    
+// The log file is located at  
+// c:\logs\usb\MODULE_NAME.txt
 
-#else
-
-// Logging with RDebug for target HW
-#define __CLOGGING__
-
-#endif //__WINS__
-
-#endif // Debug
-
-#if defined ( __FLOGGING__ )
-
-_LIT( KLogFile,"UsbWatcher.txt" );
-_LIT( KLogDir,"usb" );
-
-#include <f32file.h>
 #include <flogger.h>
 
-#define FLOG( a ) { FPrint( a ); }
-
-#define FLOGHEX( value, len ) { RFileLogger::HexDump( KLogDir, KLogFile, EFileLoggingModeAppend, "", " ",value, len ); }
-
-#define FTRACE( a ) { a; }
+#define DESC( x ) TPtrC( ( const TText* ) ( x ) )
+#define DESC8( x ) TPtrC8( ( const TUint8* ) ( x ) )
+_LIT( KUsbLogDir, "USB" );
+_LIT( KUsbLogFile, ""WIDEN(MODULE_NAME)L".txt" );
 
-inline void FPrint( const TRefByValue<const TDesC> aFmt, ... )
-{
-    VA_LIST list;
-    VA_START( list, aFmt );
-    RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
+// s: c string. 
+#define LOG(s) RFileLogger::WriteFormat( KUsbLogDir, \
+                KUsbLogFile, EFileLoggingModeAppend, \
+                DESC8( "["MODULE_NAME"] "##s ) )
 
-    // If memory tracing is activated.
-#ifdef MEMTRACE
-    TInt size;
-    User::Heap().AllocSize( size );
-    RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, _L( "[USBWATCHER]\tmemory\tMemory usage: %d high: %d" ), size, User::Heap().Size() );
-#endif
-}
+// s: c string contains "%x"
+// v: varaible corresponding to %x
+#define LOG1(s, v) RFileLogger::WriteFormat( KUsbLogDir, \
+                KUsbLogFile, EFileLoggingModeAppend, \
+                DESC8( "["MODULE_NAME"] "##s ), v)
+// s: c string contains "%x%y"
+// v1: varaible corresponding to %x
+// v2: varaible corresponding to %y
+#define LOG2(s, v1, v2) RFileLogger::WriteFormat( KUsbLogDir, \
+                KUsbLogFile, EFileLoggingModeAppend, \
+                DESC8( "["MODULE_NAME"] "##s ), v1, v2)
 
-inline void FHex( const TUint8* aPtr, TInt aLen )
-{
-    RFileLogger::HexDump( KLogDir, KLogFile, EFileLoggingModeAppend, 0, 0, aPtr, aLen );
-}
+// s: c string contains "%x%y%z"
+// v1: varaible corresponding to %x
+// v2: varaible corresponding to %y
+// v3: varaible corresponding to %z
+#define LOG3(s, v1, v2, v3) RFileLogger::WriteFormat( KUsbLogDir, \
+            KUsbLogFile, EFileLoggingModeAppend, \
+            DESC8( "["MODULE_NAME"] "##s ), v1, v2, v3 )
 
-inline void FHex( const TDesC8& aDes )
-{
-    FHex( aDes.Ptr(), aDes.Length() );
-}
+class TFuncLogger
+    {
+public:
+    TFuncLogger(const TDesC8& aFuncName)
+        {
+        iFuncName.Set( aFuncName );
+        RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, EFileLoggingModeAppend, 
+                DESC8( "["MODULE_NAME"] >>%s" ), iFuncName.Ptr() );
+        }
+    ~TFuncLogger()
+        {
+        RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, 
+                EFileLoggingModeAppend, 
+                DESC8( "["MODULE_NAME"] <<%s" ), iFuncName.Ptr() );
+        }
+private:
+    TPtrC8 iFuncName;
+    };
+// ===========================================================================
+#else //Real-time logging
+// ===========================================================================
+#include <e32debug.h>
 
-// RDebug logging
-#elif defined(__CLOGGING__)
+// Paramters same as above.
+#define LOG( str ) { RDebug::Printf( "["MODULE_NAME"] %s", str  ); }
 
-#include <e32svr.h>
-
-#define FLOG( a ) { RDebug::Print( a ); }
-
-#define FLOGHEX( a )
+#define LOG1( s, v ) { RDebug::Printf( "["MODULE_NAME"] "##s , v ); }
 
-#define FTRACE( a ) { a; }
+#define LOG2( s, v1,v2 ) { RDebug::Printf( "["MODULE_NAME"] "##s , v1, v2 ); }
 
-// Declare the FPrint function
+#define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "["MODULE_NAME"] "##s , \
+        v1, v2, v3); }
 
-inline void FPrint( const TRefByValue<const TDesC> aFmt, ... )
-{
-    VA_LIST list;
-    VA_START( list,aFmt );
-    TInt tmpInt = VA_ARG( list, TInt );
-    TInt tmpInt2 = VA_ARG( list, TInt );
-    TInt tmpInt3 = VA_ARG( list, TInt );
-    VA_END( list );
-    RDebug::Print( aFmt, tmpInt, tmpInt2, tmpInt3 );
-}
+class TFuncLogger
+    {
+public:
+    TFuncLogger(const TPtrC8& aFuncName) : iFuncName( aFuncName )
+        {
+        RDebug::Printf( "["MODULE_NAME"] >>%s", iFuncName.Ptr());
+        }
+    ~TFuncLogger()
+        {
+        RDebug::Printf( "["MODULE_NAME"] <<%s", iFuncName.Ptr());
+        }
+private:
+    TPtrC8 iFuncName;
+    };
+#endif // LOG_TO_FILE
+
+#define LEAVE( exp )  {volatile TInt err = exp; \
+            LOG3( "LEAVE(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\
+            User::Leave( err );}
+
+#define LEAVEIFERROR( exp ) {volatile TInt err = exp; if(err < 0) LEAVE(err);}
+
+#define PANIC( exp ) {volatile TInt err = exp; \
+            LOG3( "PANIC(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\
+            User::Panic( KUsbPanicModule, err );}
 
 
-#else   // No loggings --> reduced code size
+#define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__));
+
+#else // _DEBUG   
+// ===========================================================================
 
-#define FLOG( a )
-#define FLOGHEX( a )
-#define FTRACE( a )
+#define LOG( s )
+#define LOG1( s, v ) 
+#define LOG2( s, v1, v2 )
+#define LOG3( s, v1, v2, v3 )
+#define LOG_FUNC_ENTRY 
+#define LOG_FUNC_EXIT 
+#define LEAVE( exp ) User::Leave( exp );
+#define LEAVEIFERROR( exp ) User::LeaveIfError( exp );
+#define PANIC( err ) User::Panic( KUsbPanicModule, err );
+#define LOG_FUNC
+// ===========================================================================
+#endif // _DEBUG
+// ===========================================================================
+#endif // DEBUG_H
 
-#endif //_DEBUG
-
-#endif // USBDEVCON_DEBUG_H
-
+// End of File