connectivitymodules/SeCon/servers/syncserver/inc/debug.h
branchRCL_3
changeset 19 0aa8cc770c8a
parent 18 453dfc402455
child 20 4a793f564d72
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 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 SyncServer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef _SECON_DEBUG_H
       
    20 #define _SECON_DEBUG_H
       
    21 
       
    22 #ifdef _DEBUG
       
    23     
       
    24     // 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, "[SeConSync] ");
       
    49     _LIT8(KTracePrefix8, "[SeConSync] ");
       
    50     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    51     _LIT8(KFuncExitFormat8, "%S : End");
       
    52     _LIT8(KFuncFormat8, "><%S");
       
    53     
       
    54     const TInt KMaxLogLineLength = 512;
       
    55     
       
    56     // old function loggin macros
       
    57     #define FLOG(a) {FPrint(a);}
       
    58     #define FLOG_1(a,b) {FPrint(a,b);}
       
    59     #define FLOG_2(a,b,c) {FPrint(a,b,c);}
       
    60     #define FTRACE(a) {a;}
       
    61     #define LOGGER_ENTERFN( name )      {TRACE_FUNC_ENTRY;}
       
    62     #define LOGGER_LEAVEFN( name )      {TRACE_FUNC_EXIT;}
       
    63     
       
    64     #define LOGGER_WRITE( text )                    {_LIT( KTemp, text ); FPrint( KTemp );}
       
    65     #define LOGGER_WRITE_1( text,par1 )             {_LIT( KTemp, text ); FPrint( KTemp, par1 );}
       
    66     #define LOGGER_WRITE8_1( text,par1 )            {_LIT8( KTemp, text ); FPrint( KTemp, par1 );}
       
    67     #define LOGGER_WRITE_2( text,par1,par2 )        {_LIT( KTemp, text ); FPrint( KTemp, par1, par2 );}
       
    68     #define LOGGER_WRITE_3( text,par1,par2,par3 )   {_LIT( KTemp, text ); FPrint( KTemp, par1, par2, par3 );}
       
    69     
       
    70     // New function logging macros
       
    71     #define TRACE_FUNC_ENTRY {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncEntryFormat8, &ptr8);}
       
    72     #define TRACE_FUNC_EXIT {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncExitFormat8, &ptr8);}
       
    73     #define TRACE_FUNC {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncFormat8, &ptr8);}
       
    74     
       
    75     // Declare the FPrint function
       
    76     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
       
    77         {
       
    78         VA_LIST list;
       
    79         VA_START(list,aFmt);
       
    80     #ifdef __FLOGGING__
       
    81         RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    82     #endif
       
    83         TBuf16<KMaxLogLineLength> theFinalString;
       
    84         theFinalString.Append(KTracePrefix16);
       
    85         TOverflowTruncate16 overflow;
       
    86         theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    87         RDebug::Print(theFinalString);
       
    88         }
       
    89     
       
    90     // Declare the FPrint function
       
    91     inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
       
    92         {
       
    93         VA_LIST list;
       
    94         VA_START(list, aFmt);
       
    95     #ifdef __FLOGGING__
       
    96         RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    97     #endif
       
    98         TOverflowTruncate8 overflow;
       
    99         TBuf8<KMaxLogLineLength> buf8;
       
   100         buf8.Append(KTracePrefix8);
       
   101         buf8.AppendFormatList(aFmt, list, &overflow);
       
   102         TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
   103         buf16.Copy(buf8);
       
   104         TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
   105         RDebug::Print(tmpFmt, &buf16);
       
   106         }
       
   107 #else
       
   108     
       
   109     // No loggings --> reduced code size
       
   110     #define FLOG(a)
       
   111     #define FLOG_1(a,b)
       
   112     #define FLOG_2(a,b,c)
       
   113     #define FTRACE(a)
       
   114     #define LOGGER_ENTERFN( name )
       
   115     #define LOGGER_LEAVEFN( name )
       
   116     #define LOGGER_WRITE( text )
       
   117     #define LOGGER_WRITE_1( text, par1 )
       
   118     #define LOGGER_WRITE8_1( text, par1 )
       
   119     #define LOGGER_WRITE_2( text, par1, par2 )
       
   120     #define LOGGER_WRITE_3( text, par1, par2, par3 )
       
   121     #define TRACE_FUNC_ENTRY
       
   122     #define TRACE_FUNC_EXIT
       
   123     #define TRACE_FUNC
       
   124 
       
   125 #endif //_DEBUG
       
   126 
       
   127 #endif // SECON_DEBUG_H
       
   128 
       
   129 // End of file
       
   130