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