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