wvuing/Inc/LayoutDebugPrint.h
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Layout debug print definitions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /*
       
    20 *
       
    21 *  Description:
       
    22 *
       
    23 *     Logging tools. Uniforms style to write debug data to
       
    24 *     screen using RDebug or to a file with RFileLogger.
       
    25 *
       
    26 *     Usage:
       
    27 *     1.Configuring:
       
    28 *
       
    29 *       Logging and debug printing is configured with following macros
       
    30 *           LAYOUT_ENABLE_DEBUG_PRINT         (defining this enables debug printing)
       
    31 *           LAYOUT_DEBUG_OUTPUT_TO_FILE       (now debug printing goes to file)
       
    32 *           LAYOUT_DEBUG_FILENAME "Some.log"  (file to store debug log)
       
    33 *
       
    34 *       Debug printing can be configured on project level by defining desired
       
    35 *       macros in .mmp file like this
       
    36 *           //enable file logging
       
    37 *           MACRO LAYOUT_ENABLE_DEBUG_PRINT
       
    38 *           MACRO LAYOUT_DEBUG_OUTPUT_TO_FILE
       
    39 *
       
    40 *       You may also automate the debug printing to follow current build
       
    41 *       variant like this:
       
    42 *           #ifdef _DEBUG
       
    43 *           MACRO LAYOUT_ENABLE_DEBUG_PRINT
       
    44 *           #endif // _DEBUG
       
    45 *
       
    46 *       The file to write debug log needs to be defined in file level.
       
    47 *       (Defining it in mmp file causes errors to build procedure..)
       
    48 *           #define LAYOUT_DEBUG_FILENAME "Example.log"
       
    49 *
       
    50 *       When using debug printing to file, flogger.lib needs to be added in
       
    51 *       mmp file
       
    52 *           LIBRARY  flogger.lib
       
    53 *       and following directory must be manually done before loggin
       
    54 *       (no directory, not logs)  Epoc32\Wins\c\logs\LAYOUT\
       
    55 *
       
    56 *
       
    57 *     2.Printing:
       
    58 *
       
    59 *       // normal string                                  output:
       
    60 *       LAYOUT_DP( D_LAYOUT_LIT("Some text.") );                 >> LAYOUT: Some text.
       
    61 *       LAYOUT_DP( D_PLAIN_LIT("Some text.") );               >> Some text.
       
    62 *       LAYOUT_DP_TXT("Some text.");                          >> LAYOUT: Some text.
       
    63 *
       
    64 *       // string with variables
       
    65 *       TInt index( 99 );
       
    66 *       _LIT( KExample, "Example" );
       
    67 *       LAYOUT_DP( D_LAYOUT_LIT("Some text: %d"), 100 );         >> LAYOUT: Some text: 100
       
    68 *       LAYOUT_DP( D_LAYOUT_LIT("Some text: %d"), index );       >> LAYOUT: Some text: 99
       
    69 *       LAYOUT_DP( D_LAYOUT_LIT("Some text: %S"), &KExample );   >> LAYOUT: Some text: Example
       
    70 *
       
    71 *       LAYOUT_DP( D_PLAIN_LIT("Some text: %d"), 100 );       >> Some text: 100
       
    72 *       LAYOUT_DP( D_PLAIN_LIT("Some text: %d"), index );     >> Some text: 99
       
    73 *       LAYOUT_DP( D_PLAIN_LIT("Some text: %S"), &KExample ); >> Some text: Example
       
    74 *
       
    75 *
       
    76 *     3.Known issues:
       
    77 *
       
    78 *       - If you use macros from .mmp file remember to abld makefile <target> to
       
    79 *         change flags from project.
       
    80 *       - In statements like LAYOUT_DP( D_LAYOUT_LIT("Some text: %S"), &KExample );
       
    81 *         parameters causes still some code to generated in release builds.
       
    82 *         Propably it is best to #ifdef all debugprint blocks
       
    83 *         with LAYOUT_ENABLE_DEBUG_PRINT statement.
       
    84 *
       
    85 * ============================================================================
       
    86 */
       
    87 
       
    88 
       
    89 #ifndef __LAYOUTDEBUGPRINT_H__
       
    90 #define __LAYOUTDEBUGPRINT_H__
       
    91 
       
    92 // Debug logging is enabled, you may enable debug printing in release builds also
       
    93 #ifdef LAYOUT_ENABLE_DEBUG_PRINT
       
    94 
       
    95 // no include files if no debug printing --> faster compile time
       
    96 // INCLUDES
       
    97 #include <e32std.h>
       
    98 #include <e32svr.h>
       
    99 #include <flogger.h>
       
   100 
       
   101 #ifndef _DEBUG
       
   102 // warn in release build!!
       
   103 #if defined(__VC32__)
       
   104 #pragma message( "Warning: LAYOUT debug printing is on in release build!" ) // CSI: 68 # Warning for rel builds
       
   105 #else // __GCC32__
       
   106 #warning "LAYOUT debug printing is on in release build!"
       
   107 #endif // __VC32__
       
   108 #endif
       
   109 
       
   110 /**
       
   111  * Depending if the build is UNICODE or not, define the
       
   112  * helper macros that insert LAYOUT prefix.
       
   113  */
       
   114 #ifdef _UNICODE
       
   115 #ifndef LAYOUT_DEBUG_OUTPUT_TO_FILE
       
   116 #define LAYOUT_TOKEN_PASTING( s ) L##s
       
   117 #define LAYOUT_TO_UNICODE( s ) LAYOUT_TOKEN_PASTING( s )
       
   118 #define LAYOUT_DEBUG_STR( m ) LAYOUT_TO_UNICODE( "LAYOUT: " ) L##m
       
   119 #else
       
   120 #define LAYOUT_TOKEN_PASTING( s ) L##s
       
   121 #define LAYOUT_TO_UNICODE( s ) LAYOUT_TOKEN_PASTING( s )
       
   122 #define LAYOUT_DEBUG_STR( m ) L##m
       
   123 #endif
       
   124 #else
       
   125 #define LAYOUT_DEBUG_STR "LAYOUT: "
       
   126 #endif // _UNICODE
       
   127 
       
   128 
       
   129 /**
       
   130  * Helper macro for defining debug strings with plain debug text.
       
   131  */
       
   132 #define D_LPLAIN_LIT( s ) _L( s )   // CSI: 78 # Debug print
       
   133 
       
   134 
       
   135 /**
       
   136  * Helper macro for defining debug strings with "LAYOUT:" prefix.
       
   137  */
       
   138 #define D_LAYOUT_LIT( s ) TPtrC( ( const TText * ) LAYOUT_DEBUG_STR( s ) )
       
   139 
       
   140 #ifdef LAYOUT_DEBUG_OUTPUT_TO_FILE
       
   141 
       
   142 /**
       
   143  * Method to handle file writing
       
   144  */
       
   145 inline void LAYOUTDebugWriteFormat( TRefByValue< const TDesC > aFmt, ... )
       
   146     {
       
   147     _LIT( KDir, "Layout" );
       
   148 #ifdef LAYOUT_DEBUG_FILENAME
       
   149     const static TLitC < sizeof( LAYOUT_DEBUG_FILENAME ) > KName = {
       
   150         sizeof( LAYOUT_DEBUG_FILENAME ) - 1, LAYOUT_TO_UNICODE(
       
   151             LAYOUT_DEBUG_FILENAME )
       
   152         };
       
   153 #else
       
   154     _LIT( KName, "LayoutDebug.log" );
       
   155 #endif // LAYOUT_DEBUG_FILENAME
       
   156 
       
   157     // take the ellipsis parameters
       
   158     VA_LIST args;
       
   159     VA_START( args, aFmt );
       
   160     RFileLogger::WriteFormat( KDir, KName, EFileLoggingModeAppend,
       
   161                               aFmt, args );
       
   162     VA_END( args );
       
   163     }
       
   164 
       
   165 /**
       
   166  * Actual debug printters.
       
   167  * Output to log file.
       
   168  */
       
   169 #define LAYOUT_DP LAYOUTDebugWriteFormat
       
   170 #define LAYOUT_DP_TXT( s ) LAYOUTDebugWriteFormat( D_LAYOUT_LIT( s ) )
       
   171 
       
   172 
       
   173 
       
   174 #else
       
   175 /**
       
   176  * Actual debug printters.
       
   177  * Output to debugger output.
       
   178  */
       
   179 #define LAYOUT_DP RDebug::Print
       
   180 #define LAYOUT_DP_TXT( s ) RDebug::Print( D_LAYOUT_LIT( s ) )
       
   181 #endif
       
   182 
       
   183 
       
   184 #else   //LAYOUT_ENABLE_DEBUG_PRINT
       
   185 
       
   186 /**
       
   187  *
       
   188  * Empty implementations for non-debug printing build versions.
       
   189  *
       
   190  */
       
   191 
       
   192 /**
       
   193  * Dummy struct for checking that all LAYOUT_DP's define string
       
   194  * literals using space-saving D_PLAIN_LIT or D_LAYOUT_LIT.
       
   195  */
       
   196 struct TLAYOUTEmptyDebugString { };
       
   197 
       
   198 /**
       
   199  * Macro for defining debug-only literal strings (empty release version)
       
   200  */
       
   201 #define D_LPLAIN_LIT( s ) TLAYOUTEmptyDebugString()
       
   202 
       
   203 /**
       
   204  * Macro for defining debug-only literal strings (empty release version)
       
   205  */
       
   206 #define D_LAYOUT_LIT( s ) TLAYOUTEmptyDebugString()
       
   207 
       
   208 /**
       
   209  * Macro for empty debug print function
       
   210  */
       
   211 #define LAYOUT_DP_TXT( s ) LAYOUT_DP( D_LAYOUT_LIT( s ) )
       
   212 
       
   213 
       
   214 /// Empty debug print function for release builds.
       
   215 inline void LAYOUT_DP( TLAYOUTEmptyDebugString )
       
   216     {
       
   217     }
       
   218 
       
   219 template< class T1 >
       
   220 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1 )
       
   221     {
       
   222     }
       
   223 
       
   224 template< class T1, class T2 >
       
   225 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2 )
       
   226     {
       
   227     }
       
   228 
       
   229 template< class T1, class T2, class T3 >
       
   230 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3 )
       
   231     {
       
   232     }
       
   233 
       
   234 template< class T1, class T2, class T3, class T4 >
       
   235 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4 )
       
   236     {
       
   237     }
       
   238 
       
   239 template< class T1, class T2, class T3, class T4, class T5 >
       
   240 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5 )
       
   241     {
       
   242     }
       
   243 
       
   244 template< class T1, class T2, class T3, class T4, class T5, class T6 >
       
   245 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6 )
       
   246     {
       
   247     }
       
   248 
       
   249 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
       
   250 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6, T7 )
       
   251     {
       
   252     }
       
   253 
       
   254 template < class T1, class T2, class T3, class T4, class T5, class T6, class T7,
       
   255 class T8 >
       
   256 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8 )
       
   257     {
       
   258     }
       
   259 
       
   260 template < class T1, class T2, class T3, class T4, class T5, class T6, class T7,
       
   261 class T8, class T9 >
       
   262 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, T9 )
       
   263     {
       
   264     }
       
   265 
       
   266 template < class T1, class T2, class T3, class T4, class T5, class T6, class T7,
       
   267 class T8, class T9, class T10 >
       
   268 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, T9,
       
   269                        T10 )
       
   270     {
       
   271     }
       
   272 
       
   273 template < class T1, class T2, class T3, class T4, class T5, class T6, class T7,
       
   274 class T8, class T9, class T10, class T11 >
       
   275 inline void LAYOUT_DP( TLAYOUTEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, T9,
       
   276                        T10, T11 )
       
   277     {
       
   278     }
       
   279 
       
   280 #endif  // LAYOUT_ENABLE_DEBUG_PRINT
       
   281 
       
   282 /* Some general wrappers to LAYOUT_DP for convenience.
       
   283  *
       
   284  * Since these just wrap LAYOUT_DP, they work transparently: the macros write
       
   285  * stuff to debug output or to a file, whichever you are using,
       
   286  * you don't have to care.
       
   287  *
       
   288  * Since LAYOUT_DP is either defined or empty inline, these won't
       
   289  * matter in either build (no, there is no noticeable penalty in compile time)
       
   290  *
       
   291  * There are three types of wrappers, output format is
       
   292  *
       
   293  * "filename:linenumber method - enter" when entering function
       
   294  * "filename:linenumber method - message" when inside function
       
   295  * "filename:linenumber method - done" when exiting function
       
   296  *
       
   297  * Example:
       
   298  * TInt CSomeClass::SomeMethod()
       
   299  * {
       
   300  *      LAYOUT_DP_FUNC_ENTER("SomeMethod");
       
   301  *
       
   302  *      TInt i = 41;
       
   303  *
       
   304  *      LAYOUT_DP_FUNC_DP("SomeMethod", "Doing intensive calculations");
       
   305  *
       
   306  *      i++;
       
   307  *
       
   308  *      LAYOUT_DP_FUNC_DONE("SomeMethod");
       
   309  *  }
       
   310  *
       
   311  * You have to provide the method name yourself since the __FUNCTION__
       
   312  * preprocessor macro is not understood.
       
   313  */
       
   314 
       
   315 #include "ChatDebugMacros.h"	// WFILE etc.
       
   316 
       
   317 // when entering a function
       
   318 #define LAYOUT_DP_FUNC_ENTER( method ) \
       
   319     LAYOUT_DP( D_LAYOUT_LIT( "%s:%d %s - enter" ), __WFILE__, __LINE__, L ## method );
       
   320 
       
   321 // debug print
       
   322 #define LAYOUT_DP_FUNC_DP( method,msg ) \
       
   323     LAYOUT_DP( D_LAYOUT_LIT( "%s:%d %s - %s" ), __WFILE__, __LINE__, L ## method, L ## msg );
       
   324 
       
   325 // when exiting a function
       
   326 #define LAYOUT_DP_FUNC_DONE( method ) \
       
   327     LAYOUT_DP( D_LAYOUT_LIT( "%s:%d %s - done" ), __WFILE__, __LINE__, L ## method );
       
   328 
       
   329 // Helpper Method to write rect's value
       
   330 #ifdef LAYOUT_ENABLE_DEBUG_PRINT
       
   331 #define LAYOUT_DP_RECT( name, rect ) \
       
   332     LAYOUT_DP( \
       
   333                D_LAYOUT_LIT( "%s: %d,%d;%d,%d (%dx%d)" ), \
       
   334                L ## name, \
       
   335                rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY, \
       
   336                rect.Width(), rect.Height() );
       
   337 
       
   338 #else //LAYOUT_ENABLE_DEBUG_PRINT
       
   339 #define LAYOUT_DP_RECT( name, rect ) \
       
   340     LAYOUT_DP_TXT( "LAYOUT_DP_RECT" );
       
   341 
       
   342 #endif //LAYOUT_ENABLE_DEBUG_PRINT
       
   343 
       
   344 #endif  // __LAYOUTDEBUGPRINT_H__
       
   345 
       
   346 
       
   347 //  End of File