usbmgmt/usbmgr/host/functiondrivers/ms/msmm/server/src/msmmdismountusbdrives.cpp
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
       
     2 * Copyright (c) 2007-2010 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:  Active Object to dismount usb drives
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <usb/usblogger.h>
       
    20 #include <usb/hostms/srverr.h>
       
    21 #include <usb/hostms/msmmpolicypluginbase.h>
       
    22 
       
    23 #include "msmmdismountusbdrives.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "msmmdismountusbdrivesTraces.h"
       
    27 #endif
       
    28 
       
    29 
       
    30 const TInt KDismountTimeOut   = 6000000; // 6 seconds
       
    31 
       
    32 
       
    33 CMsmmDismountUsbDrives::~CMsmmDismountUsbDrives()
       
    34     {
       
    35     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_CMSMMDISMOUNTUSBDRIVES_DES_ENTRY );
       
    36     
       
    37     Cancel(); 
       
    38     delete iDismountTimer;    
       
    39     iRFs.Close();    
       
    40     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_CMSMMDISMOUNTUSBDRIVES_DES_EXIT );
       
    41     }
       
    42 
       
    43 /**
       
    44  * Symbian two phase constructor
       
    45  */
       
    46 CMsmmDismountUsbDrives* CMsmmDismountUsbDrives::NewL()
       
    47     {
       
    48     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_NEWL_ENTRY );
       
    49     
       
    50     CMsmmDismountUsbDrives* self = CMsmmDismountUsbDrives::NewLC();
       
    51     CleanupStack::Pop(self);    
       
    52     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_NEWL_EXIT );
       
    53     return self;
       
    54     }
       
    55 
       
    56 /**
       
    57  * Symbian two phase constructor. Object pushed to cleanup stack
       
    58  */
       
    59 CMsmmDismountUsbDrives* CMsmmDismountUsbDrives::NewLC()
       
    60     {
       
    61     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_NEWLC_ENTRY );
       
    62     
       
    63     CMsmmDismountUsbDrives* self = new (ELeave) CMsmmDismountUsbDrives();
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_NEWLC_EXIT );
       
    67     return self;
       
    68     }
       
    69 
       
    70 /**
       
    71  * Check the status of current dismount request and continue issuing next if no error
       
    72  */
       
    73 void CMsmmDismountUsbDrives::RunL()
       
    74     {
       
    75     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_RUNL_ENTRY );
       
    76     
       
    77     iDismountTimer->CancelTimer();    
       
    78     
       
    79     // Indicates there has been an error dismounting a usb drive, report immediately to MSMM plugin and 
       
    80     // abort the process
       
    81     if ( iStatus != KErrNone )
       
    82         {
       
    83         CompleteDismountRequest( iStatus.Int() );
       
    84         }
       
    85     // Indicates we have reached the end of all usb drives dismounting, in other words a success condition
       
    86     else if ( iDriveIndex == KMaxDrives )
       
    87         {
       
    88         CompleteDismountRequest( KErrNone );
       
    89         }
       
    90     // We still have more drives to traverse
       
    91     else if ( iDriveIndex < KMaxDrives )
       
    92         {
       
    93         DoDismount();
       
    94         }
       
    95     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_RUNL_EXIT );
       
    96     }
       
    97 
       
    98 /**
       
    99  * Cancel pending notifier and those in queue 
       
   100  */
       
   101 void CMsmmDismountUsbDrives::DoCancel()
       
   102     {
       
   103     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_DOCANCEL_ENTRY );
       
   104     
       
   105     iRFs.NotifyDismountCancel(iStatus);
       
   106     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_DOCANCEL_EXIT );
       
   107     }
       
   108 
       
   109 CMsmmDismountUsbDrives::CMsmmDismountUsbDrives()
       
   110     : CActive(EPriorityStandard)
       
   111     {
       
   112     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_CMSMMDISMOUNTUSBDRIVES_ENTRY );
       
   113     
       
   114     CActiveScheduler::Add(this);    
       
   115     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_CMSMMDISMOUNTUSBDRIVES_EXIT );
       
   116     }
       
   117 
       
   118 void CMsmmDismountUsbDrives::ConstructL()
       
   119     {
       
   120     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_CONSTRUCTL_ENTRY );
       
   121     
       
   122     User::LeaveIfError( iRFs.Connect());
       
   123     iDismountTimer = CDismountTimer::NewL(this);
       
   124     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_CONSTRUCTL_EXIT );
       
   125     }
       
   126 
       
   127 /**
       
   128  * Dismount usb drives
       
   129  */
       
   130 void CMsmmDismountUsbDrives::DismountUsbDrives(CMsmmPolicyPluginBase& aPlugin, TUSBMSDeviceDescription& aDevice)
       
   131     {    
       
   132     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_DISMOUNTUSBDRIVES_ENTRY );
       
   133     
       
   134     Cancel();
       
   135     iPlugin = &aPlugin;
       
   136     TUSBMSDeviceDescription& device = iDevicePkgInfo();
       
   137     device = aDevice;
       
   138     iDriveIndex = 0;
       
   139     iRFs.DriveList( iDriveList );
       
   140     DoDismount();
       
   141     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_DISMOUNTUSBDRIVES_EXIT );
       
   142     }
       
   143 
       
   144 /**
       
   145  * Callback to CMsmmPolicyPluginBase with either success or failure message
       
   146  */
       
   147 void CMsmmDismountUsbDrives::CompleteDismountRequest(const TInt aResult)
       
   148     {
       
   149     THostMsErrData data;
       
   150     if( aResult == KErrNone )
       
   151         data.iError = EHostMsErrNone;
       
   152     else
       
   153         data.iError = EHostMsErrInUse;
       
   154     data.iE32Error = aResult;
       
   155     data.iManufacturerString = iDevicePkgInfo().iManufacturerString;
       
   156     data.iProductString = iDevicePkgInfo().iProductString;
       
   157     data.iDriveName = 0x0;
       
   158    
       
   159     TRAP_IGNORE(iPlugin->SendErrorNotificationL(data));
       
   160     }
       
   161 
       
   162 /**
       
   163  * Dismount next usb drive
       
   164  */
       
   165 void CMsmmDismountUsbDrives::DoDismount()
       
   166     {
       
   167     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_DODISMOUNT_ENTRY );
       
   168        
       
   169     TDriveInfo info;
       
   170     TInt err = KErrNone;
       
   171     for ( ; iDriveIndex < KMaxDrives; iDriveIndex++ )
       
   172         {
       
   173         if ( iDriveList[iDriveIndex] )
       
   174             {
       
   175             err = iRFs.Drive( info , iDriveIndex );            
       
   176             if ( info.iConnectionBusType == EConnectionBusUsb &&                 
       
   177                  info.iDriveAtt & KDriveAttExternal && 
       
   178                  err == KErrNone  )
       
   179                 {
       
   180                 OstTrace0( TRACE_NORMAL, CMSMMDISMOUNTUSBDRIVES_DODISMOUNT, 
       
   181                         "CMsmmDismountUsbDrives::DoDismount Dismount notify request" );
       
   182                 iRFs.NotifyDismount( iDriveIndex, iStatus, EFsDismountNotifyClients );                
       
   183                 iDismountTimer->StartTimer();
       
   184                 SetActive();
       
   185                 OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_DODISMOUNT_EXIT );
       
   186                 return;
       
   187                 }                     
       
   188             }
       
   189         }
       
   190     // Indicates we have gone through all the drives and no more usb drives left to request dismount
       
   191     CompleteDismountRequest( KErrNone );
       
   192     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_DODISMOUNT_EXIT_DUP1 );
       
   193     }
       
   194 
       
   195 
       
   196 /**
       
   197  * Callback function from CDismountTimer after 6 seconds indicating a usb drive is not released by another process, report it as an error
       
   198  */
       
   199 void CMsmmDismountUsbDrives::TimerExpired()
       
   200     {
       
   201     OstTraceFunctionEntry0( CMSMMDISMOUNTUSBDRIVES_TIMEREXPIRED_ENTRY );
       
   202     
       
   203     Cancel();
       
   204     iDismountTimer->CancelTimer();    
       
   205     CompleteDismountRequest( KErrInUse );    
       
   206     OstTraceFunctionExit0( CMSMMDISMOUNTUSBDRIVES_TIMEREXPIRED_EXIT );
       
   207     }    
       
   208 
       
   209 //CDismountTimer
       
   210 
       
   211 CDismountTimer* CDismountTimer::NewL( MTimerNotifier* aTimeOutNotify)
       
   212     {
       
   213     OstTraceFunctionEntry0( CDISMOUNTTIMER_NEWL_ENTRY );
       
   214         
       
   215     CDismountTimer* self = CDismountTimer::NewLC( aTimeOutNotify );
       
   216     CleanupStack::Pop(self);
       
   217     OstTraceFunctionExit0( CDISMOUNTTIMER_NEWL_EXIT );
       
   218     return self;
       
   219     }
       
   220 
       
   221 CDismountTimer* CDismountTimer::NewLC( MTimerNotifier* aTimeOutNotify )
       
   222     {
       
   223     OstTraceFunctionEntry0( CDISMOUNTTIMER_NEWLC_ENTRY );
       
   224         
       
   225     CDismountTimer* self = new (ELeave) CDismountTimer( aTimeOutNotify );
       
   226     CleanupStack::PushL(self);
       
   227     self->ConstructL();
       
   228     OstTraceFunctionExit0( CDISMOUNTTIMER_NEWLC_EXIT );
       
   229     return self;
       
   230     }
       
   231 
       
   232 CDismountTimer::CDismountTimer( MTimerNotifier* aTimeOutNotify):
       
   233     CTimer(EPriorityStandard), 
       
   234     iNotify(aTimeOutNotify)    
       
   235     {
       
   236     OstTraceFunctionEntry0( CDISMOUNTTIMER_CDISMOUNTTIMER_CONS_ENTRY );
       
   237     }    
       
   238 
       
   239 CDismountTimer::~CDismountTimer()
       
   240     {
       
   241     OstTraceFunctionEntry0( CDISMOUNTTIMER_CDISMOUNTTIMER_DES_ENTRY );
       
   242     
       
   243     Cancel();
       
   244     OstTraceFunctionExit0( CDISMOUNTTIMER_CDISMOUNTTIMER_DES_EXIT );
       
   245     }
       
   246 
       
   247 void CDismountTimer::ConstructL()
       
   248     {
       
   249     OstTraceFunctionEntry0( CDISMOUNTTIMER_CONSTRUCTL_ENTRY );
       
   250         
       
   251     if ( !iNotify )    
       
   252         {
       
   253         User::Leave(KErrArgument);    
       
   254         }
       
   255     CTimer::ConstructL();
       
   256     CActiveScheduler::Add(this);
       
   257     OstTraceFunctionExit0( CDISMOUNTTIMER_CONSTRUCTL_EXIT );
       
   258     }
       
   259 
       
   260 void CDismountTimer::RunL()
       
   261     {
       
   262     OstTraceFunctionEntry0( CDISMOUNTTIMER_RUNL_ENTRY );
       
   263     
       
   264     // Timer request has completed, so notify the timer's owner
       
   265     iNotify->TimerExpired();
       
   266     OstTraceFunctionExit0( CDISMOUNTTIMER_RUNL_EXIT );
       
   267     }
       
   268 void CDismountTimer::CancelTimer()
       
   269     {
       
   270     OstTraceFunctionEntry0( CDISMOUNTTIMER_CANCELTIMER_ENTRY );
       
   271      
       
   272     Cancel();    
       
   273     OstTraceFunctionExit0( CDISMOUNTTIMER_CANCELTIMER_EXIT );
       
   274     }
       
   275 
       
   276 void CDismountTimer::StartTimer()
       
   277     {
       
   278     OstTraceFunctionEntry0( CDISMOUNTTIMER_STARTTIMER_ENTRY );
       
   279     
       
   280     After( KDismountTimeOut );  
       
   281     OstTraceFunctionExit0( CDISMOUNTTIMER_STARTTIMER_EXIT );
       
   282     }
       
   283 // End of File