webengine/wrtharvester/src/wrtusbhandler.cpp
changeset 11 c8a366e56285
child 15 60c5402cb945
equal deleted inserted replaced
10:a359256acfc6 11:c8a366e56285
       
     1 /*
       
     2 * Copyright (c) 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 the License "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:  Handle notifications of MMC events.
       
    15 *
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 #include "wrtusbhandler.h"
       
    21 #include "wrtharvester.h"
       
    22 #include "wrtusbhandler.h"
       
    23 
       
    24 // CONSTANTS
       
    25 
       
    26 
       
    27 // ============================================================================
       
    28 // CWidgetMMCHandler::NewL()
       
    29 // two-phase constructor
       
    30 //
       
    31 // @since 3.1
       
    32 // @param aRegistry - Widget registry for callback.
       
    33 // @param aFs - file session
       
    34 // @return pointer to CWidgetMMCHandler
       
    35 // ============================================================================
       
    36 //
       
    37 CWidgetMMCHandler* CWidgetMMCHandler::NewL(
       
    38     CWrtHarvester* aHarvester,
       
    39     RFs& aFs )
       
    40     {
       
    41     CWidgetMMCHandler* self =
       
    42         new(ELeave) CWidgetMMCHandler( aHarvester , aFs );
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ============================================================================
       
    50 // CWidgetMMCHandler::CWidgetMMCHandler()
       
    51 // C++ default constructor
       
    52 //
       
    53 // @since 3.1
       
    54 // ============================================================================
       
    55 //
       
    56 CWidgetMMCHandler::CWidgetMMCHandler( CWrtHarvester* aHarvester,
       
    57                                       RFs& aFs )
       
    58     : CActive( CActive::EPriorityUserInput ),
       
    59       iHarvester( aHarvester ),
       
    60       iFs( aFs ),
       
    61       iDriveFlags( 0 )
       
    62     {
       
    63     CActiveScheduler::Add( this );
       
    64     }
       
    65 
       
    66 // ============================================================================
       
    67 // CWidgetMMCHandler::ConstructL()
       
    68 // Symbian default constructor
       
    69 //
       
    70 // @since 3.1
       
    71 // ============================================================================
       
    72 //
       
    73 void CWidgetMMCHandler::ConstructL()
       
    74     {
       
    75     if ( KErrNone != ScanDrives( iDriveFlags ) )
       
    76         {
       
    77         iDriveFlags = 0;
       
    78         }
       
    79         RDebug::Print(_L("iDriveFlags ConstructL() : %x %d"), iDriveFlags,iDriveFlags);
       
    80     }
       
    81 
       
    82 // ============================================================================
       
    83 // CWidgetMMCHandler::~CWidgetMMCHandler()
       
    84 // destructor
       
    85 //
       
    86 // @since 3.1
       
    87 // ============================================================================
       
    88 CWidgetMMCHandler::~CWidgetMMCHandler()
       
    89     {
       
    90     Cancel();
       
    91 
       
    92     }
       
    93 
       
    94 // ============================================================================
       
    95 // CWidgetMMCHandler::Start()
       
    96 // Start monitoring.
       
    97 //
       
    98 // @since 5.0
       
    99 // ============================================================================
       
   100 void CWidgetMMCHandler::Start()
       
   101     {
       
   102     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   103     SetActive();
       
   104     }
       
   105 
       
   106 // ============================================================================
       
   107 // CWidgetMMCHandler::RunL()
       
   108 // Handle notifications of MMC events.
       
   109 //
       
   110 // @since 3.1
       
   111 // ============================================================================
       
   112 void CWidgetMMCHandler::RunL()
       
   113     {
       
   114     if ( iStatus == KErrNone )
       
   115       {
       
   116         TInt driveFlags = 0;
       
   117         TInt deltaDriveFlags = 0;
       
   118       
       
   119 
       
   120          User::After( 10000000 );
       
   121          
       
   122        if ( KErrNone == ScanDrives( driveFlags ) )
       
   123          {
       
   124             deltaDriveFlags = iDriveFlags ^ driveFlags;
       
   125             
       
   126             iDriveFlags = driveFlags;
       
   127          }
       
   128         
       
   129        if ( deltaDriveFlags )
       
   130           {
       
   131           //Unpluging USB from Mass storage . . . 
       
   132           if(iHarvester->IsInMSMode() == 1)
       
   133             {
       
   134              iHarvester->SetMSMode(0);
       
   135              iHarvester->ClearAllOperations();
       
   136              iHarvester->UpdateL();
       
   137              
       
   138              iFs.NotifyChange( ENotifyDisk, iStatus );
       
   139              SetActive();
       
   140              return;
       
   141             }
       
   142 
       
   143           TVolumeInfo volInfo;
       
   144           TInt temp = deltaDriveFlags;
       
   145           TBool massMemAltered = EFalse;
       
   146           TBool mmcAltered = EFalse;
       
   147           for(TInt DriveNo = EDriveA+1 ; DriveNo<=EDriveY; DriveNo++ )
       
   148             {
       
   149                 
       
   150             temp =  temp >> 1;
       
   151             if( temp & 01)
       
   152               {
       
   153                 switch (DriveNo)
       
   154                   {
       
   155                     case EDriveE :
       
   156                       {
       
   157                       massMemAltered = ETrue;   
       
   158                       break; 
       
   159                       }
       
   160                     case EDriveF:
       
   161                       {
       
   162                            
       
   163                       mmcAltered = ETrue;
       
   164                       break;
       
   165                       }
       
   166                          
       
   167                    }
       
   168               }
       
   169             
       
   170             }
       
   171                      
       
   172        if( !massMemAltered && mmcAltered)    
       
   173          {
       
   174           iHarvester->UpdateL();   
       
   175          }
       
   176        else if( massMemAltered )
       
   177          {
       
   178           iHarvester->SetMSMode(1);  
       
   179           iHarvester->UpdateL(); 
       
   180          }
       
   181 
       
   182         }
       
   183       }
       
   184       
       
   185       
       
   186     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   187     SetActive();
       
   188     }
       
   189 
       
   190 // ============================================================================
       
   191 // CWidgetMMCHandler::RunError()
       
   192 // Ignore errors from RunL.
       
   193 //
       
   194 // @since 5.0
       
   195 // ============================================================================
       
   196 TInt CWidgetMMCHandler::RunError( TInt /* aError */ )
       
   197     {
       
   198 
       
   199     return KErrNone; // indicates error was handled
       
   200     }
       
   201 
       
   202 // ============================================================================
       
   203 // CWidgetMMCHandler::DoCancel()
       
   204 // Cancel the MMC event handler
       
   205 //
       
   206 // @since 3.1
       
   207 // ============================================================================
       
   208 void CWidgetMMCHandler::DoCancel()
       
   209     {
       
   210 
       
   211     iFs.NotifyChangeCancel();
       
   212     }
       
   213 
       
   214 /* Scans drives and records a bit flag for those that exist and are
       
   215  * suitable for installing widgets to.
       
   216  */
       
   217 TInt CWidgetMMCHandler::ScanDrives( TInt& aDriveFlags )
       
   218     {
       
   219 
       
   220     // List all drives in the system
       
   221     TDriveList driveList;
       
   222     TInt error = iFs.DriveList( driveList );
       
   223     if ( KErrNone == error )
       
   224         {
       
   225         for ( TInt driveNumber = EDriveY;
       
   226               driveNumber >= EDriveA;
       
   227               driveNumber-- )
       
   228             {
       
   229             // The drives that will be filtered out are the same ones that
       
   230             // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL()
       
   231             if ( (EDriveD == driveNumber)
       
   232                  || !driveList[driveNumber] )
       
   233                 {
       
   234                 // EDriveD is a temporary drive usually a RAM disk
       
   235                 continue;
       
   236                 }
       
   237 
       
   238             TVolumeInfo volInfo;
       
   239             if ( iFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   240                 {
       
   241                 // volume is not usable (e.g. no media card inserted)
       
   242                 continue;
       
   243                 }
       
   244             if ( (volInfo.iDrive.iType == EMediaNotPresent) ||
       
   245                  (volInfo.iDrive.iType == EMediaRom) ||
       
   246                  (volInfo.iDrive.iType == EMediaRemote) ||
       
   247                  (volInfo.iDrive.iDriveAtt & KDriveAttRom) ||
       
   248                  (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) )
       
   249                 {
       
   250                 // not a suitable widget install drive
       
   251                 continue;
       
   252                 }
       
   253 
       
   254             // found a usable drive
       
   255             aDriveFlags |= (1 << driveNumber);
       
   256           
       
   257             }
       
   258         }
       
   259 
       
   260     return error;
       
   261     }