calendarui/inc/calendarui_debug.h
changeset 0 f979ecb2b13e
child 18 c198609911f9
child 65 12af337248b1
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2009 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: Calendar debug file.
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 *
       
    20 **/
       
    21 
       
    22 #include "debug.h"
       
    23 
       
    24 #define RD_CALENDAR_PREVIEW
       
    25 
       
    26 #ifndef PIM_TRACE_H
       
    27 #define PIM_TRACE_H
       
    28 
       
    29 #if defined (_DEBUG) || defined (_PIM_FILE_LOG) || defined (_DISPLAY_WARNINGS) 
       
    30     //Includes
       
    31     #include <e32base.h>
       
    32     #include <e32std.h>
       
    33     #include <flogger.h>
       
    34     #include <e32svr.h>
       
    35     #include <f32file.h>
       
    36     #include <AknGlobalConfirmationQuery.h>
       
    37     const TInt KMaxLogLineLength = 512;
       
    38 #endif
       
    39 
       
    40 /**
       
    41 * Define our own trap and assert macros to prevent compiler warnings.
       
    42 */
       
    43 #if defined (_DISPLAY_WARNINGS)
       
    44     _LIT( KWarningFormat, " error %d trapped %S line %d");
       
    45     inline void DisplayWarningNote( TInt aError, const TDesC8& aFile, TInt aWarningNote )
       
    46         {
       
    47         if ( aError )
       
    48             {
       
    49             TRAP_IGNORE(
       
    50             CAknGlobalConfirmationQuery* cq = CAknGlobalConfirmationQuery::NewL();
       
    51             CleanupStack::PushL( cq );
       
    52             
       
    53             TBuf<KMaxLogLineLength> text;
       
    54             TBuf<128> fileName;
       
    55             fileName.Copy( aFile );
       
    56             text.Format( KWarningFormat, aError, &fileName, aWarningNote );
       
    57             
       
    58             TRequestStatus stat = KRequestPending;
       
    59             cq->ShowConfirmationQueryL( stat, text, R_AVKON_SOFTKEYS_YES_NO );
       
    60             User::WaitForRequest( stat );
       
    61             
       
    62             CleanupStack::PopAndDestroy( cq );
       
    63             );
       
    64             }       
       
    65         }
       
    66 
       
    67     inline void DisplayWarningNote( const TDesC& aNote )
       
    68         {
       
    69         TRAP_IGNORE(
       
    70             CAknGlobalConfirmationQuery* cq = CAknGlobalConfirmationQuery::NewL();
       
    71             CleanupStack::PushL( cq );
       
    72            
       
    73             
       
    74             TRequestStatus stat = KRequestPending;
       
    75             cq->ShowConfirmationQueryL( stat, aNote, R_AVKON_SOFTKEYS_YES_NO );
       
    76             User::WaitForRequest( stat );
       
    77             
       
    78             CleanupStack::PopAndDestroy( cq );
       
    79             );
       
    80         }
       
    81         
       
    82     #undef TRAP_INSTRUMENTATION_LEAVE
       
    83     #define TRAP_INSTRUMENTATION_LEAVE(aResult) DisplayWarningNote( aResult,TPtrC8( ( TText8* )__FILE__), __LINE__);
       
    84 
       
    85     #define PIM_TRAP_HANDLE( _err, _s ) \
       
    86     { \
       
    87         TRAP( _err, _s; ); \
       
    88         DisplayWarningNote( _err,TPtrC8( ( TText8* )__FILE__),__LINE__ ); \
       
    89     }
       
    90     #define PIM_TRAPD_HANDLE( _s ) \
       
    91     { \
       
    92         TRAPD( _err, _s; ); \
       
    93         DisplayWarningNote( _err, TPtrC8( ( TText8* )__FILE__), __LINE__ ); \
       
    94     }
       
    95     #define WARNING_NOTE( _s ) DisplayWarningNote( _s );
       
    96     
       
    97 #elif defined( _DEBUG ) 
       
    98     #define PIM_TRAP_HANDLE( _err, _s ) \
       
    99     { \
       
   100         TRAP( _err, _s; ); \
       
   101         ASSERT( !_err ); \
       
   102     }
       
   103     #define PIM_TRAPD_HANDLE( _s ) \
       
   104     { \
       
   105         TRAPD( _err, _s; ); \
       
   106         ASSERT( !_err ); \
       
   107     }
       
   108     #define WARNING_NOTE( _s )
       
   109     #define PIM_ASSERT( _s ) \
       
   110     { \
       
   111         const TInt _err = _s; \
       
   112         if( _err ) RDebug::Print( _L("### PIM_ASSERT: %d"), _err ); \
       
   113         ASSERT( !_err ); \
       
   114     }
       
   115 #else 
       
   116 // urel
       
   117     #define PIM_TRAP_HANDLE( _err, _s )   TRAP_IGNORE( _s; );
       
   118     #define PIM_TRAPD_HANDLE( _s )  TRAP_IGNORE( _s; );
       
   119     #define WARNING_NOTE( _s )
       
   120     #define PIM_ASSERT( _s )  _s;
       
   121 #endif // _DEBUG
       
   122 
       
   123 #if defined (_DEBUG) || defined (_PIM_FILE_LOG) 
       
   124     
       
   125    
       
   126     /********************************************************************************************************************/
       
   127 
       
   128     // MMP MACROS
       
   129     #if defined( TRACE_MODULE_AIAGENDAPLUGINENGINE )
       
   130         _LIT8( KModuleName8, "AIAgendaPluginEngine" );
       
   131     #elif defined( TRACE_MODULE_CALENDAR ) 
       
   132         _LIT8( KModuleName8, "calendar" );
       
   133     #elif defined( TRACE_MODULE_CALENGLOBALDATA ) 
       
   134         _LIT8( KModuleName8, "CalenGlobalData" );
       
   135     #elif defined( TRACE_MODULE_CALENCOMMONUI ) 
       
   136         _LIT8( KModuleName8, "CalenCommonUi" );
       
   137     #elif defined( TRACE_MODULE_CALENDEFAULTEDITORS ) 
       
   138         _LIT8( KModuleName8, "CalenDefaultEditors" );
       
   139     #elif defined( TRACE_MODULE_CALENLUNAR ) 
       
   140         _LIT8( KModuleName8, "CalenLunar" );
       
   141     #elif defined( TRACE_MODULE_CALENLUNARPLUGIN ) 
       
   142         _LIT8( KModuleName8, "CalenLunarPlugin" );
       
   143     #elif defined( TRACE_MODULE_CALENTHAIPLUGIN ) 
       
   144         _LIT8( KModuleName8, "CalenThaiPlugin" );
       
   145     #elif defined( TRACE_MODULE_CALENSVR ) 
       
   146         _LIT8( KModuleName8, "CalenSvr" );
       
   147     #elif defined( TRACE_MODULE_CALENSVRCLIENT ) 
       
   148         _LIT8( KModuleName8, "CalenSvrClient" );
       
   149     #else // default
       
   150         _LIT8( KModuleName8, "CalendarUI" );
       
   151     #endif
       
   152 
       
   153     // traces
       
   154     // [module_name]_ENTRY_POINT;[thread_id];[function_name];[filename]:[line_number];
       
   155     _LIT8( KFuncEntryFormat8, ";%S_ENTRY_POINT;%d;%S;%S:%d;");
       
   156     // [module_name]_EXIT_POINT;[thread_id];[function_name];[filename]:[line_number];
       
   157     _LIT8( KFuncExitFormat8,  ";%S_EXIT_POINT;%d;%S;%S:%d;");
       
   158     
       
   159     /********************************************************************************************************************/
       
   160     NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
       
   161         {
       
   162         public:
       
   163             void Overflow(TDes8& /*aDes*/) {}
       
   164         };
       
   165 
       
   166     //Trace macro 8bit
       
   167     // Disable lint warning of function having a variable number of
       
   168     //  arguments 
       
   169     //lint -esym( 960, 69 )
       
   170     inline void TraceDebugPrint( TRefByValue<const TDesC8> aFmt, ...) 
       
   171         {
       
   172         VA_LIST list;
       
   173         
       
   174         // Disabled  lint warning of comma operator 
       
   175         //lint -esym( 960, 42 )
       
   176         VA_START( list, aFmt ); 
       
   177         
       
   178         TOverflowTruncate8 overflow;
       
   179         TBuf8<KMaxLogLineLength> buf8;
       
   180         buf8.AppendFormatList( aFmt, list, &overflow );
       
   181         TBuf16<KMaxLogLineLength> buf16( buf8.Length() );
       
   182         buf16.Copy( buf8 );
       
   183         TRefByValue<const TDesC> tmpFmt( _L("%S") );
       
   184  #if defined (_PIM_FILE_LOG)  
       
   185         _LIT( KLogDir, "CalenUi");
       
   186         _LIT( KLogDir2, "c://CalenUi");
       
   187         _LIT( KLogFile, "log.txt");
       
   188         _LIT( KDir, "c://logs//CalenUi" );
       
   189         _LIT( KDir2, "c://logs//CalenUi" );
       
   190         
       
   191         RFs fs;
       
   192         fs.Connect();
       
   193         fs.MkDirAll( KDir );
       
   194         
       
   195         RFileLogger fileLogger;
       
   196         fileLogger.Connect();
       
   197         fileLogger.CreateLog( KLogDir, KLogFile, EFileLoggingModeAppend );
       
   198         fileLogger.SetDateAndTime( EFalse, ETrue );
       
   199         fileLogger.WriteFormat( tmpFmt, &buf16 );
       
   200         fileLogger.CloseLog();
       
   201         fileLogger.Close();
       
   202 
       
   203         fs.MkDirAll( KDir2 );
       
   204         
       
   205         RFileLogger fileLogger2;
       
   206         fileLogger2.Connect();
       
   207         fileLogger2.CreateLog( KLogDir2, KLogFile, EFileLoggingModeAppend );
       
   208         fileLogger2.SetDateAndTime( EFalse, ETrue );
       
   209         fileLogger2.WriteFormat( tmpFmt, &buf16 );
       
   210         fileLogger2.CloseLog();
       
   211         fileLogger2.Close();
       
   212         fs.Close();
       
   213         
       
   214 #else      
       
   215         RDebug::Print( tmpFmt, &buf16 );
       
   216 #endif
       
   217         }
       
   218         
       
   219     _LIT8( KWarningFormat2, " error %d trapped line %d");
       
   220     inline void WriteTrapInfo( TInt aError, TInt aWarningNote )
       
   221         {
       
   222         if ( aError )
       
   223             {    
       
   224             TBuf8<128> text;
       
   225             text.Format( KWarningFormat2, aError, aWarningNote );
       
   226             
       
   227             TraceDebugPrint(text);
       
   228             }       
       
   229         }
       
   230         
       
   231         
       
   232     #undef TRAP_INSTRUMENTATION_LEAVE
       
   233     #define TRAP_INSTRUMENTATION_LEAVE(aResult) WriteTrapInfo( aResult, __LINE__);
       
   234         
       
   235     /********************************************************************************************************************/
       
   236     //Debug print
       
   237     #ifdef TRACE_ENTRY_EXIT_POINT // MACRO IN MMP FILE
       
   238         #ifdef __ARMCC__
       
   239             #define TRACE_FUNC_ENTRY_DEBUG_PRINT                                                                \
       
   240             {                                                                                                   \
       
   241                 const TUint threadId( RThread().Id() );                                                         \
       
   242                 TPtrC8 ptr8File( (TUint8*)__MODULE__ );                                                         \
       
   243                 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ );                                                  \
       
   244                 TraceDebugPrint( KFuncEntryFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ );    \
       
   245             }
       
   246             #define TRACE_FUNC_EXIT_DEBUG_PRINT                                                                 \
       
   247             {                                                                                                   \
       
   248                 const TUint threadId( RThread().Id() );                                                         \
       
   249                 TPtrC8 ptr8File( (TUint8*)__MODULE__ );                                                         \
       
   250                 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ );                                                  \
       
   251                 TraceDebugPrint( KFuncExitFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ );     \
       
   252             }
       
   253         #else // __WINS__
       
   254             #define TRACE_FUNC_ENTRY_DEBUG_PRINT                                                                \
       
   255             {                                                                                                   \
       
   256                 const TUint threadId( RThread().Id() );                                                         \
       
   257                 TPtrC8 ptr8File( (TUint8*)__FILE__ );                                                           \
       
   258                 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ );                                                  \
       
   259                 TraceDebugPrint( KFuncEntryFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ );    \
       
   260             }
       
   261             #define TRACE_FUNC_EXIT_DEBUG_PRINT                                                                 \
       
   262             {                                                                                                   \
       
   263                 const TUint threadId( RThread().Id() );                                                         \
       
   264                 TPtrC8 ptr8File( (TUint8*)__FILE__ );                                                           \
       
   265                 TPtrC8 ptr8PF( (TUint8*)__PRETTY_FUNCTION__ );                                                  \
       
   266                 TraceDebugPrint( KFuncExitFormat8, &KModuleName8, threadId, &ptr8PF, &ptr8File, __LINE__ );     \
       
   267             }
       
   268         #endif
       
   269     #endif
       
   270 
       
   271     /********************************************************************************************************************/
       
   272     //Check if trace should be activated 
       
   273     #ifdef TRACE_ENTRY_EXIT_POINT // MACRO IN MMP FILE
       
   274         #define TRACE_ENTRY_POINT TRACE_FUNC_ENTRY_DEBUG_PRINT
       
   275         #define TRACE_EXIT_POINT  TRACE_FUNC_EXIT_DEBUG_PRINT
       
   276     #else
       
   277         #define TRACE_ENTRY_POINT
       
   278         #define TRACE_EXIT_POINT
       
   279     #endif
       
   280     
       
   281 #else 
       
   282     #define TRACE_ENTRY_POINT
       
   283     #define TRACE_EXIT_POINT
       
   284 
       
   285 #endif // defined (_DEBUG) || defined (_PIM_FILE_LOG) 
       
   286 
       
   287 #endif // PIM_TRACE_H