connectivitymodules/SeCon/plugins/hapticsconnplugin/inc/hapticsconntrace.h
author Pat Downey <patd@symbian.org>
Wed, 01 Sep 2010 12:20:56 +0100
branchRCL_3
changeset 20 4a793f564d72
parent 0 d0791faffa3f
permissions -rw-r--r--
Revert incorrect RCL_3 drop: Revision: 201032 Kit: 201035

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Haptics conn plugin debug trace macro definition header file.
*
*/
#ifndef HAPTICSCONNTRACE_H
#define HAPTICSCONNTRACE_H

#include <bldvariant.hrh>
#include <e32svr.h>
#include <e32std.h>
#include <e32svr.h>
#include <flogger.h>

/**
 * Writes formatted string data to a file using RFileLogger.
 *
 * @param aFmt Value-referenced descriptor containing the formatted string. 
 */
inline void HwrmWriteFormat( TRefByValue<const TDesC> aFmt, ... )
    {
    _LIT( KDir, "Hwrm" );
    _LIT( KName, "Hwres.log" );

    // take the ellipsis parameters
    VA_LIST args;
    VA_START( args, aFmt );
    RFileLogger::WriteFormat( KDir, KName, EFileLoggingModeAppend, aFmt, args );
    VA_END( args );
    }

/**
 * Writes data dump in hex format in "[ 00 01 FF ]" style.
 * 
 * @param aPrefix Descriptor containing the string to be appended in 
 *                front of the actual data dump.
 * @param aData   An 8-bit descriptor containing the data buffer for which 
 *                the data dump is written.
 */
inline void DataDumpTrace( const TDesC& aPrefix, const TDesC8& aData )
    {
    _LIT( KSATraceDataDumpStart, " [ " );
    _LIT( KSATraceDataDumpLineAlign, "   " );
    _LIT( KSATraceDataDumpStop, " ] " );
    _LIT( KSATraceDataDumpValue, "%02x " );
    const TInt KSASDataDumpTraceBytesPerLine = 10;
    
    HBufC* buffer = HBufC::New( 255 );

    if ( buffer != NULL )
        {
        buffer->Des().Copy( aPrefix );
        buffer->Des().Append( KSATraceDataDumpStart );
        for ( TInt i = 0; i < aData.Length(); i++)
            {
            buffer->Des().AppendFormat( KSATraceDataDumpValue,  aData[i] );
            
            if( ( i % KSASDataDumpTraceBytesPerLine == ( KSASDataDumpTraceBytesPerLine - 1 ) ) && 
                ( i + 1 < aData.Length() ) )
                {
                RDebug::Print( buffer->Des() );

                buffer->Des().Copy( aPrefix);
                buffer->Des().Append( KSATraceDataDumpLineAlign );
                }
            }
        buffer->Des().Append( KSATraceDataDumpStop );
            
        RDebug::Print( buffer->Des() );
                
        }

    delete buffer;
    }

#ifdef _DEBUG

    #ifdef USE_FILE_LOGGING
    
        #define COMPONENT_TRACE( a ) HwrmWriteFormat a
        #define API_TRACE( a ) HwrmWriteFormat a
        #define DATADUMP_TRACE( a, b )
    
    #else

        #define COMPONENT_TRACE( a ) RDebug::Print a
        #define API_TRACE( a ) RDebug::Print a
        #define DATADUMP_TRACE( a, b ) DataDumpTrace( a, b )
        
    #endif // #ifdef USE_FILE_LOGGING

#else // #ifdef _DEBUG

    #define COMPONENT_TRACE( a )
    #define API_TRACE( a )
    #define DATADUMP_TRACE( a, b ) 

#endif //#ifdef _DEBUG
#endif //#ifndef HAPTICSCONNTRACE_H


//  End of File