remotestoragefw/remotefileengine/src/rsfwmountconnectionstatemachine.cpp
branchRCL_3
changeset 20 1aa8c82cb4cb
parent 0 3ad9d5175a89
equal deleted inserted replaced
19:88ee4cf65e19 20:1aa8c82cb4cb
       
     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 changing mount state, e.g. online->offline
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "rsfwmountconnectionstatemachine.h"
       
    20 #include "rsfwvolumetable.h"
       
    21 #include "rsfwfileengine.h"
       
    22 #include "rsfwfiletable.h"
       
    23 #include "rsfwlockmanager.h"
       
    24 #include "rsfwwaitnotemanager.h"
       
    25 #include "mdebug.h"
       
    26 #include "rsfwrfeserver.h"
       
    27 
       
    28 /**********************************************************
       
    29  * CRsfwMountConnectionStateMachine
       
    30  *
       
    31  * If connect to server fails, deletes the remote accessor 
       
    32  * (this comes from the way synch version fo CRsfwFileEngine::ConnectL() used to
       
    33  * to work, but I'm not quite sure how correct behaviour this is).
       
    34  * Note that EnteredConnectionState() in CompleteL
       
    35  * may start reintegration.
       
    36  * However instead of writing special reintegration states here
       
    37  * it is better to later implement a reintegration thred.
       
    38  *********************************************************/
       
    39 
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CRsfwMountConnectionStateMachine::CRsfwMountConnectionStateMachine
       
    43 // ----------------------------------------------------------------------------
       
    44 // 
       
    45 CRsfwMountConnectionStateMachine::CRsfwMountConnectionStateMachine(TChar aDriveLetter,
       
    46                                                            TUint aState)
       
    47     {
       
    48     iDriveLetter = aDriveLetter;
       
    49     iState = aState;
       
    50     }
       
    51 
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CRsfwMountConnectionStateMachine::TChangeConnectionState::TChangeConnectionState
       
    55 // ----------------------------------------------------------------------------
       
    56 //  
       
    57 CRsfwMountConnectionStateMachine::TChangeConnectionState::TChangeConnectionState(
       
    58     CRsfwMountConnectionStateMachine* aParent)
       
    59     : iOperation(aParent)
       
    60     {}
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CRsfwMountConnectionStateMachine::TChangeConnectionState::EnterL
       
    64 // ----------------------------------------------------------------------------
       
    65 // 
       
    66 void CRsfwMountConnectionStateMachine::TChangeConnectionState::EnterL()
       
    67     {   
       
    68     // The user has forced us to go offline/online
       
    69     iVolume =
       
    70         iOperation->Volumes()->VolumeByDriveLetter(iOperation->iDriveLetter);
       
    71     if (iVolume)
       
    72         {
       
    73         DEBUGSTRING(("Set state of volume %d to %d",
       
    74                      iVolume->iMountInfo.iMountStatus.iVolumeId,
       
    75                      iOperation->iState));
       
    76 
       
    77         // Note that eventually the volume state may differ
       
    78         // from the engine state
       
    79         if ((iVolume->iFileEngine->ConnectionState() == KMountStronglyConnected)
       
    80             && (iOperation->iState == KMountNotConnected))
       
    81             {
       
    82             // request to move from connected to disconnected state
       
    83             // warn user if this volume contains open files
       
    84            if (iVolume->iFileEngine->iFileTable->OpenFileCount() > 0) 
       
    85                 {
       
    86                 iOperation->Volumes()->WaitNoteManager()
       
    87                     ->StartWaitNoteL(ERemoteWarnDisconnect, iOperation);  
       
    88                 }
       
    89            else 
       
    90                 {
       
    91                 // actual move happens in CRsfwMountConnectionStateMachine::TChangeConnectionState::CompleteL
       
    92                 iOperation->HandleRemoteAccessResponse(0, KErrNone);     
       
    93                 }
       
    94             
       
    95             }
       
    96         else 
       
    97             {
       
    98             // currently setting mount state to Connected state not supported
       
    99             // but user is assumed to use Mount() instead
       
   100             // this used to work, but authentication options and retry dialogs
       
   101             // are now missing
       
   102             User::Leave(KErrNotSupported);                                
       
   103             }
       
   104         }
       
   105     else 
       
   106         {
       
   107         if (iOperation->iState == KMountNotConnected) 
       
   108             {
       
   109             // when volume is not yet found, we execute dormant mount
       
   110             TInt err;
       
   111             TInt drivenumber;
       
   112             TRsfwMountConfig mountConfig;
       
   113             CRsfwRfeServer::Env()->iFs.CharToDrive(iOperation->iDriveLetter, drivenumber);
       
   114             mountConfig.iDriveLetter = iOperation->iDriveLetter;
       
   115             err = iOperation->Volumes()->GetMountConfigL(mountConfig);
       
   116             if (!err) 
       
   117                 {
       
   118                 iOperation->Volumes()->MountDormantL(mountConfig, drivenumber);
       
   119                 iOperation->HandleRemoteAccessResponse(0, KErrNone);     
       
   120                 }
       
   121             else 
       
   122                 {
       
   123                 iOperation->HandleRemoteAccessResponse(0, err); 
       
   124                 }
       
   125             }
       
   126         else 
       
   127             {
       
   128             User::Leave(KErrNotSupported);  
       
   129             }
       
   130         }
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CRsfwMountConnectionStateMachine::TChangeConnectionState::CompleteL
       
   135 // ----------------------------------------------------------------------------
       
   136 //     
       
   137 CRsfwMountConnectionStateMachine::TState*
       
   138 CRsfwMountConnectionStateMachine::TChangeConnectionState::CompleteL()
       
   139     {  
       
   140     // from CRsfwFileEngine::RequestConnectionStateL
       
   141     if (iVolume && iVolume->iFileEngine) 
       
   142         {
       
   143         
       
   144         // we successfully disconnected
       
   145         iVolume->iFileEngine->RequestConnectionStateL(
       
   146                      KMountNotConnected,
       
   147                       NULL);
       
   148         
       
   149         if (iVolume->iFileEngine->ConnectionState() != iOperation->iState)
       
   150             {
       
   151             iVolume->iFileEngine->EnteredConnectionStateL(iOperation->iState, EFalse);
       
   152             }
       
   153         }
       
   154     
       
   155     if (iVolume) 
       
   156         {
       
   157         // from CRsfwVolumeTable::SetMountConnectionStateL  
       
   158         iVolume->iMountInfo.iMountStatus.iConnectionState =
       
   159             iVolume->iFileEngine->ConnectionState();     
       
   160         }
       
   161     
       
   162     return iOperation->CompleteRequestL(KErrNone);
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CRsfwMountConnectionStateMachine::TChangeConnectionState::ErrorL
       
   167 // ----------------------------------------------------------------------------
       
   168 // 
       
   169 CRsfwMountConnectionStateMachine::TState*
       
   170 CRsfwMountConnectionStateMachine::TChangeConnectionState::ErrorL(TInt aCode)
       
   171     {
       
   172     return iOperation->CompleteRequestL(aCode);
       
   173     }
       
   174