webengine/wrtharvester/src/wrtusbhandler.cpp
changeset 15 60c5402cb945
parent 11 c8a366e56285
child 18 a758fa0cb043
equal deleted inserted replaced
11:c8a366e56285 15:60c5402cb945
     1 /*
     1 //
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     2 // ============================================================================
     3 * All rights reserved.
     3 //  Name     : WidgetMMCHandler.cpp
     4 * This component and the accompanying materials are made available
     4 //  Part of  : SW Installer UIs / WidgetInstallerUI
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 //
     6 * which accompanies this distribution, and is available
     6 //  Description: Handle notifications of MMC events.
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 *
     8 //
     9 * Initial Contributors:
     9 //  Version     : 3.1
    10 * Nokia Corporation - initial contribution.
    10 //
    11 *
    11 //  Copyright © 2006 Nokia Corporation.
    12 * Contributors:
    12 //  This material, including documentation and any related
    13 *
    13 //  computer programs, is protected by copyright controlled by
    14 * Description:  Handle notifications of MMC events.
    14 //  Nokia Corporation. All rights are reserved. Copying,
    15 *
    15 //  including reproducing, storing, adapting or translating, any
    16 *
    16 //  or all of this material requires the prior written consent of
    17 *
    17 //  Nokia Corporation. This material also contains confidential
    18 */
    18 //  information which may not be disclosed to others without the
    19 
    19 //  prior written consent of Nokia Corporation.
       
    20 // ==============================================================================
       
    21 ///
       
    22 
       
    23 // INCLUDE FILES
    20 #include "wrtusbhandler.h"
    24 #include "wrtusbhandler.h"
    21 #include "wrtharvester.h"
    25 #include "wrtharvester.h"
    22 #include "wrtusbhandler.h"
    26 #include "wrtusbhandler.h"
       
    27 #include <DriveInfo.h>
    23 
    28 
    24 // CONSTANTS
    29 // CONSTANTS
    25 
    30 
    26 
    31 
    27 // ============================================================================
    32 static TInt TimerCallBack( TAny* ptr )
    28 // CWidgetMMCHandler::NewL()
    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()
    29 // two-phase constructor
    44 // two-phase constructor
    30 //
    45 //
    31 // @since 3.1
    46 // @since 3.1
    32 // @param aRegistry - Widget registry for callback.
    47 // @param aRegistry - Widget registry for callback.
    33 // @param aFs - file session
    48 // @param aFs - file session
    34 // @return pointer to CWidgetMMCHandler
    49 // @return pointer to CWrtUsbHandler
    35 // ============================================================================
    50 // ============================================================================
    36 //
    51 //
    37 CWidgetMMCHandler* CWidgetMMCHandler::NewL(
    52 CWrtUsbHandler* CWrtUsbHandler::NewL(
    38     CWrtHarvester* aHarvester,
    53     CWrtHarvester* aHarvester,
    39     RFs& aFs )
    54     RFs& aFs )
    40     {
    55     {
    41     CWidgetMMCHandler* self =
    56     CWrtUsbHandler* self =
    42         new(ELeave) CWidgetMMCHandler( aHarvester , aFs );
    57         new(ELeave) CWrtUsbHandler( aHarvester , aFs );
    43     CleanupStack::PushL( self );
    58     CleanupStack::PushL( self );
    44     self->ConstructL();
    59     self->ConstructL();
    45     CleanupStack::Pop( self );
    60     CleanupStack::Pop( self );
    46     return self;
    61     return self;
    47     }
    62     }
    48 
    63 
    49 // ============================================================================
    64 // ============================================================================
    50 // CWidgetMMCHandler::CWidgetMMCHandler()
    65 // CWrtUsbHandler::CWrtUsbHandler()
    51 // C++ default constructor
    66 // C++ default constructor
    52 //
    67 //
    53 // @since 3.1
    68 // @since 3.1
    54 // ============================================================================
    69 // ============================================================================
    55 //
    70 //
    56 CWidgetMMCHandler::CWidgetMMCHandler( CWrtHarvester* aHarvester,
    71 CWrtUsbHandler::CWrtUsbHandler( CWrtHarvester* aHarvester,
    57                                       RFs& aFs )
    72                                       RFs& aFs )
    58     : CActive( CActive::EPriorityUserInput ),
    73     : CActive( CActive::EPriorityUserInput ),
    59       iHarvester( aHarvester ),
    74       iHarvester( aHarvester ),
    60       iFs( aFs ),
    75       iFs( aFs ),
    61       iDriveFlags( 0 )
    76       iDriveFlags( 0 )
    62     {
    77     {
    63     CActiveScheduler::Add( this );
    78     CActiveScheduler::Add( this );
    64     }
    79     }
    65 
    80 
    66 // ============================================================================
    81 // ============================================================================
    67 // CWidgetMMCHandler::ConstructL()
    82 // CWrtUsbHandler::ConstructL()
    68 // Symbian default constructor
    83 // Symbian default constructor
    69 //
    84 //
    70 // @since 3.1
    85 // @since 3.1
    71 // ============================================================================
    86 // ============================================================================
    72 //
    87 //
    73 void CWidgetMMCHandler::ConstructL()
    88 void CWrtUsbHandler::ConstructL()
    74     {
    89     {
    75     if ( KErrNone != ScanDrives( iDriveFlags ) )
    90     if ( KErrNone != ScanDrives( iDriveFlags ) )
    76         {
    91         {
    77         iDriveFlags = 0;
    92         iDriveFlags = 0;
    78         }
    93         }        
    79         RDebug::Print(_L("iDriveFlags ConstructL() : %x %d"), iDriveFlags,iDriveFlags);
    94     }
    80     }
    95 
    81 
    96 // ============================================================================
    82 // ============================================================================
    97 // CWrtUsbHandler::~CWrtUsbHandler()
    83 // CWidgetMMCHandler::~CWidgetMMCHandler()
       
    84 // destructor
    98 // destructor
    85 //
    99 //
    86 // @since 3.1
   100 // @since 3.1
    87 // ============================================================================
   101 // ============================================================================
    88 CWidgetMMCHandler::~CWidgetMMCHandler()
   102 CWrtUsbHandler::~CWrtUsbHandler()
    89     {
   103     {
    90     Cancel();
   104     Cancel();
    91 
   105     }
    92     }
   106 
    93 
   107 // ============================================================================
    94 // ============================================================================
   108 // CWrtUsbHandler::Start()
    95 // CWidgetMMCHandler::Start()
       
    96 // Start monitoring.
   109 // Start monitoring.
    97 //
   110 //
    98 // @since 5.0
   111 // @since 5.0
    99 // ============================================================================
   112 // ============================================================================
   100 void CWidgetMMCHandler::Start()
   113 void CWrtUsbHandler::Start()
   101     {
   114     {
   102     iFs.NotifyChange( ENotifyDisk, iStatus );
   115     iFs.NotifyChange( ENotifyDisk, iStatus );
   103     SetActive();
   116     SetActive();
   104     }
   117     }
   105 
   118 
   106 // ============================================================================
   119 // ============================================================================
   107 // CWidgetMMCHandler::RunL()
   120 // CWrtUsbHandler::RunL()
   108 // Handle notifications of MMC events.
   121 // Handle notifications of MMC events.
   109 //
   122 //
   110 // @since 3.1
   123 // @since 3.1
   111 // ============================================================================
   124 // ============================================================================
   112 void CWidgetMMCHandler::RunL()
   125 void CWrtUsbHandler::RunL()
   113     {
   126     {
   114     if ( iStatus == KErrNone )
   127     if ( iStatus == KErrNone )
   115       {
   128         {
   116         TInt driveFlags = 0;
   129         //Call back Timer
   117         TInt deltaDriveFlags = 0;
   130         iCallBackTimer = CPeriodic::NewL(CActive::EPriorityLow);
   118       
   131         iCallBackTimer->Start(10000000,0,TCallBack(&TimerCallBack,this));         
   119 
   132         }
   120          User::After( 10000000 );
   133     }
   121          
   134 
   122        if ( KErrNone == ScanDrives( driveFlags ) )
   135 void CWrtUsbHandler::DoScanAndUpdate()
   123          {
   136     {
   124             deltaDriveFlags = iDriveFlags ^ driveFlags;
   137     TInt err = 0;
   125             
   138     TInt driveFlags = 0;
   126             iDriveFlags = driveFlags;
   139     TInt deltaDriveFlags = 0;
   127          }
   140     if ( KErrNone == ScanDrives( driveFlags ) )
   128         
   141         {
   129        if ( deltaDriveFlags )
   142         deltaDriveFlags = iDriveFlags ^ driveFlags;
   130           {
   143         iDriveFlags = driveFlags;
   131           //Unpluging USB from Mass storage . . . 
   144         }
   132           if(iHarvester->IsInMSMode() == 1)
   145     
   133             {
   146     if ( deltaDriveFlags )
   134              iHarvester->SetMSMode(0);
   147         {           
   135              iHarvester->ClearAllOperations();
   148         //Unpluging USB from Mass storage . . . 
   136              iHarvester->UpdateL();
   149         if(iHarvester->IsInMSMode() == 1)
   137              
   150             {                  
   138              iFs.NotifyChange( ENotifyDisk, iStatus );
   151             iHarvester->SetMSMode(0);
   139              SetActive();
   152             iHarvester->ClearAllOperations();
   140              return;
   153             TRAP(err, iHarvester->UpdateL() );            
       
   154             iFs.NotifyChange( ENotifyDisk, iStatus );
       
   155             SetActive();
       
   156             return;
   141             }
   157             }
   142 
   158 
   143           TVolumeInfo volInfo;
   159         TVolumeInfo volInfo;
   144           TInt temp = deltaDriveFlags;
   160         TInt temp = deltaDriveFlags;
   145           TBool massMemAltered = EFalse;
   161         TBool massMemAltered = EFalse;        
   146           TBool mmcAltered = EFalse;
   162         for(TInt DriveNo = EDriveA+1 ; DriveNo<=EDriveY; DriveNo++ )
   147           for(TInt DriveNo = EDriveA+1 ; DriveNo<=EDriveY; DriveNo++ )
   163             {   
   148             {
       
   149                 
       
   150             temp =  temp >> 1;
   164             temp =  temp >> 1;
   151             if( temp & 01)
   165             if( temp & 01)
   152               {
   166                 {
   153                 switch (DriveNo)
   167                 TUint status(0);
   154                   {
   168                 err = DriveInfo::GetDriveStatus( iFs, DriveNo , status );
   155                     case EDriveE :
   169                 if(!err && (status & DriveInfo::EDriveExternallyMountable) && (status & DriveInfo::EDriveInternal ))
   156                       {
   170                     {
   157                       massMemAltered = ETrue;   
   171                     //Internal Memory
   158                       break; 
   172                     massMemAltered = ETrue;
   159                       }
   173                     }                     
   160                     case EDriveF:
   174                 }            
   161                       {
       
   162                            
       
   163                       mmcAltered = ETrue;
       
   164                       break;
       
   165                       }
       
   166                          
       
   167                    }
       
   168               }
       
   169             
       
   170             }
   175             }
   171                      
   176        if( massMemAltered )
   172        if( !massMemAltered && mmcAltered)    
   177            {           
   173          {
   178            iHarvester->SetMSMode(1);            
   174           iHarvester->UpdateL();   
   179            }
   175          }
   180        
   176        else if( massMemAltered )
   181         TRAP( err, iHarvester->UpdateL() ); 
   177          {
   182         }
   178           iHarvester->SetMSMode(1);  
       
   179           iHarvester->UpdateL(); 
       
   180          }
       
   181 
       
   182         }
       
   183       }
       
   184       
       
   185       
       
   186     iFs.NotifyChange( ENotifyDisk, iStatus );
   183     iFs.NotifyChange( ENotifyDisk, iStatus );
   187     SetActive();
   184     SetActive();
   188     }
   185     }
   189 
   186 
   190 // ============================================================================
   187 
   191 // CWidgetMMCHandler::RunError()
   188 // ============================================================================
       
   189 // CWrtUsbHandler::RunError()
   192 // Ignore errors from RunL.
   190 // Ignore errors from RunL.
   193 //
   191 //
   194 // @since 5.0
   192 // @since 5.0
   195 // ============================================================================
   193 // ============================================================================
   196 TInt CWidgetMMCHandler::RunError( TInt /* aError */ )
   194 TInt CWrtUsbHandler::RunError( TInt /* aError */ )
   197     {
   195     {
   198 
       
   199     return KErrNone; // indicates error was handled
   196     return KErrNone; // indicates error was handled
   200     }
   197     }
   201 
   198 
   202 // ============================================================================
   199 // ============================================================================
   203 // CWidgetMMCHandler::DoCancel()
   200 // CWrtUsbHandler::DoCancel()
   204 // Cancel the MMC event handler
   201 // Cancel the MMC event handler
   205 //
   202 //
   206 // @since 3.1
   203 // @since 3.1
   207 // ============================================================================
   204 // ============================================================================
   208 void CWidgetMMCHandler::DoCancel()
   205 void CWrtUsbHandler::DoCancel()
   209     {
   206     {
   210 
       
   211     iFs.NotifyChangeCancel();
   207     iFs.NotifyChangeCancel();
   212     }
   208     }
   213 
   209 
   214 /* Scans drives and records a bit flag for those that exist and are
   210 /* Scans drives and records a bit flag for those that exist and are
   215  * suitable for installing widgets to.
   211  * suitable for installing widgets to.
   216  */
   212  */
   217 TInt CWidgetMMCHandler::ScanDrives( TInt& aDriveFlags )
   213 TInt CWrtUsbHandler::ScanDrives( TInt& aDriveFlags )
   218     {
   214     {
   219 
       
   220     // List all drives in the system
   215     // List all drives in the system
   221     TDriveList driveList;
   216     TDriveList driveList;
   222     TInt error = iFs.DriveList( driveList );
   217     TInt error = iFs.DriveList( driveList );
   223     if ( KErrNone == error )
   218     if ( KErrNone == error )
   224         {
   219         {
   257             }
   252             }
   258         }
   253         }
   259 
   254 
   260     return error;
   255     return error;
   261     }
   256     }
       
   257 void CWrtUsbHandler::DeleteTimer()
       
   258     {
       
   259     iCallBackTimer->Cancel();
       
   260     delete iCallBackTimer;
       
   261     iCallBackTimer = NULL; 
       
   262     }