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