brandingserver/Group/DebugTrace.h
author hgs
Sun, 11 Apr 2010 15:33:49 +0530
changeset 31 9dbc70490d9a
permissions -rw-r--r--
201014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Debug Traces.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#ifndef __DEBUGTRACE_H__
hgs
parents:
diff changeset
    19
#define __DEBUGTRACE_H__
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
//  INCLUDES
hgs
parents:
diff changeset
    22
#include  "e32std.h"
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
//  DEFINES
hgs
parents:
diff changeset
    25
//Undefine: tracing disabled
hgs
parents:
diff changeset
    26
//Define 1: Traces goes to file log
hgs
parents:
diff changeset
    27
//Define 2: Traces goes to RDebug output
hgs
parents:
diff changeset
    28
//Define 3: Trace goes both file and RDebug output
hgs
parents:
diff changeset
    29
#undef TRACE_MODE
hgs
parents:
diff changeset
    30
//#define TRACE_MODE 3
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    35
// Trace definitions
hgs
parents:
diff changeset
    36
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    37
#ifdef TRACE_MODE
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
    //  INCLUDES
hgs
parents:
diff changeset
    40
    #include <flogger.h>
hgs
parents:
diff changeset
    41
    #include <e32svr.h>
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
    // CONSTANTS
hgs
parents:
diff changeset
    44
    _LIT( KTraceLogDir, "BS" );
hgs
parents:
diff changeset
    45
    _LIT( KTraceLogFile, "BS.log" );
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
     //TRACE INDIRECTION
hgs
parents:
diff changeset
    48
    #define T_LIT(s) _L(s) // CSI: 78 # See above
hgs
parents:
diff changeset
    49
    #define TRACE Trace::Emit
hgs
parents:
diff changeset
    50
    #define IF_TRACE_ON( aStatement ) aStatement
hgs
parents:
diff changeset
    51
#endif  // TRACE_MODE
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    55
// Empty trace definitions
hgs
parents:
diff changeset
    56
//-----------------------------------------------------------------------------
hgs
parents:
diff changeset
    57
#ifndef TRACE_MODE
hgs
parents:
diff changeset
    58
    struct TEmptyTraceString { };
hgs
parents:
diff changeset
    59
    #define T_LIT(s) TEmptyTraceString()
hgs
parents:
diff changeset
    60
    #define IF_TRACE_ON( aStatement )
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
    inline void TRACE(TEmptyTraceString){}
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
    template<class T1>
hgs
parents:
diff changeset
    65
    inline void TRACE(TEmptyTraceString,T1){}
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
    template<class T1,class T2>
hgs
parents:
diff changeset
    68
    inline void TRACE(TEmptyTraceString,T1,T2){}
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
    template<class T1,class T2,class T3>
hgs
parents:
diff changeset
    71
    inline void TRACE(TEmptyTraceString,T1,T2,T3){}
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
    template<class T1,class T2,class T3,class T4>
hgs
parents:
diff changeset
    74
    inline void TRACE(TEmptyTraceString,T1,T2,T3,T4){}
hgs
parents:
diff changeset
    75
hgs
parents:
diff changeset
    76
    template<class T1,class T2,class T3,class T4,class T5>
hgs
parents:
diff changeset
    77
    inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5){}
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
    template<class T1,class T2,class T3,class T4,class T5,class T6>
hgs
parents:
diff changeset
    80
    inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6){}
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
    template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
hgs
parents:
diff changeset
    83
    inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6,T7){}
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
    template<class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
hgs
parents:
diff changeset
    86
    inline void TRACE(TEmptyTraceString,T1,T2,T3,T4,T5,T6,T7,T8){}
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
#endif  // TRACE_MODE
hgs
parents:
diff changeset
    89
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
hgs
parents:
diff changeset
    93
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    94
// Trace implementation
hgs
parents:
diff changeset
    95
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    96
#ifdef TRACE_MODE
hgs
parents:
diff changeset
    97
    #include <flogger.h>
