remotestoragefw/remotefileengine/src/rsfwmkdirstatemachine.cpp
branchRCL_3
changeset 15 88ee4cf65e19
parent 12 87c71b25c937
child 16 1aa8c82cb4cb
equal deleted inserted replaced
12:87c71b25c937 15:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2005-2006 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 creating directories
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "rsfwmkdirstatemachine.h"
       
    20 #include "rsfwfileentry.h"
       
    21 #include "rsfwfiletable.h"
       
    22 #include "rsfwinterface.h"
       
    23 #include "rsfwfileengine.h"
       
    24 #include "mdebug.h"
       
    25 #include "rsfwdirentattr.h"
       
    26 #include "rsfwvolumetable.h"
       
    27 
       
    28 // Make dir
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CRsfwMkDirStateMachine::CRsfwMkDirStateMachine
       
    32 // ----------------------------------------------------------------------------
       
    33 //    
       
    34 CRsfwMkDirStateMachine::CRsfwMkDirStateMachine()
       
    35     {
       
    36     }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CRsfwMkDirStateMachine::~CRsfwMkDirStateMachine
       
    40 // ----------------------------------------------------------------------------
       
    41 //    
       
    42 CRsfwMkDirStateMachine::~CRsfwMkDirStateMachine() 
       
    43     {
       
    44     delete iDirEntAttr;
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CRsfwMkDirStateMachine::CompleteRequestL
       
    49 // ----------------------------------------------------------------------------
       
    50 //    
       
    51 CRsfwRfeStateMachine::TState* CRsfwMkDirStateMachine::CompleteRequestL(TInt aError) 
       
    52     {
       
    53     if (iKidCreated && aError)
       
    54         {
       
    55         if ( aError == KErrNotFound )
       
    56             {
       
    57             User::Leave( KErrNotFound );
       
    58             }
       
    59         delete iKidFep;
       
    60         iKidFep = NULL;
       
    61         }
       
    62 
       
    63     // it may happen by chance that the new name is equal to iLastFailedLookup value
       
    64     FileEngine()->ResetFailedLookup();
       
    65      
       
    66     CompleteAndDestroyState()->SetErrorCode(aError);
       
    67     return CompleteAndDestroyState();
       
    68     }
       
    69 
       
    70 
       
    71 
       
    72 // Check if exists
       
    73 
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // CRsfwMkDirStateMachine::TCheckIfExistsState::TCheckIfExistsState
       
    77 // ----------------------------------------------------------------------------
       
    78 //    
       
    79 CRsfwMkDirStateMachine::
       
    80 TCheckIfExistsState::TCheckIfExistsState(CRsfwMkDirStateMachine* aParent)
       
    81     : iOperation(aParent)
       
    82     {
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CRsfwMkDirStateMachine::TCheckIfExistsState::EnterL
       
    87 // ----------------------------------------------------------------------------
       
    88 //    
       
    89 void CRsfwMkDirStateMachine::TCheckIfExistsState::EnterL() 
       
    90     {
       
    91     TRfeMkdirInArgs* inArgs =
       
    92         static_cast<TRfeMkdirInArgs*>(iOperation->iInArgs);
       
    93     TPtrC kidName(inArgs->iEntry.iName);
       
    94 
       
    95     iOperation->iKidFep = NULL;
       
    96     iOperation->iKidCreated = EFalse;
       
    97 
       
    98     // the parent to which we are making             
       
    99     if (!iOperation->Node())
       
   100         {
       
   101         User::Leave(KErrNotFound);
       
   102         }
       
   103         
       
   104     DEBUGSTRING16(("making directory '%S' in fid %d",
       
   105                    &kidName,
       
   106                    iOperation->Node()->Fid().iNodeId));    
       
   107 
       
   108     // Do we know about the kid yet?
       
   109     iOperation->iKidFep = iOperation->Node()->FindKidByName(kidName);
       
   110     if (!iOperation->iKidFep)
       
   111         {
       
   112         // This is either a completely new directory,
       
   113         // or a directory that we have not yet created a file entry for.
       
   114         // (should always happen)
       
   115         if (!iOperation->Volumes()->EnsureMetadataCanBeAddedL(iOperation->Node()))
       
   116             {
       
   117             User::Leave(KErrNoMemory);  
       
   118             }        
       
   119         iOperation->iKidFep = CRsfwFileEntry::NewL(kidName, iOperation->Node());
       
   120         iOperation->iKidCreated = ETrue;
       
   121         }
       
   122        
       
   123     iOperation->FileEngine()->GetAttributesL(*iOperation->iKidFep,
       
   124                                              iOperation->iDirEntAttr,
       
   125                                              KNodeTypeDir,
       
   126                                              iOperation);
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CRsfwMkDirStateMachine::TCheckIfExistsState::CompleteL
       
   131 // ----------------------------------------------------------------------------
       
   132 //    
       
   133 CRsfwMkDirStateMachine::TState*
       
   134 CRsfwMkDirStateMachine::TCheckIfExistsState::CompleteL()
       
   135     {
       
   136     // GetAttributes returned KErrNone
       
   137     // directory exist and we return KErrAlreadyExitsts
       
   138     return iOperation->CompleteRequestL(KErrAlreadyExists); 
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CRsfwMkDirStateMachine::TCheckIfExistsState::ErrorL
       
   143 // ----------------------------------------------------------------------------
       
   144 //    
       
   145 CRsfwMkDirStateMachine::TState*
       
   146 CRsfwMkDirStateMachine::TCheckIfExistsState::ErrorL(TInt /*aCode*/)
       
   147     {
       
   148     // GetAttributes returned error - 
       
   149     // directory does not exists, let's create it
       
   150   
       
   151     return new CRsfwMkDirStateMachine::TMakeDirectoryState(iOperation);
       
   152     }
       
   153 
       
   154 
       
   155 
       
   156 // Make directory
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CRsfwMkDirStateMachine::TMakeDirectoryState::TMakeDirectoryState
       
   160 // ----------------------------------------------------------------------------
       
   161 //    
       
   162 CRsfwMkDirStateMachine::
       
   163 TMakeDirectoryState::TMakeDirectoryState(CRsfwMkDirStateMachine* aParent)
       
   164     : iOperation(aParent)
       
   165     {
       
   166     }
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CRsfwMkDirStateMachine::TMakeDirectoryState::EnterL
       
   170 // ----------------------------------------------------------------------------
       
   171 //    
       
   172 void CRsfwMkDirStateMachine::TMakeDirectoryState::EnterL() 
       
   173     {
       
   174     // Make the directory
       
   175     if (!iOperation->FileEngine()->Disconnected())
       
   176         {
       
   177         HBufC* kidPath =
       
   178             iOperation->FileEngine()->FullNameLC(*iOperation->iKidFep);
       
   179         iOperation->FileEngine()->RemoteAccessL()->MakeDirectoryL(*kidPath,
       
   180                                                                   iOperation);
       
   181         CleanupStack::PopAndDestroy(kidPath);
       
   182         }
       
   183     }
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 // CRsfwMkDirStateMachine::TMakeDirectoryState::CompleteL
       
   187 // ----------------------------------------------------------------------------
       
   188 //    
       
   189 CRsfwMkDirStateMachine::TState*
       
   190 CRsfwMkDirStateMachine::TMakeDirectoryState::CompleteL()
       
   191     {
       
   192     iOperation->iKidFep->SetType(KNodeTypeDir);
       
   193     iOperation->FileEngine()->SetupAttributes(*iOperation->iKidFep);    
       
   194     
       
   195     // Attach the kid
       
   196     if (iOperation->iKidCreated)
       
   197         {
       
   198         iOperation->FileEngine()->iFileTable->AddL(iOperation->iKidFep);
       
   199         iOperation->Node()->AddKid(*iOperation->iKidFep);
       
   200         }
       
   201 
       
   202     // Create an empty container file locally
       
   203     iOperation->FileEngine()->CreateContainerFileL(*iOperation->iKidFep);
       
   204     iOperation->iKidFep->SetCached(ETrue);
       
   205     iOperation->iKidFep->SetAttribValidationTime();
       
   206    
       
   207     // Refresh parent directory next time it is accessed
       
   208     iOperation->Node()->SetLocallyDirty();
       
   209 
       
   210     return iOperation->CompleteRequestL(KErrNone);
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CRsfwMkDirStateMachine::TMakeDirectoryState::ErrorL
       
   215 // ----------------------------------------------------------------------------
       
   216 //    
       
   217 CRsfwMkDirStateMachine::TState*
       
   218 CRsfwMkDirStateMachine::TMakeDirectoryState::ErrorL(TInt aCode)
       
   219     {
       
   220     DEBUGSTRING(("remote mkdir failed!"));
       
   221     return iOperation->CompleteRequestL(aCode);
       
   222     }
       
   223