taskswitcher/teleportui/trace/hglogutils.h
changeset 4 4d54b72983ae
parent 3 fb3763350a08
child 5 c743ef5928ba
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
     1 /*
       
     2 * ==============================================================================
       
     3 *  Name        : hglogutils.h
       
     4 *  Part of     : Teleport / Teleport UI
       
     5 *  Description : Logging behavior
       
     6 *  Version     : %version: 3 %
       
     7 *
       
     8 *  Copyright © 2008 Nokia. All rights reserved.
       
     9 *  This material, including documentation and any related 
       
    10 *  computer programs, is protected by copyright controlled by 
       
    11 *  Nokia. All rights are reserved. Copying, including 
       
    12 *  reproducing, storing, adapting or translating, any 
       
    13 *  or all of this material requires the prior written consent of 
       
    14 *  Nokia. This material also contains confidential 
       
    15 *  information which may not be disclosed to others without the 
       
    16 *  prior written consent of Nokia.
       
    17 * ==============================================================================
       
    18 */
       
    19 
       
    20 #ifndef HGLOGUTILS_H
       
    21 #define HGLOGUTILS_H
       
    22 
       
    23 /**
       
    24  * NOTE: This file contains the logic related to logging. Change only if you
       
    25  * know what you're doing.
       
    26  */
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 
       
    34 
       
    35 
       
    36 
       
    37 #ifdef _DEBUG
       
    38 
       
    39 #include <e32std.h>
       
    40 #include <e32debug.h>
       
    41 
       
    42 static const TUint HGLOGERR   = 2;  /**< Used to create an error message */
       
    43 
       
    44 // These macros are real macros, that should be used. For temporary purposes, these
       
    45 // are left out and the logging is done by simple entry logging
       
    46 #define _HGLOG_UNCONTROLLED_INPUT_MSG  L"%s%d[%x:%x:%x]>%s UNCONTROLLED ENTRY!"
       
    47 #define _HGLOG_MULTIPLE_ENTRY_MSG      L"%s%d[%x:%x:%x]%s  ADDITIONAL ENTRY!"
       
    48 #define _HGLOG_UNCONTROLLER_EXIT_MSG   L"%s%d[%x:%x:%x]<%s UNCONTROLLED EXIT!"
       
    49 #define _HGLOG_MULTIPLE_EXIT_MSG       L"%s%d[%x:%x:%x]%s  ADDITIONAL EXIT!"
       
    50 #define _HGLOG_TRAP_HARNESS_ENTRY      L"_D%d[%x:%x:%x]TraceFramework: Entering trap harness"
       
    51 #define _HGLOG_TRAP_HARNESS_EXIT       L"_D%d[%x:%x:%x]TraceFramework: Exiting trap harness"
       
    52 #define _HGLOG_TRAP_HARNESS_LEAVE      L"_D%d[%x:%x:%x]TraceFramework: ---------- LEAVE OCCURRED !!! ---------- "
       
    53 #define _HGLOG_API_PREFIX              L"_A"
       
    54 #define _HGLOG_LOCAL_PREFIX            L"_L"
       
    55 
       
    56 /**
       
    57 * @file 
       
    58 * trace_utils.h contains definitions needed for advanced tracing features.
       
    59 * Tracing can be customized using the following compile time flags:
       
    60 * - <b>_DEBUG</b>
       
    61 *   - With this flag undefined, all traces are disabled
       
    62 * - <b>__KERNEL_MODE__</b>
       
    63 *   - if kernel mode flag is defined, kernel macro variants are used (no unicode or shared heap related stuff, faster)
       
    64 * - <b>DISABLE_SYNTAX_CHECK</b>
       
    65 *   - If this flag is defined, runtime syntax checking features are disabled from traces
       
    66 */
       
    67 #ifndef DISABLE_SYNTAX_CHECK
       
    68     #define _MARK_ENTRY() _dc.inOk=ETrue
       
    69     #define _DOINCHK() _dc.DoInChk()
       
    70     #define _CHK_MULTIIN() _dc.ChkMultiIn()
       
    71     #define _CHK_MULTIOUT() _dc.ChkMultiOut()
       
    72     #define _MARK_EXIT() _dc.outOk=ETrue
       
    73 #else
       
    74     #define _MARK_ENTRY()
       
    75     #define _DOINCHK()
       
    76     #define _CHK_MULTIIN()
       
    77     #define _CHK_MULTIOUT()
       
    78     #define _MARK_EXIT()
       
    79 #endif // DISABLE_SYNTAX_CHECK
       
    80     
       
    81 /** For tracing */
       
    82 #ifdef _HGLOG_RDEBUG
       
    83     #define _IT(a) (TPtrC((const TText *)(a)))
       
    84     #define _HGLOGPRINTER RDebug::Print        
       
    85         
       
    86 /** For filedebug */
       
    87 #else   // _HGLOG_RDEBUG
       
    88 
       
    89     /** Includes */
       
    90     #include <e32base.h>
       
    91     #include <e32std.h>
       
    92     #include <e32def.h>
       
    93     #include <e32svr.h>
       
    94     #include <flogger.h>
       
    95     
       
    96     #define _IT(a) KHgLogPath, KHgLogFile, EFileLoggingModeAppend, (TPtrC((const TText *)(a)))    
       
    97     #define _HGLOGPRINTER RFileLogger::WriteFormat    
       
    98 #endif // _HGLOG_RDEBUG    
       
    99 
       
   100 class _THgLogContext
       
   101     {
       
   102     public:
       
   103         _THgLogContext(
       
   104             const TText* _fn, 
       
   105             const TUint _id, 
       
   106             const TUint _vis, 
       
   107             const TUint _addr, 
       
   108             const TUint _thdId, 
       
   109             const TUint _category=0 )
       
   110             : 
       
   111             iFn(_fn), 
       
   112             iId(_id), 
       
   113             iApi((TBool)_vis), 
       
   114             iAddr(_addr), 
       
   115             iThdId(_thdId), 
       
   116             iVis((_vis == 0 ? (TText*)_HGLOG_API_PREFIX : (TText*)_HGLOG_LOCAL_PREFIX)),
       
   117             iCategory(_category)            
       
   118         #ifndef DISABLE_SYNTAX_CHECK
       
   119             ,outOk(EFalse), inOk(EFalse)
       
   120         #endif
       
   121             {
       
   122             }
       
   123         ~_THgLogContext() 
       
   124             {
       
   125             #ifndef DISABLE_SYNTAX_CHECK
       
   126                 do
       
   127                     {                   
       
   128                     DoInChk();
       
   129                     if (!outOk)
       
   130                         {
       
   131                         _HGLOGPRINTER(_IT(_HGLOG_UNCONTROLLER_EXIT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn);
       
   132                         }
       
   133                     } while (0);
       
   134             #endif // DISABLE_SYNTAX_CHECK
       
   135             }
       
   136 
       
   137         const TText* iFn;
       
   138         const TUint iId;
       
   139         const TText* iVis;
       
   140         const TUint iAddr;
       
   141         const TInt iThdId;
       
   142         const TBool iApi;
       
   143         const TUint iCategory;
       
   144         
       
   145         #ifndef DISABLE_SYNTAX_CHECK
       
   146             inline void DoInChk()
       
   147                 {
       
   148                 if (!inOk)
       
   149                     {
       
   150                     _HGLOGPRINTER(_IT(_HGLOG_UNCONTROLLED_INPUT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn);
       
   151                     inOk = ETrue;
       
   152                     }
       
   153                 }
       
   154                         
       
   155             inline void ChkMultiIn()
       
   156                 {
       
   157                 if (inOk)
       
   158                     {
       
   159                     _HGLOGPRINTER(_IT(_HGLOG_MULTIPLE_ENTRY_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn);                
       
   160                     }
       
   161                 }
       
   162     
       
   163             inline void ChkMultiOut()
       
   164                 {
       
   165                 if (outOk)
       
   166                     {           
       
   167                     _HGLOGPRINTER(_IT(_HGLOG_MULTIPLE_EXIT_MSG), iVis, iCategory, iId, iThdId, iAddr, iFn);                                        
       
   168                     }
       
   169                 }
       
   170 
       
   171             TBool inOk;
       
   172             TBool outOk;
       
   173         #endif // DISABLE_SYNTAX_CHECK
       
   174     };
       
   175     
       
   176 class _THgLogTrapHandler: public TTrapHandler
       
   177     {
       
   178     public:
       
   179 
       
   180         _THgLogTrapHandler(_THgLogContext& _context) : _dc( _context ) 
       
   181             {
       
   182             RThread me;
       
   183             iThdId = (TInt)me.Id();
       
   184             }
       
   185     	void Trap() 
       
   186     	    {
       
   187     	    _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_ENTRY), 0, HGLOGERR, iThdId, this);
       
   188     	    oldHandler->Trap();
       
   189     	    } 
       
   190     	void UnTrap()
       
   191     	    {
       
   192     	    _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_EXIT), 0, HGLOGERR, iThdId, this);
       
   193     	    oldHandler->UnTrap();
       
   194     	    }	
       
   195     	void Leave(TInt aValue)
       
   196     	    {
       
   197     	    _HGLOGPRINTER(_IT(_HGLOG_TRAP_HARNESS_LEAVE), 0, HGLOGERR, iThdId, this);
       
   198     	    oldHandler->Leave(aValue);
       
   199     	    }	
       
   200     	TTrapHandler* oldHandler;
       
   201     private:
       
   202         _THgLogContext& _dc;
       
   203         TInt iThdId;
       
   204     };
       
   205     
       
   206 #endif // _DEBUG    
       
   207 
       
   208 #endif // HGLOGUTILS_H