phonebookui/Phonebook2/inc/Pbk2Debug.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 debugging support.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PBK2DEBUG_H
       
    20 #define PBK2DEBUG_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <Pbk2Config.hrh>
       
    24 #include <e32std.h>
       
    25 #include <e32svr.h>
       
    26 
       
    27 // MACROS
       
    28 #ifdef _DEBUG
       
    29 
       
    30     /// Helper macro for defining debug-only test code
       
    31     #define PBK2_DEBUG_ONLY(f) f
       
    32 
       
    33      /// Helper macro for calling invariant on function entry and
       
    34      /// (normal) exit. Declare typedef SelfType as the type of
       
    35      /// the class you're using this macro in.
       
    36     #define PBK2_DEBUG_TEST_INVARIANT_ON_ENTRY_AND_EXIT \
       
    37         TPbk2DebugCallInvariantOnEntryAndExit<SelfType> \
       
    38         pbk2_debug_test_invariant(this)
       
    39 
       
    40 #else // _DEBUG
       
    41 
       
    42     /// Helper macro for defining debug-only test code (empty release version)
       
    43     #define PBK2_DEBUG_ONLY(f)
       
    44 
       
    45     /// Helper macro for calling invariant on function entry and
       
    46     /// (normal) exit. This is empty release build version.
       
    47     #define PBK2_DEBUG_TEST_INVARIANT_ON_ENTRY_AND_EXIT
       
    48 
       
    49 #endif // _DEBUG
       
    50 
       
    51 /**
       
    52  * Phonebook 2 debug printing implementation.
       
    53  *
       
    54  */
       
    55 #ifdef PBK2_ENABLE_DEBUG_PRINT
       
    56 
       
    57     // Debug logging is enabled
       
    58 
       
    59     /// Warn if this is a release build
       
    60     #ifndef __WINSCW__
       
    61     #ifndef _DEBUG
       
    62         #if defined(__VC32__)
       
    63             #pragma message("Warning: Phonebook2 debug printing is on in release build!")
       
    64         #else // __GCC32__
       
    65             #warning "Phonebook2 debug printing is on in release build!"
       
    66         #endif // __VC32__
       
    67     #endif // _DEBUG
       
    68     #endif // __WINSCW__
       
    69 
       
    70     /// Macro for defining debug-only literal strings
       
    71     #define PBK2_DEBUG_STRING(s) _L(s)
       
    72 
       
    73     #ifdef PBK2_ENABLE_DEBUG_LOGGER
       
    74 
       
    75         /// Print to log file
       
    76         #define PBK2_DEBUG_PRINT Pbk2PrintToLog
       
    77 
       
    78         #include <flogger.h>
       
    79 
       
    80         namespace {
       
    81 
       
    82         void Pbk2PrintToLog( TRefByValue<const TDesC> aFormat, ... )
       
    83             {
       
    84             _LIT( KLogDir, "Pbk2" );
       
    85             _LIT( KLogName, "Pbk2.log" );
       
    86 
       
    87             VA_LIST args;
       
    88             VA_START( args, aFormat );
       
    89             RFileLogger::WriteFormat
       
    90                 (KLogDir, KLogName, EFileLoggingModeAppend, aFormat, args);
       
    91             VA_END( args );
       
    92             }
       
    93 
       
    94         } /// namespace
       
    95 
       
    96     #else // PBK2_ENABLE_DEBUG_LOGGER
       
    97 
       
    98         /// Prints to debugger output
       
    99         #define PBK2_DEBUG_PRINT RDebug::Print
       
   100 
       
   101     #endif // PBK2_ENABLE_DEBUG_LOGGER
       
   102 
       
   103 #else // PBK2_ENABLE_DEBUG_PRINT
       
   104 
       
   105     /// Dummy struct for checking that all PBK2_DEBUG_PRINT's define string
       
   106     /// literals using space-saving PBK2_DEBUG_STRING.
       
   107     struct TPbk2EmptyDebugString { };
       
   108 
       
   109     /// Macro for defining debug-only literal strings (empty release version)
       
   110     #define PBK2_DEBUG_STRING(s) TPbk2EmptyDebugString()
       
   111 
       
   112     /// Empty debug print function for release builds.
       
   113     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString)
       
   114         {
       
   115         }
       
   116 
       
   117     /// Empty debug print function for release builds.
       
   118     template<class T1>
       
   119     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1)
       
   120         {
       
   121         }
       
   122 
       
   123     /// Empty debug print function for release builds.
       
   124     template<class T1,class T2>
       
   125     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2)
       
   126         {
       
   127         }
       
   128 
       
   129     /// Empty debug print function for release builds.
       
   130     template<class T1,class T2,class T3>
       
   131     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3)
       
   132         {
       
   133         }
       
   134 
       
   135     /// Empty debug print function for release builds.
       
   136     template<class T1,class T2,class T3,class T4>
       
   137     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3,T4)
       
   138         {
       
   139         }
       
   140 
       
   141     /// Empty debug print function for release builds.
       
   142     template<class T1,class T2,class T3,class T4,class T5>
       
   143     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3,T4,T5)
       
   144         {
       
   145         }
       
   146 
       
   147     /// Empty debug print function for release builds.
       
   148     template<class T1,class T2,class T3,class T4,class T5,class T6>
       
   149     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3,T4,T5,T6)
       
   150         {
       
   151         }
       
   152 
       
   153     /// Empty debug print function for release builds.
       
   154     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
       
   155     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3,T4,T5,T6,T7)
       
   156         {
       
   157         }
       
   158 
       
   159     /// Empty debug print function for release builds.
       
   160     template<class T1,class T2,class T3,class T4,class T5,class T6,class T7,class T8>
       
   161     inline void PBK2_DEBUG_PRINT(TPbk2EmptyDebugString,T1,T2,T3,T4,T5,T6,T7,T8)
       
   162         {
       
   163         }
       
   164 
       
   165 #endif // PBK2_ENABLE_DEBUG_PRINT
       
   166 
       
   167 #ifdef _DEBUG
       
   168 
       
   169     /// Asserts and checks that statement doesn't allocate any memory.
       
   170     /// If allocation happens evaluates failed.
       
   171     #define PBK2_ASSERT_NO_ALLOC(statement,failed) \
       
   172         { __UHEAP_FAILNEXT(1); \
       
   173         TRAPD(err, statement); \
       
   174         __UHEAP_RESET; \
       
   175         if (err==KErrNoMemory) { failed; } }
       
   176 
       
   177 #else // _DEBUG
       
   178 
       
   179     /// Release version of macro. Just executes the statement.
       
   180     #define PBK2_ASSERT_NO_ALLOC(statement,failed) statement
       
   181 
       
   182 #endif // _DEBUG
       
   183 
       
   184 
       
   185 // CLASS DECLARATION
       
   186 
       
   187 /**
       
   188  * Helper class for calling class invariant automatically on function
       
   189  * entry and exit.
       
   190  */
       
   191 template<class T>
       
   192 class TPbk2DebugCallInvariantOnEntryAndExit
       
   193     {
       
   194     public: // Construction and destruction
       
   195 
       
   196         /**
       
   197          * Constructor.
       
   198          *
       
   199          * @param aObj  The object.
       
   200          */
       
   201         inline TPbk2DebugCallInvariantOnEntryAndExit( const T* aObj ):
       
   202                 iObj( aObj )
       
   203             {
       
   204             iObj->__DbgTestInvariant();
       
   205             }
       
   206 
       
   207         /**
       
   208          * Destructor.
       
   209          */
       
   210         inline ~TPbk2DebugCallInvariantOnEntryAndExit()
       
   211             {
       
   212             iObj->__DbgTestInvariant();
       
   213             }
       
   214 
       
   215     private: // Data
       
   216         /// Ref: The object
       
   217         const T* iObj;
       
   218     };
       
   219 
       
   220 #endif // PBK2DEBUG_H
       
   221 
       
   222 // End of File