filemanager/src/fmbkupengine/src/RMMCScBkupArchiveStreams.cpp
branchRCL_3
changeset 39 65326cf895ed
parent 38 491b3ed49290
child 42 f5c50b8af68c
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
     1 /*
       
     2 * Copyright (c) 2005 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: RMMCScBkupArchiveReadStream implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "RMMCScBkupArchiveStreams.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMCScBkupLogger.h"
       
    23 #include "CMMCScBkupArchiveDataManager.h"
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 // ========================= MEMBER FUNCTIONS ================================
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // RMMCScBkupArchiveBuf::RMMCScBkupArchiveBuf()
       
    32 // 
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 RMMCScBkupArchiveBuf::RMMCScBkupArchiveBuf()
       
    36 :   iADM(NULL)
       
    37     {
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // RMMCScBkupArchiveBuf::AttachL()
       
    43 // 
       
    44 // 
       
    45 // ---------------------------------------------------------------------------
       
    46 void RMMCScBkupArchiveBuf::AttachL( CMMCScBkupArchiveDataManager& aADM, RFile64& aFile, TInt aPos, TBool aForWrite )
       
    47     {
       
    48     //__LOG3("RMMCScBkupArchiveBuf::AttachL() - START - aFile: 0x%08x, aPos: %d, aForWrite: %d", aFile.SubSessionHandle(), aPos, aForWrite);
       
    49 
       
    50     // Prevent RFileBuf from resetting our file handle
       
    51     RFile64 file(aFile);
       
    52     RFileBuf::Attach(file, aPos);
       
    53 
       
    54     // We save the attach pos so that we can update the ADM with the final
       
    55     // length of data that was read or written...
       
    56     iInfo.Reset();
       
    57     iInfo.SetOffset(aPos);
       
    58 
       
    59     iWriteMode = aForWrite;
       
    60     iADM = &aADM;
       
    61 
       
    62     //__LOG("RMMCScBkupArchiveBuf::AttachL() - END");
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // RMMCScBkupArchiveBuf::Close()
       
    68 // 
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 EXPORT_C void RMMCScBkupArchiveBuf::Close()
       
    72     {
       
    73     //__LOG1("RMMCScBkupArchiveBuf::Close() - START - File: 0x%08x", File().SubSessionHandle());
       
    74 
       
    75     TRAP_IGNORE(DoSynchL());
       
    76     Detach();
       
    77     Reset();
       
    78 
       
    79     //__LOG1("RMMCScBkupArchiveBuf::Close() - END - File: 0x%08x", File().SubSessionHandle());
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // RMMCScBkupArchiveBuf::IsOpen()
       
    85 // 
       
    86 // 
       
    87 // ---------------------------------------------------------------------------
       
    88 TBool RMMCScBkupArchiveBuf::IsOpen() const
       
    89     {
       
    90     return (File().SubSessionHandle() != KNullHandle);
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // RMMCScBkupArchiveBuf::DoRelease()
       
    96 // 
       
    97 // 
       
    98 // ---------------------------------------------------------------------------
       
    99 void RMMCScBkupArchiveBuf::DoRelease()
       
   100     {
       
   101     //__LOG1("RMMCScBkupArchiveBuf::DoRelease() - START - File: 0x%08x", File().SubSessionHandle());
       
   102 
       
   103     TRAP_IGNORE( UpdateInfoL() );
       
   104     Detach();
       
   105     RFileBuf::DoRelease();
       
   106 
       
   107     //__LOG1("RMMCScBkupArchiveBuf::DoRelease() - END - File: 0x%08x", File().SubSessionHandle());
       
   108     }
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // RMMCScBkupArchiveBuf::DoSynchL()
       
   113 // 
       
   114 // 
       
   115 // ---------------------------------------------------------------------------
       
   116 void RMMCScBkupArchiveBuf::DoSynchL()
       
   117     {
       
   118     //__LOG1("RMMCScBkupArchiveBuf::DoSynchL() - START - File: 0x%08x", File().SubSessionHandle());
       
   119 
       
   120     RFileBuf::DoSynchL();
       
   121     UpdateInfoL();
       
   122 
       
   123     //__LOG1("RMMCScBkupArchiveBuf::DoSynchL() - END - File: 0x%08x", File().SubSessionHandle());
       
   124     }
       
   125 
       
   126 
       
   127 #ifdef RD_FILE_MANAGER_BACKUP
       
   128 // ---------------------------------------------------------------------------
       
   129 // RMMCScBkupArchiveBuf::DoWriteL()
       
   130 // 
       
   131 // 
       
   132 // ---------------------------------------------------------------------------
       
   133 void RMMCScBkupArchiveBuf::DoWriteL(const TAny* aPtr,TInt aLength)
       
   134     {
       
   135     iADM->CalculateCrc(aPtr, aLength);
       
   136     RFileBuf::DoWriteL(aPtr, aLength);
       
   137     }
       
   138 #endif
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // RMMCScBkupArchiveBuf::UpdateInfoL()
       
   143 // 
       
   144 // 
       
   145 // ---------------------------------------------------------------------------
       
   146 void RMMCScBkupArchiveBuf::UpdateInfoL()
       
   147     {
       
   148     //__LOG1("RMMCScBkupArchiveBuf::UpdateInfoL() - START - File: 0x%08x", File().SubSessionHandle());
       
   149 
       
   150     // Update our stats
       
   151     if  ( iADM && File().SubSessionHandle() != KNullHandle )
       
   152         {
       
   153         TStreamPos pos;
       
   154         if  ( iWriteMode )
       
   155             {
       
   156             pos = TellL( MStreamBuf::EWrite );
       
   157             //__LOG("RMMCScBkupArchiveBuf::UpdateInfoL() - write mode...");
       
   158             }
       
   159         else
       
   160             {
       
   161             pos = TellL( MStreamBuf::ERead );
       
   162             //__LOG("RMMCScBkupArchiveBuf::UpdateInfoL() - read mode...");
       
   163             }
       
   164         //
       
   165         const TInt currentOffset = pos.Offset();
       
   166         const TInt length = currentOffset - iInfo.Offset();
       
   167 
       
   168         //__LOG1("RMMCScBkupArchiveBuf::UpdateInfoL() - currentOffset: %8d", currentOffset);
       
   169         //__LOG1("RMMCScBkupArchiveBuf::UpdateInfoL() - length: %8d", length);
       
   170         iInfo.SetLength( length );
       
   171 
       
   172         // Inform ADM of final info
       
   173         iADM->SetCurrentVector( iInfo );
       
   174         }
       
   175 
       
   176     //__LOG1("RMMCScBkupArchiveBuf::UpdateInfoL() - END - File: 0x%08x", File().SubSessionHandle());
       
   177     }
       
   178 
       
   179 
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 // ========================= MEMBER FUNCTIONS ================================
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // RMMCScBkupArchiveReadStream::OpenLC()
       
   193 // 
       
   194 // 
       
   195 // ---------------------------------------------------------------------------
       
   196 void RMMCScBkupArchiveReadStream::OpenLC( CMMCScBkupArchiveDataManager& aADM, RFile64& aArchiveFile, TInt aPos )
       
   197     {
       
   198     CleanupClosePushL( *this );
       
   199     //
       
   200     iSource.AttachL( aADM, aArchiveFile, aPos, EFalse );
       
   201     RReadStream::Attach( &iSource );
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // RMMCScBkupArchiveReadStream::IsOpen()
       
   207 // 
       
   208 // 
       
   209 // ---------------------------------------------------------------------------
       
   210 TBool RMMCScBkupArchiveReadStream::IsOpen() const
       
   211     {
       
   212     return iSource.IsOpen();
       
   213     }
       
   214 
       
   215 
       
   216 
       
   217 
       
   218 
       
   219 
       
   220 
       
   221 
       
   222 
       
   223 
       
   224 
       
   225 
       
   226 // ========================= MEMBER FUNCTIONS ================================
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // RMMCScBkupArchiveWriteStream::OpenLC()
       
   230 // 
       
   231 // 
       
   232 // ---------------------------------------------------------------------------
       
   233 void RMMCScBkupArchiveWriteStream::OpenLC( CMMCScBkupArchiveDataManager& aADM, RFile64& aArchiveFile, TInt aPos )
       
   234     {
       
   235     CleanupClosePushL( *this );
       
   236     //
       
   237     iSink.AttachL( aADM, aArchiveFile, aPos, ETrue );
       
   238     RWriteStream::Attach( &iSink );
       
   239     }
       
   240 
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // RMMCScBkupArchiveWriteStream::IsOpen()
       
   244 // 
       
   245 // 
       
   246 // ---------------------------------------------------------------------------
       
   247 TBool RMMCScBkupArchiveWriteStream::IsOpen() const
       
   248     {
       
   249     return iSink.IsOpen();
       
   250     }
       
   251 
       
   252 
       
   253 
       
   254 
       
   255 
       
   256