hgs
parents:
diff changeset
    98
    #include <e32svr.h>
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
    // TARGET WARNING
hgs
parents:
diff changeset
   101
    #if !defined(_DEBUG)
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
    #if defined(__CW32__)
hgs
parents:
diff changeset
   104
    #pragma message("Trace logging on.") // CSI: 68 # See above
hgs
parents:
diff changeset
   105
    #else
hgs
parents:
diff changeset
   106
    //ARMCC warning
hgs
parents:
diff changeset
   107
    #endif
hgs
parents:
diff changeset
   108
    #endif
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
    namespace Trace
hgs
parents:
diff changeset
   111
        {
hgs
parents:
diff changeset
   112
        class TOverflowHandler : public TDes16Overflow
hgs
parents:
diff changeset
   113
            {
hgs
parents:
diff changeset
   114
            inline void Overflow( TDes16& /*aDes*/ ) {}
hgs
parents:
diff changeset
   115
            };
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
        inline void Emit( TRefByValue<const TDesC> aFmt, ... )
hgs
parents:
diff changeset
   118
            {
hgs
parents:
diff changeset
   119
            //Format the log line
hgs
parents:
diff changeset
   120
            TBuf< 250 > buffer;
hgs
parents:
diff changeset
   121
            buffer.Append( _L("[") ); // CSI: 78 # See above
hgs
parents:
diff changeset
   122
            buffer.Append( RThread().Name() );
hgs
parents:
diff changeset
   123
            buffer.Append( _L("] ") ); // CSI: 78 # See above
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
            TOverflowHandler overflowHandler;
hgs
parents:
diff changeset
   126
hgs
parents:
diff changeset
   127
            VA_LIST list;
hgs
parents:
diff changeset
   128
            VA_START( list, aFmt );
hgs
parents:
diff changeset
   129
            buffer.AppendFormatList( aFmt, list, &overflowHandler );
hgs
parents:
diff changeset
   130
hgs
parents:
diff changeset
   131
            TInt theTraceMode = TRACE_MODE;
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
            //Send trace to file
hgs
parents:
diff changeset
   134
            if( ( theTraceMode == 1 ) ||
hgs
parents:
diff changeset
   135
                ( theTraceMode == 3 ) )
hgs
parents:
diff changeset
   136
                {
hgs
parents:
diff changeset
   137
                RFileLogger logger;
hgs
parents:
diff changeset
   138
                if( logger.Connect() == KErrNone )
hgs
parents:
diff changeset
   139
                    {
hgs
parents:
diff changeset
   140
                    logger.SetDateAndTime( EFalse, ETrue );
hgs
parents:
diff changeset
   141
                    logger.CreateLog( KTraceLogDir,
hgs
parents:
diff changeset
   142
                                      KTraceLogFile,
hgs
parents:
diff changeset
   143
                                      EFileLoggingModeAppend );
hgs
parents:
diff changeset
   144
hgs
parents:
diff changeset
   145
                    logger.Write( buffer );
hgs
parents:
diff changeset
   146
                    logger.CloseLog();
hgs
parents:
diff changeset
   147
                    logger.Close();
hgs
parents:
diff changeset
   148
                    }
hgs
parents:
diff changeset
   149
                }
hgs
parents:
diff changeset
   150
hgs
parents:
diff changeset
   151
            //Send trace to default debug output
hgs
parents:
diff changeset
   152
            if( ( theTraceMode == 2 ) ||
hgs
parents:
diff changeset
   153
                ( theTraceMode == 3 ) )
hgs
parents:
diff changeset
   154
                {
hgs
parents:
diff changeset
   155
                RDebug::Print( _L("%S"), &buffer );
hgs
parents:
diff changeset
   156
                }
hgs
parents:
diff changeset
   157
            }
hgs
parents:
diff changeset
   158
        }
hgs
parents:
diff changeset
   159
#endif //TRACE_MODE
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
#endif //__DEBUGTRACE_H__
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
//  END OF FILE