hwrmhaptics/inc/hwrmhapticstrace.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Haptics debug trace macro definition header file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef HWRMHAPTICSTRACE_H
       
    20 #define HWRMHAPTICSTRACE_H
       
    21 
       
    22 #include <bldvariant.hrh>
       
    23 #include <e32svr.h>
       
    24 #include <e32std.h>
       
    25 #include <e32svr.h>
       
    26 #include <flogger.h>
       
    27 
       
    28 /**
       
    29  * Writes formatted string data to a file using RFileLogger.
       
    30  *
       
    31  * @param aFmt Value-referenced descriptor containing the formatted string. 
       
    32  */
       
    33 inline void HwrmWriteFormat( TRefByValue<const TDesC> aFmt, ... )
       
    34     {
       
    35     _LIT( KDir, "haptics" );
       
    36     _LIT( KName, "haptics.log" );
       
    37 
       
    38     // take the ellipsis parameters
       
    39     VA_LIST args;
       
    40     VA_START( args, aFmt );
       
    41     RFileLogger::WriteFormat( KDir, KName, EFileLoggingModeAppend, aFmt, args );
       
    42     VA_END( args );
       
    43     }
       
    44 
       
    45 /**
       
    46  * Writes data dump in hex format in "[ 00 01 FF ]" style.
       
    47  * 
       
    48  * @param aPrefix Descriptor containing the string to be appended in 
       
    49  *                front of the actual data dump.
       
    50  * @param aData   An 8-bit descriptor containing the data buffer for which 
       
    51  *                the data dump is written.
       
    52  */
       
    53 inline void DataDumpTrace( const TDesC& aPrefix, const TDesC8& aData )
       
    54     {
       
    55     _LIT( KSATraceDataDumpStart, " [ " );
       
    56     _LIT( KSATraceDataDumpLineAlign, "   " );
       
    57     _LIT( KSATraceDataDumpStop, " ] " );
       
    58     _LIT( KSATraceDataDumpValue, "%02x " );
       
    59     const TInt KSASDataDumpTraceBytesPerLine = 10;
       
    60     
       
    61     HBufC* buffer = HBufC::New( 255 );
       
    62 
       
    63     if ( buffer != NULL )
       
    64         {
       
    65         buffer->Des().Copy( aPrefix );
       
    66         buffer->Des().Append( KSATraceDataDumpStart );
       
    67         for ( TInt i = 0; i < aData.Length(); i++)
       
    68             {
       
    69             buffer->Des().AppendFormat( KSATraceDataDumpValue,  aData[i] );
       
    70             
       
    71             if( ( i % KSASDataDumpTraceBytesPerLine == ( KSASDataDumpTraceBytesPerLine - 1 ) ) && 
       
    72                 ( i + 1 < aData.Length() ) )
       
    73                 {
       
    74                 RDebug::Print( buffer->Des() );
       
    75 
       
    76                 buffer->Des().Copy( aPrefix);
       
    77                 buffer->Des().Append( KSATraceDataDumpLineAlign );
       
    78                 }
       
    79             }
       
    80         buffer->Des().Append( KSATraceDataDumpStop );
       
    81             
       
    82         RDebug::Print( buffer->Des() );
       
    83                 
       
    84         }
       
    85 
       
    86     delete buffer;
       
    87     }
       
    88 
       
    89 
       
    90 #ifdef _DEBUG
       
    91 
       
    92     #ifdef USE_FILE_LOGGING
       
    93        
       
    94         #define COMPONENT_TRACE( a ) HwrmWriteFormat a 
       
    95         #define DATADUMP_TRACE( a, b ) 
       
    96         #define API_TRACE( a ) HwrmWriteFormat a 
       
    97         
       
    98     #else
       
    99 
       
   100         #define COMPONENT_TRACE( a ) RDebug::Print a 
       
   101         #define DATADUMP_TRACE( a, b ) DataDumpTrace( a, b ) 
       
   102         #define API_TRACE( a ) RDebug::Print a
       
   103             
       
   104     #endif // #ifdef USE_FILE_LOGGING
       
   105 
       
   106 #else // #ifdef _DEBUG
       
   107 
       
   108     #define COMPONENT_TRACE( a )
       
   109     #define API_TRACE( a )
       
   110     #define DATADUMP_TRACE( a, b ) 
       
   111 
       
   112 #endif //#ifdef _DEBUG
       
   113 #endif //#ifndef HWRMHAPTICSTRACE_H
       
   114 
       
   115 
       
   116 //  End of File