|         |      1 /* | 
|         |      2 * Copyright (c) 2002-2004 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:   Debugging utilities implementation. | 
|         |     15 * | 
|         |     16 */ | 
|         |     17  | 
|         |     18  | 
|         |     19  | 
|         |     20 // INCLUDE FILES | 
|         |     21 #include "rubydebug.h" | 
|         |     22  | 
|         |     23 #ifdef __RUBY_DEBUG_TRACES_TO_FILE | 
|         |     24 #include <f32file.h> | 
|         |     25 #endif | 
|         |     26  | 
|         |     27 // EXTERNAL DATA STRUCTURES | 
|         |     28  | 
|         |     29 // EXTERNAL FUNCTION PROTOTYPES   | 
|         |     30  | 
|         |     31 // CONSTANTS | 
|         |     32  | 
|         |     33 #ifdef __RUBY_DEBUG_TRACES_TO_FILE | 
|         |     34 #ifdef _DEBUG // UDEB version: | 
|         |     35 _LIT( KSpace, " " ); | 
|         |     36 _LIT( KColon, ":" ); | 
|         |     37 _LIT( KFormat, "%02d" ); | 
|         |     38 _LIT( KFormat2, "%06d" ); | 
|         |     39 #endif | 
|         |     40 #endif | 
|         |     41  | 
|         |     42 // MACROS | 
|         |     43  | 
|         |     44 // LOCAL CONSTANTS AND MACROS | 
|         |     45  | 
|         |     46 // MODULE DATA STRUCTURES | 
|         |     47  | 
|         |     48 // LOCAL FUNCTION PROTOTYPES | 
|         |     49  | 
|         |     50 // FORWARD DECLARATIONS | 
|         |     51  | 
|         |     52 // ============================= LOCAL FUNCTIONS =============================== | 
|         |     53  | 
|         |     54 // ============================ MEMBER FUNCTIONS =============================== | 
|         |     55  | 
|         |     56 // ----------------------------------------------------------------------------- | 
|         |     57 // RRubyDebug::PrintToFile | 
|         |     58 // Method for writing traces to a file. | 
|         |     59 // ----------------------------------------------------------------------------- | 
|         |     60 // | 
|         |     61 #ifdef __RUBY_DEBUG_TRACES_TO_FILE | 
|         |     62  | 
|         |     63 #ifdef _DEBUG // UDEB version: | 
|         |     64 void RRubyDebug::PrintToFile( TRefByValue<const TDesC> aFmt, ... ) | 
|         |     65     { | 
|         |     66     _LIT( KRubyLogFileName, "c:\\Data\\Logs\\RubyTrace_vccclientprovisioning.txt" ); | 
|         |     67  | 
|         |     68     const TInt KRubyDebugMaxLineLength = 0x84; // rest will be truncated | 
|         |     69  | 
|         |     70     const TInt KRubyDebugOpenFileRetries = 100; | 
|         |     71     const TInt KRubyDebugOpenFileInterval = 1000; | 
|         |     72  | 
|         |     73     const TUint16 KRubyDebugLineSep1 = 0x0d; | 
|         |     74     const TUint16 KRubyDebugLineSep2 = 0x0a; | 
|         |     75  | 
|         |     76     // Handle variable argument list | 
|         |     77     VA_LIST list; | 
|         |     78 	VA_START( list, aFmt ); | 
|         |     79 	TBuf<KRubyDebugMaxLineLength+2> aBuf; | 
|         |     80     TTruncateOverflow overflow; | 
|         |     81      | 
|         |     82     // Append the time... | 
|         |     83     TTime currentTime; | 
|         |     84     currentTime.HomeTime(); | 
|         |     85     TDateTime dateTime = currentTime.DateTime(); | 
|         |     86  | 
|         |     87     aBuf.AppendFormat( KFormat, dateTime.Hour() ); | 
|         |     88     aBuf.Append( KColon ); | 
|         |     89  | 
|         |     90     aBuf.AppendFormat( KFormat, dateTime.Minute() ); | 
|         |     91     aBuf.Append( KColon ); | 
|         |     92  | 
|         |     93     aBuf.AppendFormat( KFormat, dateTime.Second() ); | 
|         |     94     aBuf.Append( KColon ); | 
|         |     95  | 
|         |     96     aBuf.AppendFormat( KFormat2, dateTime.MicroSecond() ); | 
|         |     97     aBuf.Append( KSpace ); | 
|         |     98     // time done | 
|         |     99      | 
|         |    100 	aBuf.AppendFormatList( aFmt, list, &overflow ); | 
|         |    101 	if( aBuf.Length() > ( KRubyDebugMaxLineLength - 2 ) ) | 
|         |    102 		{ | 
|         |    103 		aBuf.Delete(aBuf.Length() - 2, 2); | 
|         |    104 		} | 
|         |    105 	 | 
|         |    106     // Add linefeed characters | 
|         |    107     aBuf.Append( KRubyDebugLineSep1 ); | 
|         |    108     aBuf.Append( KRubyDebugLineSep2 ); | 
|         |    109  | 
|         |    110     RFs fs; | 
|         |    111     if ( fs.Connect() == KErrNone ) | 
|         |    112         { | 
|         |    113         RFile file; | 
|         |    114  | 
|         |    115         // Open file in an exclusive mode so that only one thread  | 
|         |    116         // can acess it simultaneously | 
|         |    117         TUint fileMode = EFileWrite | EFileShareExclusive; | 
|         |    118  | 
|         |    119         TInt err = file.Open( fs, KRubyLogFileName, fileMode ); | 
|         |    120  | 
|         |    121         // Create a file if it doesn't exist | 
|         |    122         if ( err == KErrNotFound ) | 
|         |    123             { | 
|         |    124             err = file.Create( fs, KRubyLogFileName, fileMode ); | 
|         |    125             } | 
|         |    126         else | 
|         |    127             { | 
|         |    128             // Error in opening the file | 
|         |    129             TInt retryCount = KRubyDebugOpenFileRetries; | 
|         |    130             while ( err == KErrInUse && retryCount-- ) | 
|         |    131                 { | 
|         |    132                 // Some other tread is accessing the file, wait a while... | 
|         |    133                 User::After( KRubyDebugOpenFileInterval ); | 
|         |    134                 err = file.Open( fs, KRubyLogFileName, fileMode ); | 
|         |    135                 } | 
|         |    136             } | 
|         |    137  | 
|         |    138         // Check if we have access to a file | 
|         |    139         if ( err == KErrNone ) | 
|         |    140             { | 
|         |    141             TInt offset = 0; | 
|         |    142             if ( file.Seek( ESeekEnd, offset ) == KErrNone ) | 
|         |    143                 { | 
|         |    144                 // Append text to the end of file | 
|         |    145                 TPtr8 ptr8( (TUint8*)aBuf.Ptr(), aBuf.Size(), aBuf.Size() ); | 
|         |    146                 file.Write( ptr8 ); | 
|         |    147                 } | 
|         |    148             file.Close(); | 
|         |    149             } | 
|         |    150  | 
|         |    151         fs.Close(); | 
|         |    152         } | 
|         |    153     } | 
|         |    154  | 
|         |    155 #else // UREL version: | 
|         |    156 void RRubyDebug::PrintToFile( TRefByValue<const TDesC> /*aFmt*/, ... ) | 
|         |    157     { | 
|         |    158     } | 
|         |    159 #endif | 
|         |    160  | 
|         |    161 #endif // __RUBY_DEBUG_TRACES_TO_FILE | 
|         |    162  | 
|         |    163 // ========================== OTHER EXPORTED FUNCTIONS ========================= | 
|         |    164  | 
|         |    165 //  End of File   |