wvuing/wvlogger/Src/CCALoggerWriter.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 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:  History file writer class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <E32DEF.H>
       
    22 #include <e32std.h>
       
    23 #include "CCALoggerWriter.h"
       
    24 #include "MCALoggerWriteObserver.h"
       
    25 #include "MCALoggerMessageHeader.h"
       
    26 #include "MCALoggerMessage.h"
       
    27 #include "PrivateDefinitions.h"
       
    28 
       
    29 //for debug
       
    30 #include "ChatDebugPrint.h"
       
    31 
       
    32 #ifdef RD_MULTIPLE_DRIVE
       
    33 #include <centralrepository.h>
       
    34 #include <IMPSServiceSettingsUINGInternalCRKeys.h>
       
    35 #include <E32std.h>
       
    36 #include <EIKAPP.H>
       
    37 #include <eikappui.h>
       
    38 #include <eikenv.h>
       
    39 #include <eikbtgpc.h>
       
    40 #include <driveinfo.h>
       
    41 #include <StringLoader.h>            // StringLoader	
       
    42 #include "IMDialogUtils.h"
       
    43 #include <CAknMemorySelectionDialogMultiDrive.h>
       
    44 #include <rsfwmountman.h>
       
    45 
       
    46 const TInt KErrNotSaved = -999;
       
    47 
       
    48 #endif
       
    49 //CONSTANTS
       
    50 
       
    51 // ================= MEMBER FUNCTIONS =======================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // Destructor
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CCALoggerWriter::~CCALoggerWriter()
       
    58     {
       
    59     CHAT_DP_TXT( "CCALoggerWriter::~CCALoggerWriter" );
       
    60 
       
    61     if ( iLoggingOn )
       
    62         {
       
    63         //Must not leave here so trap all leaves no matter what.
       
    64         TInt ignore( KErrNone );
       
    65         TRAP( ignore, EndLoggingL() );
       
    66         }
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // Two phase creation.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CCALoggerWriter* CCALoggerWriter::NewL(		MCALoggerWriteObserver& aObserver,
       
    74                                          RFs& aFileSession )
       
    75     {
       
    76     CHAT_DP_TXT( "CCALoggerWriter::NewL" );
       
    77     CCALoggerWriter* self = new ( ELeave ) CCALoggerWriter(	aObserver,
       
    78                                                             aFileSession );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // Constructor
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CCALoggerWriter::CCALoggerWriter(	MCALoggerWriteObserver& aObserver,
       
    87                                   RFs& aFileSession )
       
    88         : iManager( aObserver ), iFileSession( aFileSession )
       
    89     {
       
    90     CHAT_DP_TXT( "CCALoggerWriter::CCALoggerWriterL" );
       
    91     }
       
    92 
       
    93 // ================= INHERITED FUNCTIONS =======================
       
    94 
       
    95 // From MCALoggerWriteInterface.
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // Logging starts here. Header information should be written.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CCALoggerWriter::StartLoggingL( MCALoggerMessageHeader* aFile )
       
   102     {
       
   103     CHAT_DP_TXT( "CCALoggerWriter::StartLoggingL" );
       
   104 
       
   105     if ( ! aFile )
       
   106         {
       
   107         User::Leave( KErrArgument );
       
   108         }
       
   109 
       
   110     CleanupDeletePushL( aFile );
       
   111 
       
   112     //Ownership of aFile is transfered to this component so push it to stack
       
   113 
       
   114     if ( iLoggingOn )
       
   115         {
       
   116         User::Leave( KErrInUse );
       
   117         }
       
   118 
       
   119     HBufC* logFileName = iManager.CreateNewFilenameL(); // we should get the correct file name only....
       
   120 #ifdef RD_MULTIPLE_DRIVE
       
   121 
       
   122     if ( logFileName == NULL )
       
   123         {
       
   124         CleanupStack::Pop( aFile );
       
   125         User::Leave( KErrNotSaved );
       
   126         return;
       
   127         }
       
   128 #endif
       
   129 
       
   130     CleanupStack::PushL( logFileName );
       
   131 
       
   132     aFile->SetFilenameL( *logFileName );
       
   133 
       
   134     CleanupStack::PopAndDestroy( logFileName );
       
   135 
       
   136     // Try to create the file
       
   137     TInt error = iFileStream.Create( iFileSession, aFile->FilenameL(), EFileWrite );
       
   138     if ( error != KErrNone )
       
   139         {
       
   140         User::LeaveIfError( error );
       
   141         }
       
   142 
       
   143     //Transfer ownership of aFile to iManager
       
   144     TFileRelation relation;
       
   145 
       
   146     relation.iFile = aFile;
       
   147     relation.iWriter = this;
       
   148 
       
   149     CleanupStack::Pop( aFile );
       
   150 
       
   151     iManager.AddFileL( relation );
       
   152 
       
   153     iLoggingOn = ETrue;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // Logging ends here. File should be closed after this.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CCALoggerWriter::EndLoggingL()
       
   161     {
       
   162     CHAT_DP_TXT( "CCALoggerWriter::EndLoggingL" );
       
   163 
       
   164     //set Logginstate off.
       
   165     iLoggingOn = EFalse;
       
   166 
       
   167     //Close the file
       
   168     iFileStream.Close();
       
   169 
       
   170     //Inform manager that file is not needed anymore.
       
   171     iManager.RemoveFileL( *this );
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // Is logging on. ETrue if on, EFalse if off.
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 TBool CCALoggerWriter::IsLoggingOn()
       
   179     {
       
   180     CHAT_DP_TXT( "CCALoggerWriter::IsLoggingL" );
       
   181     return iLoggingOn;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // Logging the message.
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CCALoggerWriter::MakeLogL( MCALoggerMessage& aMessage )
       
   189     {
       
   190     CHAT_DP_TXT( "CCALoggerWriter::MakeLogL" );
       
   191 
       
   192     if ( ! iLoggingOn )
       
   193         {
       
   194         User::Leave( KErrNotReady );
       
   195         }
       
   196 
       
   197     if ( iManager.CheckMemoryL( aMessage.MessageSizeInBytesL() ) )
       
   198         {
       
   199         aMessage.ExternalizeL( iFileStream );
       
   200         iFileStream.CommitL();
       
   201         }
       
   202     else
       
   203         {
       
   204         User::Leave( KErrDiskFull );
       
   205         }
       
   206     }
       
   207 
       
   208 //fix - refer Ui Spec Approved Version 1.0 (Instant Messaging NG 001 151006.pdf)
       
   209 //Section 10.2.10 Pg 131 -
       
   210 //"In case user has saved the image already or sent it by himself,
       
   211 // this option(save) is not available."
       
   212 // -----------------------------------------------------------------------------
       
   213 // ReLogging the message.
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CCALoggerWriter::ReLoggingL( MCALoggerMessageHeader& aFile )
       
   217     {
       
   218     CHAT_DP_TXT( "CCALoggerWriter::StartLoggingL" );
       
   219 
       
   220     if ( iLoggingOn )
       
   221         {
       
   222         User::Leave( KErrInUse );
       
   223         }
       
   224 
       
   225     // Try to create the file
       
   226 
       
   227     User::LeaveIfError( iFileStream.Replace( iFileSession,
       
   228                                              aFile.FilenameL(),
       
   229                                              EFileWrite ) );
       
   230 
       
   231     iLoggingOn = ETrue;
       
   232 
       
   233     }
       
   234 
       
   235 //fix - refer Ui Spec Approved Version 1.0 (Instant Messaging NG 001 151006.pdf)
       
   236 //Section 10.2.10 Pg 131 -
       
   237 //"In case user has saved the image already or sent it by himself,
       
   238 // this option(save) is not available."
       
   239 // -----------------------------------------------------------------------------
       
   240 // Logging ends here. File should be closed after this.
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CCALoggerWriter::EndReLogging()
       
   244     {
       
   245     CHAT_DP_TXT( "CCALoggerWriter::EndLoggingL" );
       
   246 
       
   247     //set Logginstate off.
       
   248     iLoggingOn = EFalse;
       
   249 
       
   250     //Close the file
       
   251     iFileStream.Close();
       
   252 
       
   253     }
       
   254 
       
   255 //end of file