remotestoragefw/remotefileengine/src/rsfwflushstatemachine.cpp
changeset 13 6b4fc789785b
parent 2 c32dc0be5eb4
equal deleted inserted replaced
2:c32dc0be5eb4 13:6b4fc789785b
     1 /*
       
     2 * Copyright (c) 2007 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:  State machine for fetching data without caching it permanently
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "rsfwflushstatemachine.h"
       
    20 #include "rsfwinterface.h"
       
    21 #include "rsfwfileentry.h"
       
    22 #include "rsfwfileengine.h"
       
    23 #include "rsfwrfeserver.h"
       
    24 #include "rsfwvolumetable.h"
       
    25 #include "rsfwfiletable.h"
       
    26 #include "rsfwwaitnotemanager.h"
       
    27 #include "rsfwvolume.h"
       
    28 #include "mdebug.h"
       
    29 
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // CRsfwFlushStateMachine::CRsfwFlushStateMachine
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CRsfwFlushStateMachine::CRsfwFlushStateMachine()
       
    36     {
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CRsfwFlushStateMachine::CompleteRequestL
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CRsfwRfeStateMachine::TState*
       
    44 CRsfwFlushStateMachine::CompleteRequestL(TInt aError) 
       
    45     {
       
    46      DEBUGSTRING(("CRsfwFlushStateMachine::CompleteRequestL()"));
       
    47     // If we just wrote the file to the server set attributes from the cache
       
    48     // file's attributes.Even if writing the file failed, attributes should
       
    49     // reflect the local modifications
       
    50     if (Node()->CacheFileName())
       
    51         {
       
    52         FileEngine()->SetupAttributes(*Node());
       
    53         }
       
    54         
       
    55     CompleteAndDestroyState()->SetErrorCode(aError);
       
    56     return CompleteAndDestroyState();   
       
    57     } 
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CRsfwFlushStateMachine::TFlushDataToServerState::TFlushDataToServerState
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CRsfwFlushStateMachine::TFlushDataToServerState::TFlushDataToServerState(
       
    64     CRsfwFlushStateMachine* aParent)
       
    65     : iOperation(aParent)
       
    66     {
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CRsfwFlushStateMachine::TFlushDataToServerState::EnterL
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 void CRsfwFlushStateMachine::TFlushDataToServerState::EnterL() 
       
    74     {
       
    75     DEBUGSTRING(("CRsfwFlushStateMachine::TFlushDataToServerState::EnterL()"));
       
    76     
       
    77     TDesC* cacheNamep;
       
    78     if (!iOperation->Node())
       
    79         {
       
    80         User::Leave(KErrNotFound);
       
    81         }
       
    82 
       
    83     TRfeFlushInArgs* inArgs =
       
    84         static_cast<TRfeFlushInArgs*>(iOperation->iInArgs);
       
    85     
       
    86     
       
    87     if (iOperation->Node()->IsCancelled()) 
       
    88         {
       
    89         // user has cancelled writing this file to server even before we got to flush
       
    90         // (when the file was being written to the local cache)
       
    91         iOperation->HandleRemoteAccessResponse(0, KErrCancel);
       
    92         }
       
    93     else 
       
    94         {
       
    95         TInt firstByte = inArgs->iFirstByte;
       
    96         TInt dataLength = inArgs->iDataLength;
       
    97         TInt totalSize = inArgs->iTotalSize;  
       
    98      
       
    99         cacheNamep = iOperation->Node()->CacheFileName();
       
   100     
       
   101         _LIT8(KTextPlain, "text/plain");
       
   102         HBufC* fullName =
       
   103             iOperation->FileEngine()->FullNameLC(*(iOperation->Node()));
       
   104             
       
   105     
       
   106         // get the MIME-type of the file
       
   107         HBufC8* contentType = iOperation->FileEngine()->GetContentType(*cacheNamep);
       
   108     
       
   109         if (contentType) 
       
   110             {
       
   111             CleanupStack::PushL(contentType);  
       
   112             }
       
   113         else 
       
   114             {
       
   115             contentType = KTextPlain().AllocLC();
       
   116             }
       
   117         
       
   118         if  ((firstByte == 0) &&
       
   119             (dataLength == totalSize)) 
       
   120             {
       
   121             // non-partial put
       
   122             TUint transactionId 
       
   123                 = iOperation->FileEngine()->RemoteAccessL()->PutFileL(*cacheNamep,
       
   124                                                             *fullName,
       
   125                                                             *contentType,
       
   126                                                             iOperation);
       
   127         
       
   128             }
       
   129         else 
       
   130             {
       
   131             // partial put
       
   132             TUint transactionId 
       
   133             = iOperation->FileEngine()->RemoteAccessL()->PutFileL(*cacheNamep,
       
   134                                                             *fullName,
       
   135                                                             *contentType,
       
   136                                                             firstByte,
       
   137                                                    dataLength-firstByte,
       
   138                                                             totalSize,
       
   139                                                             iOperation);
       
   140             }
       
   141  
       
   142         CleanupStack::PopAndDestroy(2); // fullName, contentType        
       
   143         }
       
   144 
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CRsfwFlushStateMachine::TFlushDataToServerState::CompleteL
       
   149 // ----------------------------------------------------------------------------
       
   150 //
       
   151 CRsfwRfeStateMachine::TState*
       
   152 CRsfwFlushStateMachine::TFlushDataToServerState::CompleteL()
       
   153     {  
       
   154     DEBUGSTRING(("CRsfwFlushStateMachine::TFlushDataToServerState::CompleteL()"));
       
   155   	return iOperation->CompleteRequestL(KErrNone); 
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CRsfwFlushStateMachine::TFlushDataToServerState::ErrorL
       
   160 // ----------------------------------------------------------------------------
       
   161 //    
       
   162 CRsfwRfeStateMachine::TState*
       
   163 CRsfwFlushStateMachine::TFlushDataToServerState::ErrorL(TInt aCode)
       
   164     {
       
   165     DEBUGSTRING(("CRsfwFlushStateMachine::TFlushDataToServerState::ErrorL() %d", aCode));
       
   166   	return iOperation->CompleteRequestL(aCode); 
       
   167     }
       
   168 
       
   169 
       
   170 // End of file
       
   171