|         |      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 // MACROS | 
|         |     34  | 
|         |     35 // LOCAL CONSTANTS AND MACROS | 
|         |     36  | 
|         |     37 // MODULE DATA STRUCTURES | 
|         |     38  | 
|         |     39 // LOCAL FUNCTION PROTOTYPES | 
|         |     40  | 
|         |     41 // FORWARD DECLARATIONS | 
|         |     42  | 
|         |     43 // ============================= LOCAL FUNCTIONS =============================== | 
|         |     44  | 
|         |     45 // ============================ MEMBER FUNCTIONS =============================== | 
|         |     46  | 
|         |     47 // ----------------------------------------------------------------------------- | 
|         |     48 // RRubyDebug::PrintToFile | 
|         |     49 // Method for writing traces to a file. | 
|         |     50 // ----------------------------------------------------------------------------- | 
|         |     51 // | 
|         |     52 #ifdef __RUBY_DEBUG_TRACES_TO_FILE | 
|         |     53  | 
|         |     54 #ifdef _DEBUG // UDEB version: | 
|         |     55  void RRubyDebug::PrintToFile( TRefByValue<const TDesC> aFmt, ... ) | 
|         |     56     { | 
|         |     57     _LIT( KRubyLogFileName, "c:\\Data\\Logs\\rubytrace_vccutils.txt" ); | 
|         |     58  | 
|         |     59     const TInt KRubyDebugMaxLineLength = 0x80; // rest will be truncated | 
|         |     60  | 
|         |     61     const TInt KRubyDebugOpenFileRetries = 100; | 
|         |     62     const TInt KRubyDebugOpenFileInterval = 1000; | 
|         |     63  | 
|         |     64     const TUint16 KRubyDebugLineSep1 = 0x0d; | 
|         |     65     const TUint16 KRubyDebugLineSep2 = 0x0a; | 
|         |     66  | 
|         |     67     // Handle variable argument list | 
|         |     68     VA_LIST list; | 
|         |     69     VA_START( list, aFmt ); | 
|         |     70     TBuf<KRubyDebugMaxLineLength+2> aBuf; | 
|         |     71     TTruncateOverflow overflow; | 
|         |     72     aBuf.AppendFormatList( aFmt, list, &overflow ); | 
|         |     73     if( aBuf.Length() > ( KRubyDebugMaxLineLength - 2 ) ) | 
|         |     74         { | 
|         |     75         aBuf.Delete(aBuf.Length() - 2, 2); | 
|         |     76         } | 
|         |     77  | 
|         |     78     // Add linefeed characters | 
|         |     79     aBuf.Append( KRubyDebugLineSep1 ); | 
|         |     80     aBuf.Append( KRubyDebugLineSep2 ); | 
|         |     81  | 
|         |     82     RFs fs; | 
|         |     83     if ( fs.Connect() == KErrNone ) | 
|         |     84         { | 
|         |     85         RFile file; | 
|         |     86  | 
|         |     87         // Open file in an exclusive mode so that only one thread | 
|         |     88         // can acess it simultaneously | 
|         |     89         TUint fileMode = EFileWrite | EFileShareExclusive; | 
|         |     90  | 
|         |     91         TInt err = file.Open( fs, KRubyLogFileName, fileMode ); | 
|         |     92  | 
|         |     93         // Create a file if it doesn't exist | 
|         |     94         if ( err == KErrNotFound ) | 
|         |     95             { | 
|         |     96             err = file.Create( fs, KRubyLogFileName, fileMode ); | 
|         |     97             } | 
|         |     98         else | 
|         |     99             { | 
|         |    100             // Error in opening the file | 
|         |    101             TInt retryCount = KRubyDebugOpenFileRetries; | 
|         |    102             while ( err == KErrInUse && retryCount-- ) | 
|         |    103                 { | 
|         |    104                 // Some other tread is accessing the file, wait a while... | 
|         |    105                 User::After( KRubyDebugOpenFileInterval ); | 
|         |    106                 err = file.Open( fs, KRubyLogFileName, fileMode ); | 
|         |    107                 } | 
|         |    108             } | 
|         |    109  | 
|         |    110         // Check if we have access to a file | 
|         |    111         if ( err == KErrNone ) | 
|         |    112             { | 
|         |    113             TInt offset = 0; | 
|         |    114             if ( file.Seek( ESeekEnd, offset ) == KErrNone ) | 
|         |    115                 { | 
|         |    116                 // Append text to the end of file | 
|         |    117                 TPtr8 ptr8( (TUint8*)aBuf.Ptr(), aBuf.Size(), aBuf.Size() ); | 
|         |    118                 file.Write( ptr8 ); | 
|         |    119                 } | 
|         |    120             file.Close(); | 
|         |    121             } | 
|         |    122  | 
|         |    123         fs.Close(); | 
|         |    124         } | 
|         |    125     } | 
|         |    126  | 
|         |    127 #else // UREL version: | 
|         |    128  void RRubyDebug::PrintToFile( TRefByValue<const TDesC> /*aFmt*/, ... ) | 
|         |    129     { | 
|         |    130     } | 
|         |    131 #endif | 
|         |    132  | 
|         |    133 #endif // __RUBY_DEBUG_TRACES_TO_FILE | 
|         |    134  | 
|         |    135 // ========================== OTHER EXPORTED FUNCTIONS ========================= | 
|         |    136  | 
|         |    137 //  End of File |