|         |      1 /* | 
|         |      2 * Copyright (c) 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:  CS Server Debug macros | 
|         |     15  * | 
|         |     16 */ | 
|         |     17  | 
|         |     18 #ifndef __C_CS_DEBUG_H__ | 
|         |     19 #define __C_CS_DEBUG_H__ | 
|         |     20  | 
|         |     21 // INCLUDE FILES | 
|         |     22  | 
|         |     23 // SYSTEM INCLUDES | 
|         |     24 #include <e32svr.h> | 
|         |     25 #include <e32std.h> | 
|         |     26 #include <f32file.h> | 
|         |     27 #include <eikenv.h> | 
|         |     28 #include <flogger.h> | 
|         |     29  | 
|         |     30 // USER INCLUDES | 
|         |     31  | 
|         |     32 // FORWARD DECLARATIONS | 
|         |     33  | 
|         |     34 /** | 
|         |     35  * MAX_BUFF_LENGTH. | 
|         |     36  * maximum buffer used for logging  | 
|         |     37  *  | 
|         |     38  */ | 
|         |     39 #define MAX_BUFF_LENGTH     255 | 
|         |     40  | 
|         |     41 /** | 
|         |     42  * TIME_FACTOR. | 
|         |     43  * time factor used to convert latency time into milli seconds | 
|         |     44  *  | 
|         |     45  */ | 
|         |     46 #define TIME_FACTOR     1000 | 
|         |     47  | 
|         |     48 /** | 
|         |     49  * KLogDrive. | 
|         |     50  * Log Drive | 
|         |     51  */ | 
|         |     52 _LIT(KLogDrive, "c"); | 
|         |     53 /** | 
|         |     54  * KLogDirFullName. | 
|         |     55  * Log Directory Full Name | 
|         |     56  */ | 
|         |     57 _LIT(KLogDirFullName, "\\logs\\"); | 
|         |     58  | 
|         |     59 /** | 
|         |     60  * KLogDir. | 
|         |     61  * CS Log Directory  | 
|         |     62  */ | 
|         |     63 _LIT(KLogDir, "Cs"); | 
|         |     64  | 
|         |     65 /** | 
|         |     66  * KLogDir. | 
|         |     67  * CS Log Directory  | 
|         |     68  */ | 
|         |     69 _LIT(KLogFile, "CsServer.txt"); | 
|         |     70  | 
|         |     71 /** | 
|         |     72  * KLogBanner. | 
|         |     73  * CS Log Banner  | 
|         |     74  */ | 
|         |     75 _LIT( KLogBanner, "CONVERSATION SERVER"); | 
|         |     76  | 
|         |     77 /** | 
|         |     78  * KCSTimeFormatString. | 
|         |     79  * Time formatting string.  | 
|         |     80  */ | 
|         |     81 _LIT(KCSTimeFormatString,   "%H:%T:%S:%*C2"); | 
|         |     82  | 
|         |     83 /** | 
|         |     84  * Debug Marcos  | 
|         |     85  */ | 
|         |     86 #ifdef _DEBUG | 
|         |     87  | 
|         |     88 /** | 
|         |     89  * Debug Marcos for WINS. | 
|         |     90  */ | 
|         |     91 #ifdef __WINS__ | 
|         |     92  | 
|         |     93 /** | 
|         |     94  * PRINT. | 
|         |     95  * Debug Marcos to print text. | 
|         |     96  *  | 
|         |     97  * @param txt Text to be printed on console | 
|         |     98  */ | 
|         |     99 #define PRINT( txt )                    RDebug::Print( txt ); | 
|         |    100  | 
|         |    101 /** | 
|         |    102  * PRINT1. | 
|         |    103  * Debug Marco to print text and arg1. | 
|         |    104  *  | 
|         |    105  * @param txt Text to be printed on console | 
|         |    106  * @param arg1 Argument to be printed on console | 
|         |    107  */ | 
|         |    108 #define PRINT1( txt, arg1 )             RDebug::Print( txt, arg1 ); | 
|         |    109  | 
|         |    110 /** | 
|         |    111  * PRINT2. | 
|         |    112  * Debug Marco to print text, arg1 and arg2. | 
|         |    113  *  | 
|         |    114  * @param txt Text to be printed on console | 
|         |    115  * @param arg1 Argument to be printed on console | 
|         |    116  * @param arg2 Argument to be printed on console  | 
|         |    117  */ | 
|         |    118 #define PRINT2( txt, arg1, arg2 )       RDebug::Print( txt, arg1, arg2 ); | 
|         |    119  | 
|         |    120 /** | 
|         |    121  * CONSERVER_CREATE. | 
|         |    122  * Debug Marco to create folder and file to log debug txt. | 
|         |    123  * Not needed for WINS. | 
|         |    124  */ | 
|         |    125 #define CONSERVER_CREATE | 
|         |    126  | 
|         |    127 #else | 
|         |    128  | 
|         |    129 /** | 
|         |    130  * Debug Marcos for ARM | 
|         |    131  */ | 
|         |    132  | 
|         |    133 /** | 
|         |    134  * PRINT. | 
|         |    135  * Debug Marco to log text. | 
|         |    136  *  | 
|         |    137  * @param txt Text to be logged in file | 
|         |    138  */ | 
|         |    139 #define PRINT( txt ) RFileLogger::Write(KLogDir,KLogFile, \ | 
|         |    140     EFileLoggingModeAppend,txt); | 
|         |    141  | 
|         |    142 /** | 
|         |    143  * PRINT1. | 
|         |    144  * Debug Marco to log text and arg1 | 
|         |    145  *  | 
|         |    146  * @param txt Text to be logged in file | 
|         |    147  * @param arg1 Argument to be logged in file | 
|         |    148  */ | 
|         |    149 #define PRINT1( txt, arg1 )             RFileLogger::WriteFormat(KLogDir,     \ | 
|         |    150     KLogFile,EFileLoggingModeAppend,     \ | 
|         |    151     TRefByValue<const TDesC>(txt),arg1); | 
|         |    152  | 
|         |    153 /** | 
|         |    154  * PRINT2. | 
|         |    155  * Debug Marco to log text, arg1 and arg2. | 
|         |    156  *  | 
|         |    157  * @param txt Text to be logged in file | 
|         |    158  * @param arg1 Argument to be logged in file | 
|         |    159  * @param arg2 Argument to be logged in file  | 
|         |    160  */ | 
|         |    161 #define PRINT2( txt, arg1, arg2 )       RFileLogger::WriteFormat(KLogDir,      \ | 
|         |    162     KLogFile,EFileLoggingModeAppend,   \ | 
|         |    163     TRefByValue<const TDesC>(txt),arg1,arg2); | 
|         |    164  | 
|         |    165 /** | 
|         |    166  * CONSERVER_CREATE. | 
|         |    167  * Debug Marco to create folder and file to log debug txt. | 
|         |    168  */ | 
|         |    169 #define CONSERVER_CREATE                {FCsCreate( );} | 
|         |    170  | 
|         |    171 /** | 
|         |    172  * FCsCreate. | 
|         |    173  * Function creates folder and file to log debug txt. | 
|         |    174  */ | 
|         |    175 inline void FCsCreate( ) | 
|         |    176     { | 
|         |    177     TFileName path(KLogDrive); | 
|         |    178     path.Append(_L(":")); | 
|         |    179     path.Append(KLogDirFullName); | 
|         |    180     path.Append(KLogDir); | 
|         |    181     path.Append(_L("\\")); | 
|         |    182     RFs& fs = CEikonEnv::Static()->FsSession(); | 
|         |    183     fs.MkDirAll(path); | 
|         |    184     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeOverwrite, KLogBanner); | 
|         |    185     } | 
|         |    186 #endif // __WINS__ | 
|         |    187  | 
|         |    188 #else | 
|         |    189 /** | 
|         |    190  * Empty Debug Marcos  | 
|         |    191  */ | 
|         |    192  | 
|         |    193 /** | 
|         |    194  * PRINT  | 
|         |    195  * Do nothing | 
|         |    196  */ | 
|         |    197 #define PRINT( txt ) | 
|         |    198  | 
|         |    199 /** | 
|         |    200  * PRINT1 | 
|         |    201  * Do nothing | 
|         |    202  */ | 
|         |    203 #define PRINT1( txt, arg1 ) | 
|         |    204  | 
|         |    205 /** | 
|         |    206  * PRINT2  | 
|         |    207  * Do nothing | 
|         |    208  */ | 
|         |    209 #define PRINT2( txt, arg1, arg2 ) | 
|         |    210  | 
|         |    211 /** | 
|         |    212  * CONSERVER_CREATE  | 
|         |    213  * Do nothing | 
|         |    214  */ | 
|         |    215  | 
|         |    216 /** | 
|         |    217  * CONSERVER_CREATE. | 
|         |    218  * Debug Marco to create folder and file to log debug txt. | 
|         |    219  */ | 
|         |    220 #define CONSERVER_CREATE                {FCsCreate( );} | 
|         |    221  | 
|         |    222 /** | 
|         |    223  * FCsCreate. | 
|         |    224  * Function creates folder and file to log debug txt. | 
|         |    225  */ | 
|         |    226 inline void FCsCreate( ) | 
|         |    227     { | 
|         |    228     TFileName path(KLogDrive); | 
|         |    229     path.Append(_L(":")); | 
|         |    230     path.Append(KLogDirFullName); | 
|         |    231     path.Append(KLogDir); | 
|         |    232     path.Append(_L("\\")); | 
|         |    233     RFs& fs = CEikonEnv::Static()->FsSession(); | 
|         |    234     fs.MkDirAll(path); | 
|         |    235     RFileLogger::WriteFormat(KLogDir, KLogFile, EFileLoggingModeOverwrite, KLogBanner); | 
|         |    236     } | 
|         |    237  | 
|         |    238 #endif // _DEBUG | 
|         |    239  | 
|         |    240 /** | 
|         |    241  * __LATENCY_MARK. | 
|         |    242  * Marco Marks the start time for latency measurement | 
|         |    243  *  | 
|         |    244  * @param str String to be logged | 
|         |    245  */ | 
|         |    246 #define __LATENCY_MARK( str )     CCsDebugWrapper::__LatencyMarkStartL(str); | 
|         |    247  | 
|         |    248 /** | 
|         |    249  * __LATENCY_MARKEND. | 
|         |    250  * Marco Marks the end time for latency measurement | 
|         |    251  *  | 
|         |    252  * @param str String to be logged | 
|         |    253  */ | 
|         |    254 #define __LATENCY_MARKEND( str )  CCsDebugWrapper::__LatencyMarkEnd(str); | 
|         |    255  | 
|         |    256 /** | 
|         |    257  * PRINT_LATENCY. | 
|         |    258  * Debug Marco to log text. | 
|         |    259  *  | 
|         |    260  * @param txt Text to be logged in file | 
|         |    261  */ | 
|         |    262 #define PRINT_LATENCY( txt ) RFileLogger::Write(KLogDir,KLogFile, \ | 
|         |    263     EFileLoggingModeAppend,txt); | 
|         |    264  | 
|         |    265 /** | 
|         |    266  * PRINT1. | 
|         |    267  * Debug Marco to log text and arg1 | 
|         |    268  *  | 
|         |    269  * @param txt Text to be logged in file | 
|         |    270  * @param arg1 Argument to be logged in file | 
|         |    271  */ | 
|         |    272 #define PRINT_LATENCY1( txt, arg1 )             RFileLogger::WriteFormat(KLogDir,     \ | 
|         |    273     KLogFile,EFileLoggingModeAppend,     \ | 
|         |    274     TRefByValue<const TDesC>(txt),arg1); | 
|         |    275  | 
|         |    276 /** | 
|         |    277  * PRINT_LATENCY2. | 
|         |    278  * Debug Marco to log text, arg1 and arg2. | 
|         |    279  *  | 
|         |    280  * @param txt Text to be logged in file | 
|         |    281  * @param arg1 Argument to be logged in file | 
|         |    282  * @param arg2 Argument to be logged in file  | 
|         |    283  */ | 
|         |    284 #define PRINT_LATENCY2( txt, arg1, arg2 )       RFileLogger::WriteFormat(KLogDir,      \ | 
|         |    285     KLogFile,EFileLoggingModeAppend,   \ | 
|         |    286     TRefByValue<const TDesC>(txt),arg1,arg2); | 
|         |    287  | 
|         |    288 #define PRINT_TIMESTAMP(a) {_LIT(temp, a); \ | 
|         |    289                             TTime time; time.HomeTime(); \ | 
|         |    290                             TBuf<256> buffer; \ | 
|         |    291                             time.FormatL( buffer, KCSTimeFormatString ); \ | 
|         |    292                             buffer.Insert(0, temp); \ | 
|         |    293                             RFileLogger::WriteFormat(KLogDir,   \ | 
|         |    294                                     KLogFile,   \ | 
|         |    295                                     EFileLoggingModeAppend, \ | 
|         |    296                                     buffer); } | 
|         |    297  | 
|         |    298 // CLASS DECLARATION | 
|         |    299  | 
|         |    300 /** | 
|         |    301  * CCsDebug | 
|         |    302  * Debug Class | 
|         |    303  *  | 
|         |    304  * @remarks Lib: CsUtils.lib | 
|         |    305  * @since S60 v5.0 | 
|         |    306  */ | 
|         |    307 class CCsDebug : public CBase | 
|         |    308     { | 
|         |    309  | 
|         |    310     public: // Constructor and New functions | 
|         |    311  | 
|         |    312         /** | 
|         |    313          * NewL. | 
|         |    314          * Two-phased constructor. | 
|         |    315          * | 
|         |    316          * @return A pointer to the created instance of CCsDebug. | 
|         |    317          */ | 
|         |    318         IMPORT_C static CCsDebug* NewL(); | 
|         |    319  | 
|         |    320         /** | 
|         |    321          * Mark. | 
|         |    322          * Marks the start time for latency measurement. | 
|         |    323          */ | 
|         |    324         IMPORT_C void Mark(TRefByValue<const TDesC> str,...); | 
|         |    325  | 
|         |    326         /** | 
|         |    327          * UnMark. | 
|         |    328          * Unmarks the start time for latency measurement. | 
|         |    329          */ | 
|         |    330         IMPORT_C void UnMark(TRefByValue<const TDesC> str,...); | 
|         |    331  | 
|         |    332     private: // Constructor | 
|         |    333  | 
|         |    334         /** | 
|         |    335          * ConstructL. | 
|         |    336          * Performs the second phase construction of a | 
|         |    337          * CCsDebug object. | 
|         |    338          */ | 
|         |    339         void ConstructL(); | 
|         |    340  | 
|         |    341     private: // Data | 
|         |    342  | 
|         |    343         /** | 
|         |    344          * startTime. | 
|         |    345          * Start Time, when measurement is started | 
|         |    346          * Own. | 
|         |    347          */ | 
|         |    348         TTime startTime; | 
|         |    349  | 
|         |    350         /** | 
|         |    351          * endTime. | 
|         |    352          * End Time, when measurement is ended | 
|         |    353          */ | 
|         |    354         TTime endTime; | 
|         |    355     }; | 
|         |    356  | 
|         |    357 /** | 
|         |    358  * CCsDebugArr | 
|         |    359  * Debug Array | 
|         |    360  *  | 
|         |    361  * @remarks Lib: CsUtils.lib | 
|         |    362  * @since S60 v5.0 | 
|         |    363  */ | 
|         |    364 class CCsDebugArr : public CBase | 
|         |    365     { | 
|         |    366  | 
|         |    367 public: // Constructor and New functions | 
|         |    368  | 
|         |    369     /** | 
|         |    370      * NewL. | 
|         |    371      * Two-phased constructor. | 
|         |    372      * | 
|         |    373      * @return A pointer to the created instance of CCsDebugArr. | 
|         |    374      */ | 
|         |    375     IMPORT_C static CCsDebugArr* NewL(); | 
|         |    376  | 
|         |    377     /** | 
|         |    378      * Push. | 
|         |    379      * Push an element into the array | 
|         |    380      * | 
|         |    381      * @param dbg Reference to instance of CCsDebug. | 
|         |    382      */ | 
|         |    383     IMPORT_C void Push(CCsDebug& dbg); | 
|         |    384  | 
|         |    385     /** | 
|         |    386      * Pop. | 
|         |    387      * Pop an element from the array | 
|         |    388      * | 
|         |    389      * @return A pointer to the instance of CCsDebug. | 
|         |    390      */     | 
|         |    391     IMPORT_C CCsDebug* Pop(); | 
|         |    392  | 
|         |    393     /** | 
|         |    394      * IsEmpty. | 
|         |    395      * Check if array is empty. | 
|         |    396      * | 
|         |    397      * @return ETure if array is empty, otherwise EFalse. | 
|         |    398      */     | 
|         |    399     IMPORT_C TBool IsEmpty(); | 
|         |    400  | 
|         |    401 public: // Destructor | 
|         |    402  | 
|         |    403     /** | 
|         |    404      * ~CCsDebugArr. | 
|         |    405      * Destructor. | 
|         |    406      * Destroys the object and release all memory objects. | 
|         |    407      */ | 
|         |    408     ~CCsDebugArr(); | 
|         |    409  | 
|         |    410 private: // data | 
|         |    411  | 
|         |    412     /** | 
|         |    413      * debugArray. | 
|         |    414      * Array of pointer to CCsDebug objects.   | 
|         |    415      * Own. | 
|         |    416      */ | 
|         |    417     RPointerArray<CCsDebug> debugArray; | 
|         |    418     }; | 
|         |    419  | 
|         |    420 /** | 
|         |    421  * CCsDebugWrapper | 
|         |    422  * Debug Wrapper | 
|         |    423  *  | 
|         |    424  * @remarks Lib: CsUtils.lib | 
|         |    425  * @since S60 v5.0 | 
|         |    426  */ | 
|         |    427 class CCsDebugWrapper : public CBase  | 
|         |    428     { | 
|         |    429      | 
|         |    430 public: //New functions | 
|         |    431      | 
|         |    432     /** | 
|         |    433      * __LatencyMarkStartL. | 
|         |    434      * Marks the start time for latency measurement. | 
|         |    435      */ | 
|         |    436      IMPORT_C static void __LatencyMarkStartL(TRefByValue<const TDesC> str); | 
|         |    437       | 
|         |    438      /** | 
|         |    439       * __LatencyMarkEnd. | 
|         |    440       * Marks the end time for latency measurement. | 
|         |    441       */ | 
|         |    442      IMPORT_C static void __LatencyMarkEnd(TRefByValue<const TDesC> str); | 
|         |    443     }; | 
|         |    444  | 
|         |    445 #endif // __C_CS_DEBUG_H__ | 
|         |    446  | 
|         |    447 // End of File |