webengine/widgetregistry/Server/src/WidgetMMCHandler.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 "WidgetMMCHandler.h"
       
    21 #include "WidgetRegistry.h"
       
    22 
       
    23 // CONSTANTS
       
    24 LOG_NAMES( "widreg", "widrmmc.txt" )
       
    25 
       
    26 // ============================================================================
       
    27 // CWidgetMMCHandler::NewL()
       
    28 // two-phase constructor
       
    29 //
       
    30 // @since 3.1
       
    31 // @param aRegistry - Widget registry for callback.
       
    32 // @param aFs - file session
       
    33 // @return pointer to CWidgetMMCHandler
       
    34 // ============================================================================
       
    35 //
       
    36 CWidgetMMCHandler* CWidgetMMCHandler::NewL(
       
    37     CWidgetRegistry& aRegistry,
       
    38     RFs& aFs )
       
    39     {
       
    40     CWidgetMMCHandler* self =
       
    41         new(ELeave) CWidgetMMCHandler( aRegistry , aFs );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ============================================================================
       
    49 // CWidgetMMCHandler::CWidgetMMCHandler()
       
    50 // C++ default constructor
       
    51 //
       
    52 // @since 3.1
       
    53 // ============================================================================
       
    54 //
       
    55 CWidgetMMCHandler::CWidgetMMCHandler( CWidgetRegistry& aRegistry,
       
    56                                       RFs& aFs )
       
    57     : CActive( CActive::EPriorityStandard ),
       
    58       iRegistry( &aRegistry ),
       
    59       iFs( aFs ),
       
    60       iDriveFlags( 0 )
       
    61     {
       
    62     CActiveScheduler::Add( this );
       
    63     }
       
    64 
       
    65 // ============================================================================
       
    66 // CWidgetMMCHandler::ConstructL()
       
    67 // Symbian default constructor
       
    68 //
       
    69 // @since 3.1
       
    70 // ============================================================================
       
    71 //
       
    72 void CWidgetMMCHandler::ConstructL()
       
    73     {
       
    74     LOG_CONSTRUCTL;
       
    75     if ( KErrNone != ScanDrives( iDriveFlags ) )
       
    76         {
       
    77         iDriveFlags = 0;
       
    78         }
       
    79     }
       
    80 
       
    81 // ============================================================================
       
    82 // CWidgetMMCHandler::~CWidgetMMCHandler()
       
    83 // destructor
       
    84 //
       
    85 // @since 3.1
       
    86 // ============================================================================
       
    87 CWidgetMMCHandler::~CWidgetMMCHandler()
       
    88     {
       
    89     Cancel();
       
    90     LOG_DESTRUCT;
       
    91     }
       
    92 
       
    93 // ============================================================================
       
    94 // CWidgetMMCHandler::Start()
       
    95 // Start monitoring.
       
    96 //
       
    97 // @since 5.0
       
    98 // ============================================================================
       
    99 void CWidgetMMCHandler::Start()
       
   100     {
       
   101     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   102     SetActive();
       
   103     }
       
   104 
       
   105 // ============================================================================
       
   106 // CWidgetMMCHandler::RunL()
       
   107 // Handle notifications of MMC events.
       
   108 //
       
   109 // @since 3.1
       
   110 // ============================================================================
       
   111 void CWidgetMMCHandler::RunL()
       
   112     {
       
   113     LOG_OPEN;
       
   114     LOG1( "MMC notification status %d", iStatus.Int() );
       
   115 
       
   116     if ( iStatus == KErrNone )
       
   117       {
       
   118         TInt driveFlags = 0;
       
   119         TInt deltaDriveFlags = 0;
       
   120         if ( KErrNone == ScanDrives( driveFlags ) )
       
   121           {
       
   122             LOG1( " iDriveFlags 0x%x", iDriveFlags );
       
   123             LOG1( "  driveFlags 0x%x", driveFlags );
       
   124             deltaDriveFlags = iDriveFlags ^ driveFlags;
       
   125             LOG1( " deltaDriveFlags 0x%x", deltaDriveFlags );
       
   126             iDriveFlags = driveFlags;
       
   127           }
       
   128         if ( deltaDriveFlags )
       
   129           {
       
   130             LOG( " mmc start internalize" );
       
   131 
       
   132             LOG( " delay for appArch to sync with card" );
       
   133             // delay for appArch to sync with card (if don't wait then
       
   134             // when query AppArch about installed widgets, it doesn't
       
   135             // report any on card)
       
   136             User::After( 8000000 ); // 8 sec in microseconds
       
   137 
       
   138             TBool dirtyFlag = EFalse;
       
   139             TRAPD( error,
       
   140                    iRegistry->InternalizeL( dirtyFlag ) );
       
   141             LOG1( " mmc end internalize, error %d", error );
       
   142             if ( KErrNone == error )
       
   143                 {
       
   144                 LOG( " mmc notification internalize completed" );
       
   145                 // internalize consistency enforcement may have altered
       
   146                 // registry
       
   147                 if ( dirtyFlag )
       
   148                     {
       
   149                     TRAP_IGNORE( iRegistry->ExternalizeL(); );
       
   150                     }
       
   151                 }
       
   152           }
       
   153       }
       
   154     LOG( "MMC notification done" );
       
   155     LOG_CLOSE;
       
   156 
       
   157     iFs.NotifyChange( ENotifyDisk, iStatus );
       
   158     SetActive();
       
   159     }
       
   160 
       
   161 // ============================================================================
       
   162 // CWidgetMMCHandler::RunError()
       
   163 // Ignore errors from RunL.
       
   164 //
       
   165 // @since 5.0
       
   166 // ============================================================================
       
   167 TInt CWidgetMMCHandler::RunError( TInt /* aError */ )
       
   168     {
       
   169     LOG_CLOSE;
       
   170     return KErrNone; // indicates error was handled
       
   171     }
       
   172 
       
   173 // ============================================================================
       
   174 // CWidgetMMCHandler::DoCancel()
       
   175 // Cancel the MMC event handler
       
   176 //
       
   177 // @since 3.1
       
   178 // ============================================================================
       
   179 void CWidgetMMCHandler::DoCancel()
       
   180     {
       
   181     LOG_CLOSE;
       
   182     iFs.NotifyChangeCancel();
       
   183     }
       
   184 
       
   185 /* Scans drives and records a bit flag for those that exist and are
       
   186  * suitable for installing widgets to.
       
   187  */
       
   188 TInt CWidgetMMCHandler::ScanDrives( TInt& aDriveFlags )
       
   189     {
       
   190     LOG_OPEN;
       
   191     LOG( "ScanDrives" );
       
   192     // List all drives in the system
       
   193     TDriveList driveList;
       
   194     TInt error = iFs.DriveList( driveList );
       
   195     if ( KErrNone == error )
       
   196         {
       
   197         for ( TInt driveNumber = EDriveY;
       
   198               driveNumber >= EDriveA;
       
   199               driveNumber-- )
       
   200             {
       
   201             // The drives that will be filtered out are the same ones that
       
   202             // WidgetInstaller filters out in CWidgetUIHandler::SelectDriveL()
       
   203             if ( (EDriveD == driveNumber)
       
   204                  || !driveList[driveNumber] )
       
   205                 {
       
   206                 // EDriveD is a temporary drive usually a RAM disk
       
   207                 continue;
       
   208                 }
       
   209 
       
   210             TVolumeInfo volInfo;
       
   211             if ( iFs.Volume( volInfo, driveNumber ) != KErrNone )
       
   212                 {
       
   213                 // volume is not usable (e.g. no media card inserted)
       
   214                 continue;
       
   215                 }
       
   216             if ( (volInfo.iDrive.iType == EMediaNotPresent) ||
       
   217                  (volInfo.iDrive.iType == EMediaRom) ||
       
   218                  (volInfo.iDrive.iType == EMediaRemote) ||
       
   219                  (volInfo.iDrive.iDriveAtt & KDriveAttRom) ||
       
   220                  (volInfo.iDrive.iDriveAtt & KDriveAttSubsted) )
       
   221                 {
       
   222                 // not a suitable widget install drive
       
   223                 continue;
       
   224                 }
       
   225 
       
   226             // found a usable drive
       
   227             aDriveFlags |= (1 << driveNumber);
       
   228             LOG2( " drive %d, flags 0x%x", driveNumber, aDriveFlags );
       
   229             }
       
   230         }
       
   231     LOG1( "ScanDrives done, error %d", error );
       
   232     LOG_CLOSE;
       
   233     return error;
       
   234     }