phoneclientserver/phoneserver/Src/Standard/PhSrvDebugInfo.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2003 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 information implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include    <e32std.h>                  // tls
       
    22 #include    <e32svr.h>                  // rdebug
       
    23 #include    <f32file.h>                 // file and FS
       
    24 #include    <utf.h>                     // converter
       
    25 #include    "PhSrvDebugInfo.h"          // this
       
    26 #include    "KPhSrvConfigure.h"         // defines
       
    27 
       
    28 
       
    29 // Initialize
       
    30 #ifdef __PHSRV_DEBUG_INFO__
       
    31 
       
    32 // CONSTANTS
       
    33 // max length with number and extension is 25!
       
    34 _LIT( KPhSrvDebugFileName, "C:\\PhSrvDebug");
       
    35 _LIT( KPhSrvDebugFileExt, ".txt" );
       
    36 const TInt KPhSrvDebugFileNameLength( 25 );
       
    37 
       
    38 #ifdef __PHSRV_DEBUG_WRITE_LOG__
       
    39 _LIT( KPhSrvDebugEOF, "\n" );
       
    40 #endif // _PHSRV_DEBUG_WRITE_LOG__
       
    41 
       
    42 
       
    43 
       
    44 
       
    45 //----------------------------------------------------------------------------
       
    46 // PhSrvDebugInfo::Print
       
    47 //----------------------------------------------------------------------------
       
    48 //
       
    49 void PhSrvDebugInfo::Print(TInt/* aArea*/,const TDesC& aText )
       
    50 {
       
    51     
       
    52 
       
    53 
       
    54             // LOG TO FILE
       
    55 #ifdef __PHSRV_DEBUG_WRITE_LOG__
       
    56 
       
    57             TBuf8<128> toFile;
       
    58             CnvUtfConverter::ConvertFromUnicodeToUtf8( toFile, aText.Left(126) );
       
    59             toFile.Append( KPhSrvDebugEOF );
       
    60             
       
    61             PhSrvDebugInfo::CPhSrvDebugData* data = NULL;
       
    62     if( !data )
       
    63         {
       
    64         data = CreateData();
       
    65         }
       
    66     if( data )
       
    67         {
       
    68         data->CreateFile();           
       
    69         data->WriteFile( toFile );
       
    70         }
       
    71 #endif  // __PHSRV_DEBUG_WRITE_LOG__
       
    72 #ifdef __PHSRV_PRINT_DEBUG_INFO__
       
    73             RDebug::Print( aText );
       
    74 #endif // __PHSRV_PRINT_DEBUG_INFO__
       
    75           //  }   
       
    76       //  }
       
    77     }
       
    78 
       
    79 
       
    80 //----------------------------------------------------------------------------
       
    81 // PhSrvDebugInfo::CreateDataL
       
    82 //----------------------------------------------------------------------------
       
    83 //
       
    84 PhSrvDebugInfo::CPhSrvDebugData* PhSrvDebugInfo::CreateData()
       
    85     {
       
    86     PhSrvDebugInfo::CPhSrvDebugData* data = 
       
    87         new PhSrvDebugInfo::CPhSrvDebugData();
       
    88 
       
    89     return data;
       
    90     }
       
    91 
       
    92 
       
    93 //----------------------------------------------------------------------------
       
    94 // PhSrvDebugInfo::CPhSrvDebugData::~CPhSrvDebugData
       
    95 //----------------------------------------------------------------------------
       
    96 //
       
    97 PhSrvDebugInfo::CPhSrvDebugData::~CPhSrvDebugData()
       
    98     {
       
    99     ReleaseFile();
       
   100     }
       
   101 
       
   102 
       
   103 //----------------------------------------------------------------------------
       
   104 // PhSrvDebugInfo::CPhSrvDebugData::CreateFileL
       
   105 //----------------------------------------------------------------------------
       
   106 //
       
   107 void PhSrvDebugInfo::CPhSrvDebugData::CreateFile()
       
   108     {
       
   109     if ( !IsFile() )
       
   110         {
       
   111         if ( !iFs ) 
       
   112             iFs = new RFs();
       
   113         if ( !iFs )
       
   114             return;
       
   115         if ( iFs->Connect() != KErrNone )
       
   116             return;
       
   117 
       
   118         TBuf<KPhSrvDebugFileNameLength> name;
       
   119         TInt err = KErrGeneral;
       
   120         TInt i = 0;
       
   121             
       
   122         if ( !iFile )
       
   123             {
       
   124             name.Zero();
       
   125             name.Append( KPhSrvDebugFileName );
       
   126             name.AppendNum( i );
       
   127             name.Append( KPhSrvDebugFileExt );
       
   128             
       
   129             iFile = new RFile();
       
   130             if ( !iFile )
       
   131                 return;
       
   132             err = iFile->Create( *iFs, name, 
       
   133                 EFileStreamText|EFileWrite|EFileShareAny );
       
   134             }
       
   135 
       
   136        if( err != KErrNone )
       
   137             {
       
   138             err = iFile->Open( *iFs, name, 
       
   139             EFileStreamText|EFileWrite|EFileShareAny );
       
   140             }
       
   141                     
       
   142         }
       
   143     }
       
   144 
       
   145 
       
   146 void PhSrvDebugInfo::CPhSrvDebugData::ReleaseFile()
       
   147     {
       
   148     if ( iFile )
       
   149         {
       
   150         iFile->Close();
       
   151         delete iFile;
       
   152         iFile = NULL;
       
   153         }
       
   154     if ( iFs )
       
   155         {
       
   156         iFs->Close();
       
   157         delete iFs;
       
   158         iFs = NULL;
       
   159         }
       
   160     }
       
   161 
       
   162 
       
   163 TBool PhSrvDebugInfo::CPhSrvDebugData::IsFile() const
       
   164     {
       
   165     return ( iFile != NULL );
       
   166     }
       
   167 
       
   168 
       
   169 void PhSrvDebugInfo::CPhSrvDebugData::WriteFile(const TDesC8& aDes)
       
   170     {
       
   171     if ( IsFile() )
       
   172         {
       
   173         TInt place =0 ;
       
   174         iFile->Seek( ESeekEnd,place );
       
   175         iFile->Write( place, aDes );
       
   176         iFile->Flush();
       
   177         }
       
   178     }
       
   179 
       
   180 
       
   181 #endif
       
   182 
       
   183 
       
   184 
       
   185 //  End of File