omads/omadsextensions/adapters/mediads/inc/logger.h
branchRCL_3
changeset 25 4f0867e42d62
parent 24 8e7494275d3a
child 26 3e6957da2ff8
equal deleted inserted replaced
24:8e7494275d3a 25:4f0867e42d62
     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:  Logging macros used by Media DS Plugin
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __LOGGER_H__
       
    20 #define __LOGGER_H__
       
    21 
       
    22 #ifdef _DEBUG
       
    23     #ifdef __WINS__
       
    24         // File logging for WINS
       
    25         #define __FLOGGING__
       
    26     #else
       
    27         #define __FLOGGING__ // enable to log file on target HW
       
    28     #endif //__WINS__
       
    29     
       
    30     #include <e32svr.h>
       
    31     #ifdef __FLOGGING__
       
    32         #include <f32file.h>
       
    33         #include <flogger.h>
       
    34     #endif
       
    35     
       
    36     NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
       
    37         {
       
    38     public:
       
    39         void Overflow(TDes16& /*aDes*/) {}
       
    40         };
       
    41     
       
    42     NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
    43         {
       
    44     public:
       
    45         void Overflow(TDes8& /*aDes*/) {}
       
    46         };
       
    47     
       
    48     _LIT( KLogDir, "MediaDS" );
       
    49     _LIT( KLogFile, "MediaDS.txt" );
       
    50     
       
    51     _LIT(KTracePrefix16, "[MediaDs] ");
       
    52     _LIT8(KTracePrefix8, "[MediaDs] ");
       
    53     _LIT8(KFuncEntryFormat8, "%S : Begin");
       
    54     _LIT8(KFuncExitFormat8, "%S : End");
       
    55     _LIT8(KFuncReturnFormat8, "%S : End, return: %d");
       
    56     _LIT8(KFuncFormat8, "><%S");
       
    57     
       
    58     const TInt KMaxLogLineLength = 512;
       
    59     
       
    60     /**
       
    61     * logging macros, for public use
       
    62     */
       
    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     #define TRACE_FUNC_RET( number )  {TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); FPrint(KFuncReturnFormat8, &ptr8, number);}
       
    76     // Declare the FPrint function
       
    77     inline void FPrint( TRefByValue<const TDesC16> aFmt, ...)
       
    78         {
       
    79         VA_LIST list;
       
    80         VA_START(list,aFmt);
       
    81     #ifdef __FLOGGING__
       
    82         RFileLogger::WriteFormat( KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list );
       
    83     #endif
       
    84         TBuf16<KMaxLogLineLength> theFinalString;
       
    85         theFinalString.Append(KTracePrefix16);
       
    86         TOverflowTruncate16 overflow;
       
    87         theFinalString.AppendFormatList(aFmt,list,&overflow);
       
    88         RDebug::Print(theFinalString);
       
    89         }
       
    90     
       
    91     // Declare the FPrint function
       
    92     inline void FPrint(TRefByValue<const TDesC8> aFmt, ...)
       
    93         {
       
    94         VA_LIST list;
       
    95         VA_START(list, aFmt);
       
    96     #ifdef __FLOGGING__
       
    97         RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeAppend, aFmt, list);
       
    98     #endif
       
    99         TOverflowTruncate8 overflow;
       
   100         TBuf8<KMaxLogLineLength> buf8;
       
   101         buf8.Append(KTracePrefix8);
       
   102         buf8.AppendFormatList(aFmt, list, &overflow);
       
   103         TBuf16<KMaxLogLineLength> buf16(buf8.Length());
       
   104         buf16.Copy(buf8);
       
   105         TRefByValue<const TDesC> tmpFmt(_L("%S"));
       
   106         RDebug::Print(tmpFmt, &buf16);
       
   107         }
       
   108 #else // no _DEBUG defined
       
   109     
       
   110     // No loggings --> reduced code size
       
   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 // __LOGGER_H__
       
   124