1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/src/inc/featmgrdebug.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,213 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#ifndef FEATMGRDEBUG_H
1.24 +#define FEATMGRDEBUG_H
1.25 +
1.26 +
1.27 +// INCLUDES
1.28 +#include <e32debug.h>
1.29 +
1.30 +// Enable macros to support error and/or info logging
1.31 +#ifdef _DEBUG
1.32 + //#define FEATMGR_INFO_LOG_ENABLED
1.33 + //#define FEATMGR_ERROR_LOG_ENABLED
1.34 + #define FEATMGR_TIMESTAMP_ENABLED
1.35 +#endif // _DEBUG
1.36 +
1.37 +
1.38 +/**
1.39 +* Prefix trace macro to complete tracing with component name.
1.40 +* Returns TDesC which can be used directly with RDebug or RFileLogger.
1.41 +*/
1.42 + #define PREFIX( aMsg ) TPtrC( (const TText*)L"[EFM]: " L##aMsg )
1.43 +
1.44 +/**
1.45 +* Prefix error trace
1.46 +*/
1.47 + #define ERROR_PREFIX( aMsg ) PREFIX( "[ERROR]: " L##aMsg )
1.48 +
1.49 +/**
1.50 +* Prefix macro for strings
1.51 +*/
1.52 +#define _PREFIX_CHAR( aMsg ) (const char*)"[EFM]: " ##aMsg
1.53 +
1.54 +// Info logging
1.55 +#ifdef FEATMGR_INFO_LOG_ENABLED
1.56 +
1.57 + #define INFO_LOG( aMsg ) { RDebug::Print( PREFIX( aMsg ) ); }
1.58 +
1.59 + #define INFO_LOG1( aMsg, aArg1 )\
1.60 + { RDebug::Print( PREFIX( aMsg ), aArg1 ); }
1.61 +
1.62 + #define INFO_LOG2( aMsg, aArg1, aArg2 )\
1.63 + { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2 ); }
1.64 +
1.65 + #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )\
1.66 + { RDebug::Print( PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
1.67 +
1.68 + #define FUNC( aMsg, aP1 )\
1.69 + {\
1.70 + RDebug::Printf( aMsg, aP1 );\
1.71 + }\
1.72 +// Function log object
1.73 +_LIT8( KFuncNameTerminator, "(" );
1.74 +_LIT8( KFuncLeavePattern, "L" );
1.75 +
1.76 +class TFuncLog
1.77 + {
1.78 + public:
1.79 +
1.80 + static void Cleanup( TAny* aPtr )
1.81 + {
1.82 + TFuncLog* self = static_cast< TFuncLog* >( aPtr );
1.83 + self->iLeft = ETrue;
1.84 + FUNC( _PREFIX_CHAR("%S-LEAVE"), &self->iFunc ); // Leave detected
1.85 + }
1.86 +
1.87 + inline TFuncLog( const char* aFunc ) :
1.88 + iFunc( aFunc ? _S8( aFunc ) : _S8("") ),
1.89 + iLeft( EFalse ),
1.90 + iCleanupItem( Cleanup, this ),
1.91 + iCanLeave( EFalse )
1.92 + {
1.93 + TInt pos( iFunc.Find( KFuncNameTerminator ) );
1.94 + if( pos != KErrNotFound )
1.95 + {
1.96 + iFunc.Set( iFunc.Left( pos ) );
1.97 + iCanLeave = !iFunc.Right( KFuncLeavePattern().Length() ).Compare( KFuncLeavePattern );
1.98 + if ( iCanLeave )
1.99 + {
1.100 + CleanupStack::PushL( iCleanupItem ); // Ignore warnings
1.101 + }
1.102 + }
1.103 + FUNC( _PREFIX_CHAR("%S-START"), &iFunc );
1.104 + }
1.105 +
1.106 + inline ~TFuncLog()
1.107 + {
1.108 + if ( !iLeft )
1.109 + {
1.110 + if ( iCanLeave )
1.111 + {
1.112 + CleanupStack::Pop( this ); // Pop the cleanup item
1.113 + }
1.114 + FUNC( _PREFIX_CHAR("%S-END"), &iFunc ); // Normally finished
1.115 + }
1.116 + }
1.117 +
1.118 + private: // Data
1.119 +
1.120 + TPtrC8 iFunc;
1.121 + TBool iLeft;
1.122 + TCleanupItem iCleanupItem;
1.123 + TBool iCanLeave;
1.124 + };
1.125 +
1.126 + #define FUNC_LOG TFuncLog _fl( __PRETTY_FUNCTION__ );
1.127 +
1.128 +#else // FEATMGR_INFO_LOG_ENABLED
1.129 +
1.130 + #define INFO_LOG( aMsg )
1.131 +
1.132 + #define INFO_LOG1( aMsg, aArg1 )
1.133 +
1.134 + #define INFO_LOG2( aMsg, aArg1, aArg2 )
1.135 +
1.136 + #define INFO_LOG3( aMsg, aArg1, aArg2, aArg3 )
1.137 +
1.138 + #define FUNC_LOG
1.139 +
1.140 +#endif // FEATMGR_INFO_LOG_ENABLED
1.141 +
1.142 +// Timestamp logging
1.143 +#ifdef FEATMGR_TIMESTAMP_ENABLED
1.144 +
1.145 + #define TIMESTAMP( aCaption )\
1.146 + {\
1.147 + TTime t;\
1.148 + t.HomeTime();\
1.149 + TDateTime dt = t.DateTime();\
1.150 + _LIT( KCaption, aCaption );\
1.151 + RDebug::Print( PREFIX("[TIMESTAMP] %S %d:%02d:%02d.%d us"),\
1.152 + &KCaption, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond() );\
1.153 + }
1.154 +
1.155 +#else
1.156 +
1.157 + #define TIMESTAMP( aCaption )
1.158 +
1.159 +#endif // FEATMGR_TIMESTAMP_ENABLED
1.160 +
1.161 +// Error logging
1.162 +#ifdef FEATMGR_ERROR_LOG_ENABLED
1.163 +
1.164 + #define ERROR_LOG( aMsg )\
1.165 + {RDebug::Print( ERROR_PREFIX( aMsg ) ); }
1.166 +
1.167 + #define ERROR_LOG1( aMsg, aArg1 )\
1.168 + {RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
1.169 +
1.170 + #define ERROR_LOG2( aMsg, aArg1, aArg2 )\
1.171 + { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
1.172 +
1.173 + #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )\
1.174 + { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
1.175 +
1.176 + #define LOG_IF_ERROR( aErr, aMsg )\
1.177 + if ( ( aErr ) != KErrNone )\
1.178 + { RDebug::Print( ERROR_PREFIX( aMsg )); }
1.179 +
1.180 + #define LOG_IF_ERROR1( aErr, aMsg, aArg1 )\
1.181 + if ( ( aErr ) != KErrNone )\
1.182 + { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1 ); }
1.183 +
1.184 + #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 )\
1.185 + if ( ( aErr ) != KErrNone )\
1.186 + { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2 ); }
1.187 +
1.188 + #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 )\
1.189 + if ( ( aErr ) != KErrNone )\
1.190 + { RDebug::Print( ERROR_PREFIX( aMsg ), aArg1, aArg2, aArg3 ); }
1.191 +
1.192 +#else // FEATMGR_ERROR_LOG_ENABLED
1.193 +
1.194 + #define ERROR_LOG( aMsg )
1.195 +
1.196 + #define ERROR_LOG1( aMsg, aArg1 )
1.197 +
1.198 + #define ERROR_LOG2( aMsg, aArg1, aArg2 )
1.199 +
1.200 + #define ERROR_LOG3( aMsg, aArg1, aArg2, aArg3 )
1.201 +
1.202 + // Remove compiler warning
1.203 + #define LOG_IF_ERROR( aErr, aMsg ) ( aErr ) = ( aErr );
1.204 +
1.205 + #define LOG_IF_ERROR1( aErr, aMsg, aArg1 ) ( aErr ) = ( aErr );
1.206 +
1.207 + #define LOG_IF_ERROR2( aErr, aMsg, aArg1, aArg2 ) ( aErr ) = ( aErr );
1.208 +
1.209 + #define LOG_IF_ERROR3( aErr, aMsg, aArg1, aArg2, aArg3 ) ( aErr ) = ( aErr );
1.210 +
1.211 +#endif // FEATMGR_ERROR_LOG_ENABLED
1.212 +
1.213 +
1.214 +#endif // FEATMGRDEBUG_H
1.215 +
1.216 +// End of File