rtsecuritymanager/inc/rtsecmgrtracer.h
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2007-2008 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 the License "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:      
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef _RTSECMGRTRACE_H
       
    24 #define _RTSECMGRTRACE_H
       
    25  
       
    26 #include <e32base.h>
       
    27 
       
    28 
       
    29 // Define tracer logging method if defined RTSECMGR_TRACE
       
    30 // 
       
    31 // Emulator    = Log to RDebug
       
    32 // Device      = Log to file (RFileLogger)
       
    33  
       
    34 // ============================================================================
       
    35  
       
    36 
       
    37 #ifndef RTSECMGR_TRACE  // Logging off
       
    38  
       
    39     #define RTSecMgrTraceFunction(func)    
       
    40     #define RTSecMgrTraceFunctionRet(func,format)
       
    41     #define RTSecMgrCreateTraceFile()
       
    42     #define RTSecMgrTracePrintRet(a)
       
    43 #else   // Logging on
       
    44  		 
       
    45        
       
    46     // Macro to print function entry, exit and leave. 
       
    47     // Example: RTSecMgrTraceFunction("CMyClass::MyFunction");
       
    48     #define RTSecMgrTraceFunction(func) TTracer function_tracer( _S(func), _S("") );
       
    49  
       
    50     // Macro to print function return value in addition to entry, exit 
       
    51     // and leave conditions Second parameter is a formatting string used 
       
    52     // to print the return value Example to print an integer return value:
       
    53     // RTSecMgrTraceFunctionRet("CMyclass::MyFunction", "%d");
       
    54     #define RTSecMgrTraceFunctionRet(func,format) TTracer func_tracer( _S(func), _S(format) );
       
    55     
       
    56 	#define RTSecMgrTracePrintRet(a)   RFileLogger::WriteFormat(KLogDir, \
       
    57                             KLogFile,EFileLoggingModeAppend,a);
       
    58      
       
    59  /*	#if (defined(__WINS__) || defined(__WINSCW__))  // Print to RDebug
       
    60        
       
    61         #include <e32debug.h>
       
    62         
       
    63         #define TRACER_PRINT(a)         RDebug::Print(a,&iFunc);
       
    64         #define TRACER_PRINT_RET(a,b)   RDebug::Print(a,&iFunc,b);
       
    65   		#define RTSecMgrCreateTraceFile()
       
    66  	
       
    67  	 #else      //Print to file 	  
       
    68    */ 
       
    69   		#include <f32file.h>
       
    70   		#include <flogger.h>
       
    71         
       
    72         _LIT( KLogDir,  "rtsecmgrtracelogs" );     // Log directory: C:\logs\rtsecmgrtracelogs
       
    73         _LIT( KLogFile, "rtsecmgrtracelogs.txt" ); // Log file: c:\logs\tracer\rtsecmgrtracelogs.txt
       
    74         _LIT( KFullPath, "c:\\logs\\rtsecmgrtracelogs\\" );  
       
    75     	_LIT(KFullLogFileName , "c:\\logs\\rtsecmgrtracelogs\\rtsecmgrtracelogs.txt") ;
       
    76        
       
    77         LOCAL_C void CreateLogFile()  // Local function for creating Logdirectory and LogFile
       
    78         {
       
    79         RFs fs;
       
    80         RFile fileHandle ;
       
    81         if( fs.Connect() == KErrNone )
       
    82             {
       
    83             fs.MkDirAll( KFullPath );
       
    84             if(fileHandle.Open(fs ,KFullLogFileName , EFileWrite | EFileShareAny )  == KErrNotFound)
       
    85 				{
       
    86 				fileHandle.Create(fs ,KFullLogFileName , EFileWrite | EFileShareAny ) ;
       
    87 				}
       
    88             fileHandle.Close() ;
       
    89             fs.Close();
       
    90             }
       
    91         }
       
    92      
       
    93     	#define RTSecMgrCreateTraceFile() CreateLogFile();
       
    94         
       
    95         #define TRACER_PRINT(a)         RFileLogger::WriteFormat(KLogDir, \
       
    96                             KLogFile,EFileLoggingModeAppend,a,&iFunc);
       
    97         #define TRACER_PRINT_RET(a,b)   RFileLogger::WriteFormat(KLogDir, \
       
    98                             KLogFile,EFileLoggingModeAppend,a,&iFunc,b);
       
    99  
       
   100  //   #endif
       
   101  
       
   102     _LIT( KLogEnter,    "%S: ENTER" );
       
   103     _LIT( KLogExit,     "%S: EXIT" );
       
   104     _LIT( KLogLeave,    "%S: LEAVE!" );
       
   105     _LIT( KLogExitRet,  "%S: EXIT, Returning " );
       
   106  
       
   107     /**
       
   108      * Simple tracer class that logs function enter, exit or leave
       
   109      */
       
   110     class TTracer
       
   111         {
       
   112     public:
       
   113  
       
   114         /**
       
   115          * inline constructor to write log of entering a function
       
   116          */
       
   117         TTracer( const TText* aFunc, const TText* aRetFormat )
       
   118             : iFunc( aFunc )
       
   119             , iRetFormat( aRetFormat )
       
   120             {
       
   121             TRACER_PRINT( KLogEnter );
       
   122             }
       
   123  
       
   124         /**
       
   125          * inline destructor to write log of exiting a function 
       
   126          * normally or with a leave
       
   127          */
       
   128         ~TTracer()
       
   129             {
       
   130             if ( std::uncaught_exception() ) // Leave is an exception
       
   131                 {
       
   132                 // The function exited with a leave
       
   133                 TRACER_PRINT( KLogLeave );
       
   134                 }
       
   135             else
       
   136                 {
       
   137                 // The function exited normally
       
   138                 if ( iRetFormat.Length() == 0 )
       
   139                     {
       
   140                     TRACER_PRINT( KLogExit );
       
   141                     }
       
   142                 else
       
   143                     {
       
   144                     // Log the return value
       
   145                     #ifdef __WINS__
       
   146                         TInt32 retVal = 0;
       
   147  
       
   148                         // The assembly bit. This needs to be reimplemented
       
   149                         // for every target. 
       
   150                         _asm( mov retVal, ebx );
       
   151  
       
   152                         TBuf<100> format( KLogExitRet );
       
   153                         format.Append( iRetFormat );
       
   154                         TRACER_PRINT_RET( format, retVal );
       
   155                     #else
       
   156                         TRACER_PRINT( KLogExit );
       
   157                    
       
   158                     #endif
       
   159                     }
       
   160                 }
       
   161             }
       
   162  
       
   163     private:
       
   164  
       
   165         /** 
       
   166          * Pointer descriptor to function signature that is to be logged.
       
   167          */
       
   168         TPtrC iFunc;
       
   169         
       
   170  
       
   171         /**
       
   172          * Formatting string used to print the function return value
       
   173          */
       
   174         TPtrC iRetFormat;
       
   175  
       
   176         };
       
   177  
       
   178 #endif // RTSECMGR_TRACE
       
   179  
       
   180 #endif // _RTSECMGRTRACE_H