simpleengine/siputils/src/simpledebugutils.cpp
changeset 0 c8caa15ef882
child 17 2669f8761a99
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    DEBUG utilities, for DEBUG version only
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 
       
    25 #ifdef _DEBUG
       
    26 #include <flogger.h>
       
    27 #include <e32debug.h>
       
    28 #include <apparc.h>
       
    29 #include <bautils.h>
       
    30 #endif  // _DEBUG
       
    31 
       
    32 #include "simpledebugutils.h"
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 #ifdef _DEBUG
       
    37 
       
    38 //**********************************
       
    39 // TSimpleLogger
       
    40 //**********************************
       
    41 const TInt KLogBufferLength = 256;
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // TSimpleLogger::Log
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 void TSimpleLogger::Log(TRefByValue<const TDesC> aFmt,...) //lint !e960
       
    48     {
       
    49     VA_LIST list;
       
    50     VA_START(list, aFmt); //lint !e960
       
    51 
       
    52     // Print to log file
       
    53     TBuf<KLogBufferLength> buf;
       
    54     buf.FormatList(aFmt, list);
       
    55 
       
    56     _LIT(KLogDir, "simple");
       
    57     _LIT(KLogFile, "simple.txt");
       
    58     // Write to log file
       
    59     RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, buf);
       
    60     
       
    61     _LIT( KSimplePrefix,  "[simple] ");    
       
    62     buf.Insert( 0, KSimplePrefix );
       
    63     RDebug::RawPrint( buf );
       
    64 
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // TSimpleLogger::Dump
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 void TSimpleLogger::Dump( const TDesC8& aData, RFs& aFs, TInt aMode )
       
    72     {
       
    73     if ( !aData.Length() )
       
    74         {
       
    75         return;
       
    76         }
       
    77 
       
    78     _LIT(KLogDir, "c:\\logs\\simple\\");
       
    79 
       
    80     TParse myParse;
       
    81 
       
    82     // generate unique file name
       
    83     TFileName fileName;
       
    84     fileName = KLogDir;
       
    85     if( BaflUtils::PathExists( aFs, fileName ) )
       
    86         {
       
    87         _LIT( KRelatedRcv, "Receive.xml");
       
    88         _LIT( KRelatedSnt, "Sent.xml");
       
    89         if ( aMode )
       
    90             {
       
    91             myParse.Set( fileName, &KRelatedRcv, NULL );
       
    92             }
       
    93         else
       
    94             {
       
    95             myParse.Set( fileName, &KRelatedSnt, NULL );
       
    96             }
       
    97         fileName = myParse.FullName();
       
    98         if ( CApaApplication::GenerateFileName( aFs, fileName ))
       
    99             {
       
   100             return;
       
   101             }
       
   102 
       
   103         // write data into file
       
   104         RFile file;
       
   105         TInt xmlError = file.Create( aFs, fileName, EFileWrite | EFileShareExclusive );
       
   106         if ( xmlError == KErrNone )
       
   107             {
       
   108             file.Write( aData );
       
   109             file.Flush();
       
   110             }
       
   111 
       
   112         // done - close file
       
   113         file.Close();
       
   114 
       
   115         Log( _L("Dump: LogFile = %S"), &fileName );
       
   116         }
       
   117     }
       
   118 #endif  // _DEBUG
       
   119 
       
   120 
       
   121 //**********************************
       
   122 // CSimpleSettingFile
       
   123 //**********************************
       
   124 
       
   125 CSimpleSettingFile::~CSimpleSettingFile()
       
   126     {
       
   127     if ( iOpen )
       
   128         {
       
   129         iReader.Close();
       
   130         }
       
   131     iOpen = EFalse;
       
   132     }
       
   133 
       
   134 CSimpleSettingFile::CSimpleSettingFile( RFs& aFs)
       
   135 : iFs( aFs ),
       
   136   iOpen( EFalse )
       
   137     {
       
   138     }
       
   139     
       
   140 #ifdef _DEBUG
       
   141 
       
   142 CSimpleSettingFile* CSimpleSettingFile::NewL(
       
   143     RFs& aFs )
       
   144     {
       
   145     CSimpleSettingFile* self = new (ELeave) CSimpleSettingFile( aFs );
       
   146     return self;
       
   147     }
       
   148 
       
   149 void CSimpleSettingFile::OpenL(TDesC& aResFile)
       
   150     {
       
   151     // open a file
       
   152     iFileName = aResFile;
       
   153 
       
   154     TInt myError = iReader.Open( iFs,
       
   155                              iFileName,
       
   156                              EFileShareReadersOnly );
       
   157 
       
   158     User::LeaveIfError( myError );
       
   159     iOpen = ETrue;
       
   160     }
       
   161 
       
   162 TPtrC8 CSimpleSettingFile::KeyValueL( const TDesC8& aKey )
       
   163     {
       
   164 
       
   165     TPtrC8 myKey;
       
   166     TPtrC8 myValue;
       
   167     TBool getIt(EFalse);
       
   168     TInt err = 0;
       
   169 
       
   170     // Reset the reader
       
   171     OpenL( iFileName );
       
   172 
       
   173     // Start to search
       
   174     while ( !getIt)
       
   175         {
       
   176         TRAP ( err, ReadRowL( myKey, myValue ));
       
   177         if ( err != KErrNone )
       
   178             {
       
   179             User::Leave( KErrNotFound );
       
   180             }
       
   181         if ( !myKey.CompareF( aKey ))
       
   182             {
       
   183             return myValue;
       
   184             }
       
   185         }
       
   186     return TPtrC8();
       
   187     }
       
   188 
       
   189 void CSimpleSettingFile::ReadRowL( TPtrC8& aKey, TPtrC8& aValue )
       
   190     {
       
   191     // READ ONE ROW
       
   192     TChar delim( 10 );
       
   193     iReader.ReadL( iRowBuffer, delim);
       
   194     TInt length = iRowBuffer.Length();
       
   195     if ( length > 2 )
       
   196         {
       
   197         // DROP CR+LF FROM THE END OF LINE
       
   198         iRowBuffer.Delete( length - 2, 2 );
       
   199 
       
   200         TInt pos = 0;
       
   201         pos = iRowBuffer.Find( _L8("=") );
       
   202         if ( pos > 0 )
       
   203             {
       
   204             aKey.Set( iRowBuffer.Left( pos ) );
       
   205             // Cut off separator
       
   206             aValue.Set( iRowBuffer.Mid( pos + 1 ) );
       
   207             }
       
   208         }
       
   209     } 
       
   210 #endif  // _DEBUG   
       
   211 
       
   212 //  End of File
       
   213