voiceui/vcommand/rubydebug/rubydebug.h
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Interface of debugging utilities.
       
    15 *      %version: 1.1.3 %
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef RUBYDEBUG_H
       
    21 #define RUBYDEBUG_H
       
    22 
       
    23 #include "rubydebugcfg.h"
       
    24 
       
    25 //  INCLUDES
       
    26 #include <e32svr.h> // For RDebug
       
    27 
       
    28 #ifndef RUBY_DISABLE_FUNCTION_NAMES
       
    29     // No sense to store function name longer, than can be printed
       
    30     // 0x100 is the internal RDebug limit
       
    31     const TInt __K_RUBY_FUNCTION_NAME_LENGTH = 0x50;    
       
    32 
       
    33     // Prepares function name for printing
       
    34     #define __RUBY_PREPARE_FUNCTION_NAME \
       
    35     TBuf<__K_RUBY_FUNCTION_NAME_LENGTH> __ruby_function_name__;\
       
    36     __ruby_function_name__.Copy( TPtrC8( (TText8*)&__PRETTY_FUNCTION__ ).Left( __K_RUBY_FUNCTION_NAME_LENGTH ) ); \
       
    37 
       
    38     // Token to paste the function name into
       
    39     #define __K_RUBY_FUNCTION_NAME_TOKEN "%S "
       
    40     
       
    41     // Comma and function name
       
    42     #define __RUBY_FUNCTION_NAME __ruby_function_name__
       
    43     
       
    44     // A wrapper that prepares and supplies the function name as __ruby_function_name__
       
    45     #define __RUBY_FUNCTION_NAMED( text ) \
       
    46 	    {\
       
    47 	    __RUBY_PREPARE_FUNCTION_NAME;\
       
    48 	    text;\
       
    49 	    }
       
    50 	    
       
    51 	#define __RUBY_FUNCTION_NAME_POINTER8 (TText8*)&__PRETTY_FUNCTION__
       
    52     
       
    53 
       
    54 #else  // RUBY_DISABLE_FUNCTION_NAMES
       
    55 
       
    56     #define __RUBY_PREPARE_FUNCTION_NAME
       
    57     
       
    58     // Don't print the function name
       
    59     #define __K_RUBY_FUNCTION_NAME_TOKEN ""
       
    60     
       
    61     // exclude the whole token, with the comma
       
    62     #define __RUBY_FUNCTION_NAME KNullDesC
       
    63     
       
    64     // no wrapping
       
    65     #define __RUBY_FUNCTION_NAMED( text ) text
       
    66     
       
    67     #define __RUBY_FUNCTION_NAME_POINTER8 NULL
       
    68 
       
    69 #endif // RUBY_DISABLE_FUNCTION_NAMES
       
    70 
       
    71 // Macro for printing filename both in unicode and non-unicode builds
       
    72 
       
    73 
       
    74 #ifdef _UNICODE
       
    75 	#define __RUBY_WIDEN2(x) L ## x
       
    76 	#define __RUBY_WIDEN(x) __RUBY_WIDEN2(x)
       
    77 	#define __RUBY_DBG_FILE__ __RUBY_WIDEN(__FILE__)
       
    78 #else
       
    79 	#define __RUBY_DBG_FILE__ __FILE__
       
    80 #endif//_UNICODE
       
    81 
       
    82 
       
    83 
       
    84 // Debugging is enabled only in _DEBUG builds
       
    85 //#ifdef _DEBUG 
       
    86 
       
    87 // Select the debug output method
       
    88 #ifndef __RUBY_DEBUG_TRACES_TO_FILE
       
    89 #define RUBY_DEBUG_METHOD RDebug::Print
       
    90 #else
       
    91 #define RUBY_DEBUG_METHOD RRubyDebug::PrintToFile
       
    92 #endif // __RUBY_DEBUG_TRACES_TO_FILE
       
    93 
       
    94 //#endif // _DEBUG
       
    95 
       
    96 #if defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED)
       
    97 
       
    98 //	#define RUBY_DEBUG_BLOCK(text) \
       
    99 //  	RRubyDebug trace_trace( _S(text), _S("" ## __RUBY_DBG_FILE__) , __LINE__, EFalse ); \
       
   100 //  	CleanupReleasePushL( trace_trace )
       
   101   	
       
   102 //  	#define RUBY_DEBUG_BLOCKL(text) \
       
   103 //  	RRubyDebug trace_trace( _S(text), _S("" ## __RUBY_DBG_FILE__), __LINE__, ETrue ); \
       
   104 //  	CleanupReleasePushL( trace_trace )
       
   105 // A temporary fix to cope with builds on RVCT 530. It didn't compile with _RUBY_DBG_FILE
       
   106 	#define RUBY_DEBUG_BLOCK(text) \
       
   107   	RRubyDebug trace_trace( _S(text), _S("") , __LINE__, EFalse, __RUBY_FUNCTION_NAME_POINTER8 ); \
       
   108   	CleanupReleasePushL( trace_trace )
       
   109 
       
   110   	#define RUBY_DEBUG_BLOCKL(text) \
       
   111   	RRubyDebug trace_trace( _S(text), _S(""), __LINE__, ETrue, __RUBY_FUNCTION_NAME_POINTER8 ); \
       
   112   	CleanupReleasePushL( trace_trace )
       
   113 
       
   114 	#define RUBY_DEBUG0(text) \
       
   115 	    __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) )
       
   116 
       
   117 	#define RUBY_DEBUG1(text, p1) \
       
   118 	    __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) )
       
   119 
       
   120 	#define RUBY_DEBUG2(text, p1, p2) \
       
   121 	    __RUBY_FUNCTION_NAMED( RUBY_DEBUG_METHOD( _L("%S %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, p2, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) ) )
       
   122 
       
   123 #else // Debugging disabled
       
   124 
       
   125 	// Macros expand to nothing:
       
   126 	#define RUBY_DEBUG_BLOCK(text)
       
   127 	#define RUBY_DEBUG0(text)    
       
   128 	#define RUBY_DEBUG1(text, p1)
       
   129 	#define RUBY_DEBUG2(text, p1, p2)
       
   130 	#define RUBY_DEBUG_BLOCKL(text)
       
   131 
       
   132 #endif // defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED)
       
   133 
       
   134 #if !defined(RUBY_DISABLE_ERRORS) || defined(_DEBUG)
       
   135 	// if error messages are allowed (even for UREL)
       
   136 	#define RUBY_ERROR0(text) \
       
   137 	__RUBY_FUNCTION_NAMED( \
       
   138 	    RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\
       
   139 	)
       
   140 
       
   141 	#define RUBY_ERROR1(text, p1) \
       
   142 	__RUBY_FUNCTION_NAMED( \
       
   143 	RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\
       
   144 	)
       
   145 
       
   146 	#define RUBY_ERROR2(text, p1, p2) \
       
   147 	__RUBY_FUNCTION_NAMED( \
       
   148 	RUBY_DEBUG_METHOD( _L("%S[Error!] %S "L##text L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, p1, p2, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id()) )\
       
   149 	)
       
   150 #else
       
   151 	// error reporting disabled
       
   152 	// Macros expand to nothing:
       
   153 	#define RUBY_ERROR_BLOCK(text)
       
   154 	#define RUBY_ERROR0(text)    
       
   155 	#define RUBY_ERROR1(text, p1)
       
   156 	#define RUBY_ERROR2(text, p1, p2)
       
   157 #endif  // !defined(RUBY_DISABLE_ERRORS)
       
   158 
       
   159 #if !defined(RUBY_DISABLE_ASSERT_DEBUG) || defined(_DEBUG)
       
   160 	#define RUBY_ASSERT_DEBUG(condition, action) \
       
   161 	  __RUBY_FUNCTION_NAMED(\
       
   162 		__ASSERT_ALWAYS( condition, RUBY_DEBUG_METHOD(  _L("%S[Error!] %S [Assert failed!] "L###condition L## " [F:%s][L:%d][TId:%d]"), &__K_RUBY_HEADER, &__RUBY_FUNCTION_NAME, __RUBY_DBG_FILE__, __LINE__, TUint(RThread().Id())) ); \
       
   163 		__ASSERT_DEBUG( (condition), (action) )\
       
   164 	  );
       
   165 #else
       
   166 	// Macro expands to default:
       
   167 	#define RUBY_ASSERT_DEBUG(condition, action) __ASSERT_DEBUG(condition,action)
       
   168 #endif
       
   169 
       
   170 // Same as TRAP_IGNORE, but in case of leave, prints the leave code via RUBY_ERROR
       
   171 // Can be disabled by RUBY_DISABLE_TRAP_IGNORE or RUBY_DISABLE_ERRORS
       
   172 // If disabled, is equivalent to TRAP_IGNORE
       
   173 // @see rubydebugcfg.h
       
   174 #ifndef RUBY_DISABLE_TRAP_IGNORE 
       
   175     #define RUBY_TRAP_IGNORE( s ) \
       
   176         {\
       
   177         TRAPD( err, s );\
       
   178         if( err != KErrNone )\
       
   179             {\
       
   180             RUBY_ERROR1( "RUBY_TRAP_IGNORE leaves with [%d]", err );\
       
   181             }\
       
   182         }
       
   183 #else  // RUBY_DISABLE_TRAP_IGNORE 
       
   184     #define RUBY_TRAP_IGNORE( s ) TRAP_IGNORE( s )
       
   185 #endif  // RUBY_DISABLE_TRAP_IGNORE 
       
   186 
       
   187 // DATA TYPES
       
   188 
       
   189 // FUNCTION PROTOTYPES
       
   190 
       
   191 // FORWARD DECLARATIONS
       
   192 
       
   193 // CLASS DECLARATION
       
   194 
       
   195 /**
       
   196 *  Debug class for printing START, EXIT and LEAVE messages to RDebug in every 
       
   197 *  code block. Must be placed in the very beginning of a code block and the
       
   198 *  code block cannot leave items in the cleanup stack (like NewLC). 
       
   199 *
       
   200 *  @since Series 60 2.8
       
   201 *
       
   202 *  @note If this object is not the topmost item when a code block is exited, 
       
   203 *        E32USER-CBase 90 panic is raised (@see CleanupStack::Pop( TAny* )).
       
   204 */
       
   205 class RRubyDebug
       
   206     {
       
   207     public:
       
   208         /**
       
   209         * C++ constructor.
       
   210         * @since Series 60 2.8
       
   211         * @param aMsg Debug message.
       
   212         * @param aCalledFromL ETrue if called from RUBY_DEBUG_BLOCK_L
       
   213         */
       
   214         inline RRubyDebug( const TText* aMsg, const TText* aFileName, const TInt aLine, TBool aCalledFromL,
       
   215                            const TText8* aFunctionName = NULL );
       
   216 
       
   217         /**
       
   218         * Destructor.
       
   219         */
       
   220         inline ~RRubyDebug();
       
   221 
       
   222         /**
       
   223         * Destructor for Cleanup support. Called when a method leaves.
       
   224         */
       
   225         inline void Release();
       
   226 
       
   227         /**
       
   228         * Support for writing traces to file.
       
   229         */
       
   230         IMPORT_C static void PrintToFile( TRefByValue<const TDesC> aFmt, ... );
       
   231 
       
   232     private:
       
   233         /**
       
   234         *  Class for truncating debug messages if they are too long.
       
   235         *  @since Series 60 2.8
       
   236         */
       
   237         class TTruncateOverflow : public TDesOverflow
       
   238             {
       
   239             public: // Methods from TDesOverflow
       
   240 
       
   241                 inline void Overflow( TDes& aDes );
       
   242             };
       
   243 
       
   244     private:
       
   245         // A pointer to the debug message
       
   246         TPtrC iMsg;
       
   247         
       
   248         // A pointer to the filename where RUBY_DEBUG_BLOCK is written
       
   249         TPtrC iFileName;
       
   250         
       
   251         // Number of the line where RUBY_DEBUG_BLOCK is written
       
   252         TInt iLine;
       
   253 
       
   254 		// ETrue if we are called from RUBY_DEBUG_BLOCKL
       
   255         TBool iCalledFromL;
       
   256 
       
   257         // Flag that is set when a leave occurs
       
   258         TBool iLeave;
       
   259 
       
   260 	#ifndef RUBY_DISABLE_FUNCTION_NAMES        
       
   261         // Used only if aFunctionName is defined in constructor
       
   262         HBufC* iFunctionName;
       
   263    	#endif  // RUBY_DISABLE_FUNCTION_NAMES
       
   264         
       
   265     };
       
   266 
       
   267 #include "rubydebug.inl"
       
   268 
       
   269 #endif      // RUBYDEBUG_H
       
   270             
       
   271 // End of File