homescreenpluginsrv/hspstools/src/hspslogbusfile.cpp
changeset 0 79c6a41cd166
child 14 15e4dd19031c
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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 ChspsLogBusFile.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "hspslogbusfile.h"
       
    20 #include "e32debug.h"
       
    21 
       
    22 // Constants
       
    23 
       
    24 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
    25 _LIT( KDefaultLoggingDirectory, "hsps" );
       
    26 _LIT( KTimeFormatAndExtension, "%F%D_%M_%Y_%H_%T_%C.log"); // F=FORCE, dd_mm_yyyy_hh_mm_mmmmmm 
       
    27 const TInt KTimeFormatAndExtensionMaxLength = ( 2 + 1 ) +   // 'dd_'
       
    28                                               ( 2 + 1 ) +   // 'mm_'
       
    29                                               ( 4 + 1 ) +   // 'yyyy_'
       
    30                                               ( 2 + 1 ) +   // 'hh_'
       
    31                                               ( 2 + 1 ) +   // 'mm_'
       
    32                                               ( 6 + 1 ) +   // 'mmmmmm_'
       
    33                                               ( 4 ) +       // '.log'
       
    34                                               ( 16 ) ;       // overflow protection
       
    35 #endif
       
    36 
       
    37 // Methods
       
    38 
       
    39 //----------------------------------------------------------------------------
       
    40 // ChspsLogBusFile::~ChspsLogBusFile
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
    44 EXPORT_C ChspsLogBusFile::~ChspsLogBusFile()
       
    45     {
       
    46     iFileLogger.CloseLog();
       
    47     iFileLogger.Close();
       
    48     
       
    49     delete iLoggingFile; iLoggingFile = NULL;
       
    50     delete iLoggingDirectory; iLoggingDirectory = NULL;
       
    51     }
       
    52 #else
       
    53 EXPORT_C ChspsLogBusFile::~ChspsLogBusFile()
       
    54     {
       
    55     }
       
    56 #endif
       
    57 //----------------------------------------------------------------------------
       
    58 // ChspsLogBusFile::NewL
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C ChspsLogBusFile* ChspsLogBusFile::NewL( const TDesC& aLoggingFile,
       
    62                                                  const TDesC& aLoggingDirectory )
       
    63     {
       
    64     ChspsLogBusFile* self = ChspsLogBusFile::NewLC( aLoggingFile, aLoggingDirectory );
       
    65     CleanupStack::Pop(); // self;
       
    66     return self;
       
    67     }
       
    68 
       
    69 //----------------------------------------------------------------------------
       
    70 // ChspsLogBusFile::NewLC
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C ChspsLogBusFile* ChspsLogBusFile::NewLC(  const TDesC& aLoggingFile,
       
    74                                                    const TDesC& aLoggingDirectory )
       
    75     {
       
    76     ChspsLogBusFile* self = new (ELeave)ChspsLogBusFile();
       
    77     CleanupStack::PushL(self);
       
    78     self->ConstructL( aLoggingFile, aLoggingDirectory );
       
    79     return self;
       
    80     }
       
    81 
       
    82 //----------------------------------------------------------------------------
       
    83 // ChspsLogBusFile::CreateLogFilename
       
    84 // ----------------------------------------------------------------------------
       
    85 //
       
    86 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
    87 EXPORT_C TFileName ChspsLogBusFile::CreateLogFilename( const TDesC& aBaseline )
       
    88     {
       
    89     TFileName fileName;
       
    90     
       
    91     // Append baseline and trailing '_'.
       
    92     fileName.Append( aBaseline );
       
    93     fileName.Append( TChar('_') );
       
    94     
       
    95     // Append Timestamp (formatting string contains extension).
       
    96     TTime time;
       
    97     time.HomeTime();   
       
    98     TBuf<KTimeFormatAndExtensionMaxLength> timestampAndExtension;
       
    99     TRAPD( err, time.FormatL( timestampAndExtension, KTimeFormatAndExtension() ) );
       
   100     if( err == KErrNone &&
       
   101         ( fileName.MaxLength() - fileName.Length() ) > timestampAndExtension.Length() )
       
   102         {
       
   103         fileName.Append( timestampAndExtension );
       
   104         }
       
   105     
       
   106     // Return created descriptor.
       
   107     return fileName;
       
   108     }
       
   109 #else
       
   110 EXPORT_C TFileName ChspsLogBusFile::CreateLogFilename( const TDesC& /*aBaseline*/ )
       
   111     {    
       
   112     return KNullDesC();
       
   113     }
       
   114 #endif
       
   115 
       
   116 //----------------------------------------------------------------------------
       
   117 // ChspsLogBusFile::_LogText
       
   118 // ----------------------------------------------------------------------------
       
   119 //
       
   120 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
   121 void ChspsLogBusFile::_LogText( const TDesC& aMessage)
       
   122     {
       
   123     iFileLogger.Write( aMessage );
       
   124     }
       
   125 #else
       
   126 void ChspsLogBusFile::_LogText( const TDesC& /*aMessage*/ )
       
   127     {
       
   128     }
       
   129 #endif
       
   130 
       
   131 //----------------------------------------------------------------------------
       
   132 // ChspsLogBusFile::ChspsLogBusFile
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 ChspsLogBusFile::ChspsLogBusFile()
       
   136     {
       
   137     iLoggingFile = NULL;
       
   138     iLoggingDirectory = NULL;
       
   139     }
       
   140 
       
   141 //----------------------------------------------------------------------------
       
   142 // ChspsLogBusFile::ConstructL
       
   143 // ----------------------------------------------------------------------------
       
   144 //
       
   145 #ifdef HSPS_BUILD_LOG_IMPLEMENTATION
       
   146 void ChspsLogBusFile::ConstructL( const TDesC& aLoggingFile,
       
   147                                   const TDesC& aLoggingDirectory )
       
   148     {
       
   149     iLoggingFile = aLoggingFile.AllocL();
       
   150     if( aLoggingDirectory != KNullDesC() )
       
   151         {
       
   152         iLoggingDirectory = aLoggingDirectory.AllocL();
       
   153         }
       
   154     else
       
   155         {
       
   156         iLoggingDirectory = KDefaultLoggingDirectory().AllocL();
       
   157         }
       
   158 
       
   159     User::LeaveIfError( iFileLogger.Connect() );
       
   160     iFileLogger.CreateLog( *iLoggingDirectory,
       
   161                            *iLoggingFile,
       
   162                            EFileLoggingModeOverwrite );
       
   163     iFileLogger.SetDateAndTime( EFalse, ETrue );       
       
   164     }
       
   165 #else
       
   166 void ChspsLogBusFile::ConstructL( const TDesC& /*aLoggingFile*/,
       
   167                                   const TDesC& /*aLoggingDirectory*/ )
       
   168     {       
       
   169     }
       
   170 #endif