connectivitymodules/SeCon/inc/debug.h
branchRCL_3
changeset 24 8e7494275d3a
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Debug utility for SeCon components.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef _SECON_DEBUG_H
       
    20 #define _SECON_DEBUG_H
       
    21 
       
    22 #ifdef _DEBUG
       
    23     
       
    24     // Enable file logging
       
    25     #define __FLOGGING__
       
    26     
       
    27     #include <e32svr.h>
       
    28     #ifdef __FLOGGING__
       
    29         #include <f32file.h>
       
    30         #include <flogger.h>
       
    31     #endif
       
    32     
       
    33     NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    34         {
       
    35     public:
       
    36         void Overflow(TDes16& /*aDes*/) {}
       
    37         };
       
    38     
       
    39     NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    40         {
       
    41     public:
       
    42         void Overflow(TDes8& /*aDes*/) {}
       
    43         };
       
    44     
       
    45     _LIT( KLogDir, "SECON" );
       
    46     _LIT( KLogFile, "SeconDebug.txt" );
       
    47     
       
    48     _LIT(KTracePrefix16, "[SeCon] ");
       
    49     _LIT8(KTracePrefix8, "[SeCon] ");
       
    50     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    51     _LIT8(KFuncExitFormat8, "%S : End");
       
    52     _LIT8(KFuncReturnFormat8, "%S : End, return: %d");
       
    53     _LIT8(KFuncFormat8, "><%S");
       
    54     
       
    55     const TInt KMaxLogLineLength = 512;
       
    56     
       
    57     // old function loggin macros
       
    58     #define LOGGER_ENTERFN( name )      {TRACE_FUNC_ENTRY;}
       
    59     #define LOGGER_LEAVEFN( name )      {TRACE_FUNC_EXIT;}
       
    60     
       
    61     #define LOGGER_WRITE( text )                    {_LIT( KTemp, text ); FPrint( KTemp );}
       
    62     #define LOGGER_WRITE_1( text,par1 )             {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
       
    63     #define LOGGER_WRITE8_1( text,par1 )            {_LIT8( KTemp, text ); FPrint( KTemp, par1 );}
       
    64     #define LOGGER_WRITE_2( text,par1,par2 )        {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );}
       
    65     #define LOGGER_WRITE_3( text,par1,par2,par3 )   {_LIT( KTemp, text ); FPrint( KTemp, par1, par2, par3 );}
       
    66     
       
    67     // New function logging macros
       
    68     #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);}
       
    69     #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);}
       
    70     #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);}
       
    71     
       
    72     #define TRACE_FUNC_RET( number )  {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncReturnFormat8, &ptr8, number);}
       
    73     // Declare the FPrint function
       
    74     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
       
    75         {
       
    76         VA_LIST list;
       
    77         VA_START(list,aFmt);
       
    78     #ifdef __FLOGGING__
       
    79         RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    80     #endif
       
    81         TBuf16<KMaxLogLineLength> theFinalString;
       
    82         theFinalString.Append(KTracePrefix16);
       
    83         TOverflowTruncate16 overflow;
       
    84         theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    85         RDebug::Print(theFinalString);
       
    86         }
       
    87     
       
    88     // Declare the FPrint function
       
    89     inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
       
    90         {
       
    91         VA_LIST list;
       
    92         VA_START(list, aFmt);
       
    93     #ifdef __FLOGGING__
       
    94         RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    95     #endif
       
    96         TOverflowTruncate8 overflow;
       
    97         TBuf8<KMaxLogLineLength> buf8;
       
    98         buf8.Append(KTracePrefix8);
       
    99         buf8.AppendFormatList(aFmt, list, &overflow);
       
   100         TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
   101         buf16.Copy(buf8);
       
   102         TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
   103         RDebug::Print(tmpFmt, &buf16);
       
   104         }
       
   105 #else
       
   106     
       
   107     // No loggings --> reduced code size
       
   108 
       
   109     #define LOGGER_ENTERFN( name )
       
   110     #define LOGGER_LEAVEFN( name )
       
   111     #define LOGGER_WRITE( text )
       
   112     #define LOGGER_WRITE_1( text, par1 )
       
   113     #define LOGGER_WRITE8_1( text, par1 )
       
   114     #define LOGGER_WRITE_2( text, par1, par2 )
       
   115     #define LOGGER_WRITE_3( text, par1, par2, par3 )
       
   116     #define TRACE_FUNC_ENTRY
       
   117     #define TRACE_FUNC_EXIT
       
   118     #define TRACE_FUNC
       
   119     #define TRACE_FUNC_RET( number )
       
   120 
       
   121 #endif //_DEBUG
       
   122 
       
   123 #endif // SECON_DEBUG_H
       
   124 
       
   125 // End of file
       
   126