phonebookengines/VirtualPhonebook/inc/VPbkDebug.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
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef VPBKDEBUG_H
       
    21 #define VPBKDEBUG_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "VPbkConfig.hrh"
       
    25 #include "VPbkDebugEntryAndExit.h"
       
    26 
       
    27 #include <e32std.h>
       
    28 #include <e32svr.h>
       
    29 
       
    30 // MACROS
       
    31 #ifdef _DEBUG
       
    32 
       
    33     /// Helper macro for defining debug-only test code
       
    34     #define VPBK_DEBUG_ONLY(f) f
       
    35 
       
    36 #else
       
    37 
       
    38     /// Helper macro for defining debug-only test code (empty release version)
       
    39     #define VPBK_DEBUG_ONLY(f)
       
    40 
       
    41 #endif
       
    42 
       
    43 #ifdef VPBK_ENABLE_DEBUG_PRINT
       
    44     // Debug logging is enabled
       
    45 
       
    46     // warn if this is a release build
       
    47     #ifndef __WINSCW__
       
    48     #ifndef _DEBUG
       
    49         #if defined(__VC32__)
       
    50             #pragma message("Warning: VirtualPhonebook debug printing is on in release build!")
       
    51         #else // __GCC32__
       
    52             #warning "VirtualPhonebook debug printing is on in release build!"
       
    53         #endif // __VC32__
       
    54     #endif
       
    55     #endif // __WINSCW__
       
    56 
       
    57     /**
       
    58      * Macro for defining debug-only literal strings.
       
    59      */
       
    60     #define VPBK_DEBUG_STRING(s) _L(s)
       
    61 
       
    62     #ifdef VPBK_ENABLE_DEBUG_LOGGER
       
    63         // Print to log file
       
    64         #define VPBK_DEBUG_PRINT PbkPrintToLog
       
    65 
       
    66         #include <flogger.h>
       
    67 
       
    68         namespace {
       
    69         void PbkPrintToLog( TRefByValue<const TDesC> aFormat, ... )
       
    70             {
       
    71             _LIT( KLogDir, "VPbk" );
       
    72             _LIT( KLogName, "VPbk.log" );
       
    73 
       
    74             VA_LIST args;
       
    75             VA_START( args, aFormat );
       
    76             RFileLogger::WriteFormat
       
    77                 (KLogDir, KLogName, EFileLoggingModeAppend, aFormat, args);
       
    78             VA_END( args );
       
    79             }
       
    80         }  // namespace
       
    81 
       
    82     #else
       
    83         /**
       
    84          * Prints to debugger output.
       
    85          */
       
    86         #define VPBK_DEBUG_PRINT RDebug::Print
       
    87 
       
    88     #endif // #ifdef VPBK_ENABLE_DEBUG_LOGGER
       
    89 
       
    90 #else
       
    91 
       
    92     /**
       
    93      * Dummy struct for checking that all VPBK_DEBUG_PRINT's define string
       
    94      * literals using space-saving VPBK_DEBUG_STRING.
       
    95      */
       
    96     struct TPbkEmptyDebugString { };
       
    97 
       
    98     /**
       
    99      * Macro for defining debug-only literal strings (empty release version)
       
   100      */
       
   101     #define VPBK_DEBUG_STRING(s) TPbkEmptyDebugString()
       
   102 
       
   103     /// Empty debug print function for release builds.
       
   104     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString)
       
   105         {
       
   106         }
       
   107 
       
   108     /// Empty debug print function for release builds.
       
   109     template<class T1>
       
   110     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1)
       
   111         {
       
   112         }
       
   113 
       
   114     /// Empty debug print function for release builds.
       
   115     template<class T1,class T2>
       
   116     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2)
       
   117         {
       
   118         }
       
   119 
       
   120     /// Empty debug print function for release builds.
       
   121     template<class T1,class T2,class T3>
       
   122     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3)
       
   123         {
       
   124         }
       
   125 
       
   126     /// Empty debug print function for release builds.
       
   127     template<class T1,class T2,class T3,class T4>
       
   128     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3,T4)
       
   129         {
       
   130         }
       
   131 
       
   132     /// Empty debug print function for release builds.
       
   133     template<class T1,class T2,class T3,class T4,class T5>
       
   134     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3,T4,T5)
       
   135         {
       
   136         }
       
   137 
       
   138     /// Empty debug print function for release builds.
       
   139     template<class T1,class T2,class T3,class T4,class T5,class T6>
       
   140     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3,T4,T5,T6)
       
   141         {
       
   142         }
       
   143 
       
   144     /// Empty debug print function for release builds.
       
   145     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
       
   146     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3,T4,T5,T6,T7)
       
   147         {
       
   148         }
       
   149 
       
   150     /// Empty debug print function for release builds.
       
   151     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
       
   152     inline void VPBK_DEBUG_PRINT(TPbkEmptyDebugString,T1,T2,T3,T4,T5,T6,T7,T8)
       
   153         {
       
   154         }
       
   155 
       
   156 #endif
       
   157 
       
   158 
       
   159 #ifdef VPBK_ENABLE_PROFILE
       
   160     #define __VPBK_PROFILE_START(aBin) RDebug::ProfileStart(aBin)
       
   161     #define __VPBK_PROFILE_END(aBin)   RDebug::ProfileEnd(aBin)
       
   162 
       
   163     // Needs VPBK_ENABLE_DEBUG_LOGGER
       
   164     #define __VPBK_PROFILE_DISPLAY(aBin) \
       
   165         { \
       
   166         TProfile result; \
       
   167         RDebug::ProfileResult(&result, aBin, 1); \
       
   168         VPBK_DEBUG_PRINT \
       
   169             (VPBK_DEBUG_STRING("Profile bin %d:  Calls: %d, Time: %d\n" ), \
       
   170         aBin, result.iCount, result.iTime); \
       
   171         }
       
   172     #define __VPBK_PROFILE_RESET(aBin) RDebug::ProfileReset(aBin, 1)
       
   173 #else
       
   174     #define __VPBK_PROFILE_START(aBin)
       
   175     #define __VPBK_PROFILE_END(aBin)
       
   176     #define __VPBK_PROFILE_DISPLAY(aBin)
       
   177     #define __VPBK_PROFILE_RESET(aBin)
       
   178 
       
   179 #endif // VPBK_ENABLE_PROFILE
       
   180 
       
   181 
       
   182 #ifdef _DEBUG
       
   183 
       
   184 /**
       
   185  * Asserts and checks that statement doesn't allocate any memory. If
       
   186  * allocation happens evaluates failed.
       
   187  */
       
   188 #define VPBK_ASSERT_NO_ALLOC(statement,failed) \
       
   189     { __UHEAP_FAILNEXT(1); \
       
   190     TRAPD(err, statement); \
       
   191     __UHEAP_RESET; \
       
   192     if (err==KErrNoMemory) { failed; } }
       
   193 
       
   194 #else
       
   195 
       
   196 /**
       
   197  * Release version of macro. Just executes statement.
       
   198  */
       
   199 #define VPBK_ASSERT_NO_ALLOC(statement,failed) statement
       
   200 
       
   201 #endif
       
   202 
       
   203 #endif // VPBKDEBUG_H
       
   204 
       
   205 // End of File