webengine/wrtharvester/src/wrtusbhandler.cpp
branchRCL_3
changeset 48 79859ed3eea9
equal deleted inserted replaced
47:e1bea15f9a39 48:79859ed3eea9
       
     1 //
       
     2 // ============================================================================
       
     3 //  Name     : WidgetMMCHandler.cpp
       
     4 //  Part of  : SW Installer UIs / WidgetInstallerUI
       
     5 //
       
     6 //  Description: Handle notifications of MMC events.
       
     7 //
       
     8 //
       
     9 //  Version     : 3.1
       
    10 //
       
    11 //  Copyright © 2006 Nokia Corporation.
       
    12 //  This material, including documentation and any related
       
    13 //  computer programs, is protected by copyright controlled by
       
    14 //  Nokia Corporation. All rights are reserved. Copying,
       
    15 //  including reproducing, storing, adapting or translating, any
       
    16 //  or all of this material requires the prior written consent of
       
    17 //  Nokia Corporation. This material also contains confidential
       
    18 //  information which may not be disclosed to others without the
       
    19 //  prior written consent of Nokia Corporation.
       
    20 // ==============================================================================
       
    21 ///
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "wrtusbhandler.h"
       
    25 #include "wrtharvester.h"
       
    26 #include "wrtusbhandler.h"
       
    27 #include <driveinfo.h>
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 
       
    32 static TInt TimerCallBack( TAny* ptr )
       
    33 {    
       
    34     CWrtUsbHandler* temp = static_cast<CWrtUsbHandler*>(ptr);
       
    35     if(temp)
       
    36         {
       
    37         temp->DeleteTimer();
       
    38         temp->DoScanAndUpdate();       
       
    39         }
       
    40     return 0;    
       
    41 }
       
    42 // ============================================================================
       
    43 // CWrtUsbHandler::NewL()
       
    44 // two-phase constructor
       
    45 //
       
    46 // @since 3.1
       
    47 // @param aRegistry - Widget registry for callback.
       
    48 // @param aFs - file session
       
    49 // @return pointer to CWrtUsbHandler
       
    50 // ============================================================================
       
    51 //
       
    52 CWrtUsbHandler* CWrtUsbHandler::NewL(
       
    53     CWrtHarvester* aHarvester,
       
    54     RFs& aFs )
       
    55     {
       
    56     CWrtUsbHandler* self =
       
    57         new(ELeave) CWrtUsbHandler( aHarvester , aFs );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ============================================================================
       
    65 // CWrtUsbHandler::CWrtUsbHandler()
       
    66 // C++ default constructor
       
    67 //
       
    68 // @since 3.1
       
    69 // ============================================================================
       
    70 //
       
    71 CWrtUsbHandler::CWrtUsbHandler( CWrtHarvester* aHarvester,
       
    72                                       RFs& aFs )
       
    73     : CActive( CActive::EPriorityUserInput ),
       
    74       iHarvester( aHarvester ),
       
    75       iFs( aFs ),
       
    76       iDriveFlags( 0 )
       
    77     {
       
    78     CActiveScheduler::Add( this );
       
    79     }
       
    80 
       
    81 // ============================================================================
       
    82 // CWrtUsbHandler::ConstructL()
       
    83 // Symbian default constructor
       
    84 //
       
    85 // @since 3.1
       
    86 // ============================================================================
       
    87 //
       
    88 void CWrtUsbHandler::ConstructL()
       
    89     {
       
    90     if ( KErrNone != ScanDrives( iDriveFlags ) )
       
    91         {
       
    92         iDriveFlags = 0;
       
    93         }        
       
    94     }
       
    95 
       
    96 // ============================================================================
       
    97 // CWrtUsbHandler::~CWrtUsbHandler()
       
    98 // destructor
       
    99 //
       
   100 // @since 3.1
       
   101 // ============================================================================
       
   102 CWrtUsbHandler::~CWrtUsbHandler()
       
   103     {
       
   104     Cancel();
       
   105     }
       
   106 
       
   107 // ============================================================================
       
   108 // CWrtUsbHandler::Start()
       
   109 // Start monitoring.
       
   110 //
       
   111 // @since 5.0
       
   112 // ============================================================================
       
   113 void CWrtUsbHandler::Start()
       
   114     {
       
   115     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   116     SetActive();
       
   117     }
       
   118 
       
   119 // ============================================================================
       
   120 // CWrtUsbHandler::RunL()
       
   121 // Handle notifications of MMC events.
       
   122 //
       
   123 // @since 3.1
       
   124 // ============================================================================
       
   125 void CWrtUsbHandler::RunL()
       
   126     {
       
   127     if ( iStatus == KErrNone )
       
   128         {
       
   129         //Call back Timer
       
   130         iCallBackTimer = CPeriodic::NewL(CActive::EPriorityLow);
       
   131         iCallBackTimer->Start(10000000,0,TCallBack(&TimerCallBack,this));         
       
   132         }
       
   133     }
       
   134 
       
   135 void CWrtUsbHandler::DoScanAndUpdate()
       
   136     {
       
   137     TInt err = 0;
       
   138     TInt driveFlags = 0;
       
   139     TInt deltaDriveFlags = 0;
       
   140     if ( KErrNone == ScanDrives( driveFlags ) )
       
   141         {
       
   142         deltaDriveFlags = iDriveFlags ^ driveFlags;
       
   143         iDriveFlags = driveFlags;
       
   144         }
       
   145     
       
   146     if ( deltaDriveFlags )
       
   147         {           
       
   148         //Unpluging USB from Mass storage . . . 
       
   149         if(iHarvester->IsInMSMode() == 1)
       
   150             {                  
       
   151             iHarvester->SetMSMode(0);
       
   152             iHarvester->ClearAllOperations();
       
   153             TRAP(err, iHarvester->UpdateL() );            
       
   154             iFs.NotifyChange( ENotifyDisk, iStatus );
       
   155             SetActive();
       
   156             return;
       
   157             }
       
   158 
       
   159         TVolumeInfo volInfo;
       
   160         TInt temp = deltaDriveFlags;
       
   161         TBool massMemAltered = EFalse;        
       
   162         for(TInt DriveNo = EDriveA+1 ; DriveNo<=EDriveY; DriveNo++ )
       
   163             {   
       
   164             temp =  temp >> 1;
       
   165             if( temp & 01)
       
   166                 {
       
   167                 TUint status(0);
       
   168                 err = DriveInfo::GetDriveStatus( iFs, DriveNo , status );
       
   169                 if(!err && (status & DriveInfo::EDriveExternallyMountable) && (status & DriveInfo::EDriveInternal ))
       
   170                     {
       
   171                     //Internal Memory
       
   172                     massMemAltered = ETrue;
       
   173                     }                     
       
   174                 }            
       
   175             }
       
   176        if( massMemAltered )
       
   177            {           
       
   178            iHarvester->SetMSMode(1);            
       
   179            }
       
   180        
       
   181         TRAP( err, iHarvester->UpdateL() ); 
       
   182         }
       
   183     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   184     SetActive();
       
   185     }
       
   186 
       
   187 
       
   188 // ============================================================================
       
   189 // CWrtUsbHandler::RunError()
       
   190 // Ignore errors from RunL.
       
   191 //
       
   192 // @since 5.0
       
   193 // ============================================================================
       
   194 TInt CWrtUsbHandler::RunError( TInt /* aError */ )
       
   195     {
       
   196     return KErrNone; // indicates error was handled
       
   197     }
       
   198 
       
   199 // ============================================================================
       
   200 // CWrtUsbHandler::DoCancel()
       
   201 // Cancel the MMC event handler
       
   202 //
       
   203 // @since 3.1
       
   204 // ============================================================================
       
   205 void CWrtUsbHandler::DoCancel()
       
   206     {
       
   207     iFs.NotifyChangeCancel();
       
   208     }
       
   209 
       
   210 /* Scans drives and records a bit flag for those that exist and are
       
   211  * suitable for installing widgets to.
       
   212  */
       
   213 TInt CWrtUsbHandler::ScanDrives( TInt& aDriveFlags )
       
   214     {
       
   215     // List all drives in the system
       
   216     TDriveList driveList;
       
   217     TInt error = iFs.DriveList( driveList );
       
   218     if ( KErrNone == error )
       
   219         {
       
   220         for ( TInt driveNumber = EDriveY;
       
   221               driveNumber >= EDriveA;
       
   222               driveNumber-- )
       
   223             {
       
   224             // The drives that will be filtered out are the same ones that
       
   225             // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL()
       
   226             if ( (EDriveD == driveNumber)
       
   227                  || !driveList[driveNumber] )
       
   228                 {
       
   229                 // EDriveD is a temporary drive usually a RAM disk
       
   230                 continue;
       
   231                 }
       
   232 
       
   233             TVolumeInfo volInfo;
       
   234             if ( iFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   235                 {
       
   236                 // volume is not usable (e.g. no media card inserted)
       
   237                 continue;
       
   238                 }
       
   239             if ( (volInfo.iDrive.iType == EMediaNotPresent) ||
       
   240                  (volInfo.iDrive.iType == EMediaRom) ||
       
   241                  (volInfo.iDrive.iType == EMediaRemote) ||
       
   242                  (volInfo.iDrive.iDriveAtt & KDriveAttRom) ||
       
   243                  (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) )
       
   244                 {
       
   245                 // not a suitable widget install drive
       
   246                 continue;
       
   247                 }
       
   248 
       
   249             // found a usable drive
       
   250             aDriveFlags |= (1 << driveNumber);
       
   251           
       
   252             }
       
   253         }
       
   254 
       
   255     return error;
       
   256     }
       
   257 void CWrtUsbHandler::DeleteTimer()
       
   258     {
       
   259     iCallBackTimer->Cancel();
       
   260     delete iCallBackTimer;
       
   261     iCallBackTimer = NULL; 
       
   262     }