wlanutilities/wlansniffer/inc/wsflogger.h
branchRCL_3
changeset 24 63be7eb3fc78
parent 23 b852595f5cbe
child 25 f28ada11abbf
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
     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 "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:  Class header for CWsfModel
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef WSFLOGGER_H
       
    19 #define WSFLOGGER_H
       
    20 
       
    21 
       
    22 #ifdef _DEBUG
       
    23 #define USE_WSFLOGGER
       
    24 #endif
       
    25 
       
    26 
       
    27 #ifdef USE_WSFLOGGER
       
    28 
       
    29 // undef this if you want logs into file
       
    30 #define WSFLOGGER_LOGGING_METHOD_RDEBUG
       
    31 
       
    32 //  EXTERNAL INCLUDES
       
    33 #include <flogger.h>
       
    34 #include <e32debug.h>
       
    35 
       
    36 
       
    37 //  CONSTANTS
       
    38 _LIT( KLogDir,                  "Sniffer" );
       
    39 _LIT( KLogFile,                 "Sniffer.txt" );
       
    40 _LIT( KLogBanner,               "Sniffer 0.1.0" );
       
    41 _LIT( KLogEnterFn,              "%04x\t% *S-> %S" );
       
    42 _LIT( KLogLeaveFn,              "%04x\t% *S<- %S" );
       
    43 _LIT( KLogExit,                 "Sniffer: Application exit" );
       
    44 _LIT( KLogFormat,               "%04x\t% *S%S" );
       
    45 
       
    46 
       
    47 //  CLASS DEFINITION
       
    48 /**
       
    49 * Class to log functionentry/exit
       
    50 *
       
    51 * Example usage:
       
    52 *
       
    53 * @code
       
    54 * #include "wsflogger.h"
       
    55 *
       
    56 * ...
       
    57 * 
       
    58 * void MyClass::DoIt() 
       
    59 *     {
       
    60 *     LOG_ENTERFN( "MyClass::DoIt" );
       
    61 *     // doing it...
       
    62 *     }
       
    63 *
       
    64 * @endcode
       
    65 *
       
    66 * Since the macros create instances on the stack, the class is destructed when
       
    67 * the stack is unwound. Thus, if LOG_ENTERFN was called at the highest level 
       
    68 * within the function then the destructor can detect the exit from the 
       
    69 * function without the need of an explicit "LOG_LEAVEFN" to each exit point.
       
    70 *
       
    71 * Note: the destructor is not called if a leave occurs.
       
    72 *
       
    73 * @since S60 5.0
       
    74 */
       
    75 NONSHARABLE_CLASS( CFunctionEntryExit ): public CBase
       
    76     {
       
    77     public:
       
    78 
       
    79         /**
       
    80         * Constructor
       
    81         * @since S60 5.0
       
    82         * @param aFunc Name of the function being entered
       
    83         */
       
    84         CFunctionEntryExit( TRefByValue<const TDesC> aFunc )
       
    85             {
       
    86             iFunc.Set( aFunc );
       
    87 
       
    88             RThread thread;
       
    89             TUint tid = TUint( thread.Id() ) & 0xffff;
       
    90 
       
    91 #ifndef WSFLOGGER_LOGGING_METHOD_RDEBUG
       
    92             RFileLogger::WriteFormat( KLogDir, 
       
    93                                       KLogFile, 
       
    94                                       EFileLoggingModeAppend, 
       
    95                                       KLogEnterFn, 
       
    96                                       tid,
       
    97                                       4*((tid>>2)&0x3),
       
    98                                       &KNullDesC,
       
    99                                       &iFunc);
       
   100 #else
       
   101             RDebug::Print( KLogEnterFn, tid,
       
   102                            4*((tid>>2)&0x3),
       
   103                            &KNullDesC,
       
   104                            &iFunc);
       
   105 #endif
       
   106             }
       
   107     
       
   108         /**
       
   109         * Destructor
       
   110         * @since S60 5.0
       
   111         */
       
   112         ~CFunctionEntryExit()
       
   113             {
       
   114             RThread thread;
       
   115             TUint tid = TUint( thread.Id() ) & 0xffff;
       
   116 
       
   117 #ifndef WSFLOGGER_LOGGING_METHOD_RDEBUG
       
   118             RFileLogger::WriteFormat( KLogDir, 
       
   119                                       KLogFile, 
       
   120                                       EFileLoggingModeAppend, 
       
   121                                       KLogLeaveFn, 
       
   122                                       tid,
       
   123                                       4*((tid>>2)&0x3),
       
   124                                       &KNullDesC,
       
   125                                       &iFunc);
       
   126 #else
       
   127             RDebug::Print( KLogLeaveFn, 
       
   128                            tid,
       
   129                            4*((tid>>2)&0x3),
       
   130                            &KNullDesC,
       
   131                            &iFunc );
       
   132 #endif
       
   133             }
       
   134 
       
   135     public:     // data
       
   136         /**
       
   137         * Function name
       
   138         */
       
   139         TPtrC iFunc;
       
   140     };
       
   141        
       
   142 
       
   143 //  LOG MACROS       
       
   144 #ifndef WSFLOGGER_LOGGING_METHOD_RDEBUG
       
   145 // Create/overwrite the log file
       
   146 #define LOG_CREATE                                                      \
       
   147             {                                                           \
       
   148             TFileName path( _L( "c:\\logs\\" ) );                       \
       
   149             path.Append( KLogDir );                                     \
       
   150             path.Append( _L( "\\" ) );                                  \
       
   151             RFileLogger::WriteFormat( KLogDir, KLogFile,                \
       
   152                            EFileLoggingModeOverwrite, KLogBanner );     \
       
   153             }
       
   154 
       
   155 
       
   156 // Close the log
       
   157 #define LOG_DELETE                                                      \
       
   158             RFileLogger::Write( KLogDir, KLogFile,                      \
       
   159                            EFileLoggingModeAppend, KLogExit );          \
       
   160 
       
   161 
       
   162 // Place a function entry/exit watchdog            
       
   163 #define LOG_ENTERFN(a)                                                  \
       
   164             CFunctionEntryExit entryExit( _L(a) );
       
   165 
       
   166 
       
   167 // Write a solid string to the log
       
   168 #define LOG_WRITE(a)                                                    \
       
   169             {                                                           \
       
   170             _LIT( temp, a );                                            \
       
   171             RThread thread;                                             \
       
   172             TUint tid = TUint( thread.Id() ) & 0xffff;                  \
       
   173             TBuf<5+12+sizeof(L##a)/2-1> buf;                            \
       
   174             buf.Format( KLogFormat,                                     \
       
   175                         tid, 4*((tid>>2)&0x3), &KNullDesC, &temp );     \
       
   176             RFileLogger::Write( KLogDir, KLogFile,                      \
       
   177                                 EFileLoggingModeAppend, buf );          \
       
   178             }
       
   179             
       
   180 
       
   181 // Write a formatted string to the log
       
   182 #define LOG_WRITEF(a, s...)                                             \
       
   183             {                                                           \
       
   184             _LIT( temp, a );                                            \
       
   185             RThread thread;                                             \
       
   186             TUint tid = TUint( thread.Id() ) & 0xffff;                  \
       
   187             TBuf<5+12+sizeof(L##a)/2-1> buf;                            \
       
   188             buf.Format( KLogFormat,                                     \
       
   189                         tid, 4*((tid>>2)&0x3), &KNullDesC, &temp );     \
       
   190             RFileLogger::WriteFormat( KLogDir, KLogFile,                \
       
   191                         EFileLoggingModeAppend, buf, s );               \
       
   192             }
       
   193 
       
   194 #else // WSFLOGGER_LOGGING_METHOD_RDEBUG
       
   195 
       
   196 // Create/overwrite the log file
       
   197 #define LOG_CREATE                                                      \
       
   198             RDebug::Print(_L("%S"), &KLogBanner);
       
   199 
       
   200 
       
   201 // Close the log
       
   202 #define LOG_DELETE                                                      \
       
   203             RDebug::Print(_L("%S"), &KLogExit);
       
   204 
       
   205 
       
   206 // Place a function entry/exit watchdog            
       
   207 #define LOG_ENTERFN(a)                                                  \
       
   208             CFunctionEntryExit entryExit( _L(a) );
       
   209 
       
   210 
       
   211 // Write a solid string to the log
       
   212 #define LOG_WRITE(a)                                                    \
       
   213             {                                                           \
       
   214             _LIT( temp, a );                                            \
       
   215             RThread thread;                                             \
       
   216             TUint tid = TUint( thread.Id() ) & 0xffff;                  \
       
   217             TBuf<5+12+sizeof(L##a)/2-1> buf;                            \
       
   218             buf.Format( KLogFormat,                                     \
       
   219                         tid, 4*((tid>>2)&0x3), &KNullDesC, &temp );     \
       
   220             RDebug::Print(buf);                                         \
       
   221             }
       
   222             
       
   223 
       
   224 // Write a formatted string to the log
       
   225 #define LOG_WRITEF(a, s...)                                             \
       
   226             {                                                           \
       
   227             _LIT( temp, a );                                            \
       
   228             RThread thread;                                             \
       
   229             TUint tid = TUint( thread.Id() ) & 0xffff;                  \
       
   230             TBuf<5+12+sizeof(L##a)/2-1> buf;                            \
       
   231             buf.Format( KLogFormat,                                     \
       
   232                         tid, 4*((tid>>2)&0x3), &KNullDesC, &temp );     \
       
   233             RDebug::Print( buf, s);                                     \
       
   234             }
       
   235 
       
   236 #endif // WSFLOGGER_LOGGING_METHOD_RDEBUG
       
   237 
       
   238 
       
   239 #else // _DEBUG
       
   240 
       
   241 
       
   242 #define LOG_CREATE
       
   243 #define LOG_DELETE
       
   244 #define LOG_ENTERFN(a)
       
   245 #define LOG_WRITE(a)
       
   246 #define LOG_WRITEF(a, s...)
       
   247 
       
   248 
       
   249 #endif // _DEBUG
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 #endif // WSFLOGGER_H
       
   255 
       
   256 
       
   257 // End of File