phonebookengines/VirtualPhonebook/inc/VPbkDebugEntryAndExit.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Debugging utilities for logging function entry/exit
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef VPBKDEBUG_ENTRYANDEXIT_H
       
    21 #define VPBKDEBUG_ENTRYANDEXIT_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "VPbkConfig.hrh"
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <e32svr.h>
       
    28 
       
    29 #if defined( VPBK_ENABLE_DEBUG_PRINT ) && defined ( __MODULE__ ) && defined( __LINE__ )
       
    30     // Debug logging is enabled and the required macros are available in the
       
    31     // compiler.
       
    32     // Ps. It seems that these are not available in WINSCW environment.
       
    33 
       
    34     /**
       
    35      * Constants for FUNC_ENTRY and FUNC_EXIT macros and examples of the
       
    36      * corresponding output.
       
    37      */
       
    38     _LIT( KFuncEntry,  "%S:%d >>> %S" ); // "example.cpp:609 >>> ExampleL"
       
    39     _LIT( KFuncExit, "%S:%d <<< %S" );   // "example.cpp:642 <<< ExampleL"
       
    40     const TInt KMaxDesC8Length(128);     // limit output to 128 characters
       
    41 
       
    42     #ifdef VPBK_ENABLE_DEBUG_LOGGER
       
    43         #include <flogger.h>
       
    44         _LIT( KLogDir, "VPbk" );
       
    45         _LIT( KLogName, "VPbk.log" );
       
    46 
       
    47         #define FUNC_ENTRY FuncEntryToLog
       
    48         #define FUNC_EXIT FuncExitToLog
       
    49 
       
    50         namespace
       
    51             {
       
    52             /**
       
    53              * Print function entry to log file
       
    54              */
       
    55             void FuncEntryToLog()
       
    56                 {
       
    57                 TBuf<KMaxDesC8Length> moduleBuf;
       
    58                 moduleBuf.Copy( _L8(__MODULE__).Left(KMaxDesC8Length) );
       
    59                 TBuf<KMaxDesC8Length> funcBuf;
       
    60                 funcBuf.Copy( _L8(__func__).Left(KMaxDesC8Length) );
       
    61                 RFileLogger::WriteFormat(
       
    62                     KLogDir(), KLogName(), EFileLoggingModeAppend,
       
    63                     TRefByValue<const TDesC>( KFuncEntry() ),
       
    64                     &moduleBuf, __LINE__, &funcBuf );
       
    65                 }
       
    66             /**
       
    67              * Print function exit to log file
       
    68              */
       
    69             void FuncExitToLog()
       
    70                 {
       
    71                 TBuf<KMaxDesC8Length> moduleBuf;
       
    72                 moduleBuf.Copy( _L8(__MODULE__).Left(KMaxDesC8Length) );
       
    73                 TBuf<KMaxDesC8Length> funcBuf;
       
    74                 funcBuf.Copy( _L8(__func__).Left(KMaxDesC8Length) );
       
    75                 RFileLogger::WriteFormat(
       
    76                     KLogDir(), KLogName(), EFileLoggingModeAppend,
       
    77                     TRefByValue<const TDesC>( KFuncExit() ),
       
    78                     &moduleBuf, __LINE__, &funcBuf );
       
    79                 }
       
    80             }  // namespace
       
    81     #else // VPBK_ENABLE_DEBUG_LOGGER
       
    82         #define FUNC_ENTRY FuncEntryToRDebug
       
    83         #define FUNC_EXIT FuncExitToRDebug
       
    84 
       
    85         namespace
       
    86             {
       
    87             /**
       
    88              * Print function entry to RDebug 
       
    89              */
       
    90             void FuncEntryToRDebug()
       
    91                 {
       
    92                 TBuf<KMaxDesC8Length> moduleBuf;
       
    93                 moduleBuf.Copy( _L8(__MODULE__).Left(KMaxDesC8Length) );
       
    94                 TBuf<KMaxDesC8Length> funcBuf;
       
    95                 funcBuf.Copy( _L8(__func__).Left(KMaxDesC8Length) );
       
    96                 RDebug::Print( KFuncEntry, &moduleBuf, __LINE__, &funcBuf );
       
    97                 }
       
    98             /**
       
    99              * Print function exit to RDebug 
       
   100              */
       
   101             void FuncExitToRDebug()
       
   102                 {
       
   103                 TBuf<KMaxDesC8Length> moduleBuf;
       
   104                 moduleBuf.Copy( _L8(__MODULE__).Left(KMaxDesC8Length) );
       
   105                 TBuf<KMaxDesC8Length> funcBuf;
       
   106                 funcBuf.Copy( _L8(__func__).Left(KMaxDesC8Length) );
       
   107                 RDebug::Print( KFuncExit, &moduleBuf, __LINE__, &funcBuf );
       
   108                 }
       
   109             }  // namespace
       
   110     #endif // #ifdef VPBK_ENABLE_DEBUG_LOGGER
       
   111 
       
   112 #else // VPBK_ENABLE_DEBUG_PRINT
       
   113     #define FUNC_ENTRY()
       
   114     #define FUNC_EXIT()
       
   115 #endif
       
   116 
       
   117 
       
   118 #ifdef _DEBUG
       
   119     /**
       
   120      * Helper macro for calling invariant on function entry and (normal) exit.
       
   121      * Declare typedef SelfType as the type of the class you're using this
       
   122      * macro in.
       
   123      */
       
   124     #define VPBK_DEBUG_TEST_INVARIANT_ON_ENTRY_AND_EXIT \
       
   125                 TPbkDebugCallInvariantOnEntryAndExit<SelfType> \
       
   126                 __pbk_debug_test_invariant(this)
       
   127 
       
   128 #else
       
   129 
       
   130     /**
       
   131      * Helper macro for calling invariant on function entry and (normal) exit.
       
   132      * This is empty release build version.
       
   133      */
       
   134     #define VPBK_DEBUG_TEST_INVARIANT_ON_ENTRY_AND_EXIT
       
   135 
       
   136 #endif
       
   137 
       
   138 // CLASS DECLARATION
       
   139 
       
   140 /**
       
   141  * Helper class for calling class invariant automatically on function
       
   142  * entry and exit.
       
   143  */
       
   144 template<class T>
       
   145 class TPbkDebugCallInvariantOnEntryAndExit
       
   146     {
       
   147     public:
       
   148         /**
       
   149      * Constructor.
       
   150      * @param aObj object
       
   151      */
       
   152     inline TPbkDebugCallInvariantOnEntryAndExit(const T* aObj)
       
   153         : iObj(aObj)
       
   154         {
       
   155         iObj->__DbgTestInvariant();
       
   156         }
       
   157 
       
   158     /**
       
   159      * Destructor
       
   160      */
       
   161     inline ~TPbkDebugCallInvariantOnEntryAndExit()
       
   162         {
       
   163         iObj->__DbgTestInvariant();
       
   164         }
       
   165 
       
   166 private: // data
       
   167     /// Ref: the object
       
   168     const T* iObj;
       
   169     };
       
   170 
       
   171 #endif // VPBKDEBUG_ENTRYANDEXIT_H
       
   172 
       
   173 // End of File