harvesterplugins/media/mediautils/src/mmcmonitor.cpp
changeset 0 ccd0fd43f247
child 2 208a4ba3894c
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     1 /*
       
     2 * Copyright (c) 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:  Mmc monitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "mmcmonitor.h"
       
    21 #include "harvesterserverlogger.h"
       
    22 
       
    23 #include <pathinfo.h>
       
    24 #include <s32file.h>
       
    25 #include <f32file.h> // TDriveNumber
       
    26 #include <driveinfo.h> // TDriveInfo
       
    27 
       
    28 #include <uikoninternalpskeys.h>
       
    29 
       
    30 // CONSTANTS
       
    31 // 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CMMCMonitorUtil::NewL
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CMMCMonitorUtil* CMMCMonitorUtil::NewL( MMMCEventObserver* aObserver)
       
    40     {
       
    41     CMMCMonitorUtil* self = new ( ELeave ) CMMCMonitorUtil( aObserver );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CMMCMonitorUtil::CMMCMonitorUtil
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMMCMonitorUtil::CMMCMonitorUtil( MMMCEventObserver* aObserver )
       
    54     : CActive( CActive::EPriorityStandard ),
       
    55       iObserver( aObserver )
       
    56     {
       
    57     CPIXLOGSTRING("ENTER CMMCMonitorUtil::CMMCMonitorUtil");
       
    58     CActiveScheduler::Add( this );
       
    59     CPIXLOGSTRING("END CMMCMonitorUtil::CMMCMonitorUtil");
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CMMCMonitorUtil::~CMMCMonitorUtil
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CMMCMonitorUtil::~CMMCMonitorUtil()
       
    68     {
       
    69     CPIXLOGSTRING("ENTER ~CMMCMonitorUtil");
       
    70     Cancel();
       
    71     iProperty.Close();
       
    72     CPIXLOGSTRING("END ~CMMCMonitorUtil");
       
    73     }
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CMMCMonitorUtil::ConstructL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CMMCMonitorUtil::ConstructL()
       
    81     {
       
    82     CPIXLOGSTRING("ENTER CMMCMonitorUtil::ConstructL Foobar");
       
    83     User::LeaveIfError(iFsSession.Connect());    
       
    84     TInt error = iProperty.Attach( KPSUidUikon, KUikMMCInserted );
       
    85     if ( error != KErrNone ) CPIXLOGSTRING("END CMMCMonitorUtil::Attach to MMCInserted failed");
       
    86     
       
    87     error = iProperty.Get( KPSUidUikon, KUikMMCInserted, iMmcStatus );
       
    88     if ( error != KErrNone ) 
       
    89     	{
       
    90 		CPIXLOGSTRING("CMMCMonitorUtil::Get MMCInserted failed");
       
    91     	} 
       
    92     else if ( iMmcStatus ) 	 
       
    93     	{
       
    94     	CPIXLOGSTRING("CMMCMonitorUtil::MMC card is in");
       
    95     	}
       
    96     else 
       
    97     	{
       
    98     	CPIXLOGSTRING("CMMCMonitorUtil::no MMC card");
       
    99     	}
       
   100     CPIXLOGSTRING("END CMMCMonitorUtil::ConstructL");
       
   101     }
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CMMCMonitorUtil::StartMonitoring
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 TBool CMMCMonitorUtil::StartMonitoring()
       
   109     {
       
   110     CPIXLOGSTRING("ENTER CMMCMonitorUtil::StartMonitoring");
       
   111     //Subscribe for property value change once modified get update      
       
   112     iStatus = KRequestPending;
       
   113     iProperty.Subscribe( iStatus );
       
   114     SetActive();
       
   115     CPIXLOGSTRING("END CMMCMonitorUtil::StartMonitoring");
       
   116     return ETrue;
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CMMCMonitorUtil::MmcStatus
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 TBool CMMCMonitorUtil::MmcStatus( TInt aDriveNumber )
       
   125     {
       
   126     TBool isMmcPresent(EFalse);
       
   127 
       
   128     if ( iFsSession.IsValidDrive( aDriveNumber ) )
       
   129         {
       
   130         TUint drvStatus( 0 );
       
   131         TInt err = DriveInfo::GetDriveStatus( iFsSession, aDriveNumber, drvStatus );
       
   132         if ( err )
       
   133             {
       
   134             return EFalse;
       
   135             }
       
   136         // MMC drives are removable and user visible
       
   137         if ( ( drvStatus & DriveInfo::EDriveRemovable ) &&
       
   138              ( drvStatus & DriveInfo::EDriveUserVisible ) )
       
   139                 {
       
   140                 CPIXLOGSTRING2("CMMCMonitorUtil::MmcStatus Drive Number %d", aDriveNumber);
       
   141                 isMmcPresent = ETrue;
       
   142                 }
       
   143         }
       
   144     return isMmcPresent;
       
   145     }
       
   146 
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CMMCMonitorUtil::RunError
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TInt CMMCMonitorUtil::RunError( TInt aError )
       
   153     {
       
   154     CPIXLOGSTRING2("CMMCMonitorUtil::RunError Error:",aError);
       
   155     return KErrNone;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMMCMonitorUtil::DoCancel
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CMMCMonitorUtil::DoCancel()
       
   164     {
       
   165     CPIXLOGSTRING("ENTER CMMCMonitorUtil::DoCancel");
       
   166     iProperty.Cancel();
       
   167     CPIXLOGSTRING("END CMMCMonitorUtil::DoCancel");
       
   168     }
       
   169 
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CMMCMonitorUtil::RunL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 void CMMCMonitorUtil::RunL()
       
   176     {
       
   177     CPIXLOGSTRING("ENTER CMMCMonitorUtil::RunL");
       
   178     iProperty.Subscribe( iStatus );
       
   179     SetActive();
       
   180     User::LeaveIfError( iProperty.Get( KPSUidUikon, KUikMMCInserted, iMmcStatus ) );
       
   181     
       
   182     if ( iMmcStatus )
       
   183     	{
       
   184     	CPIXLOGSTRING("CMMCMonitorUtil::MMC card is in");
       
   185     	}
       
   186     else 
       
   187     	{
       
   188 		CPIXLOGSTRING("CMMCMonitorUtil::no MMC card");
       
   189     	}
       
   190 
       
   191     for ( TInt driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ )
       
   192         {
       
   193         const TBool foundMmc = MmcStatus( driveNumber );
       
   194         if ( !foundMmc )
       
   195             {
       
   196             continue;
       
   197             }
       
   198 
       
   199         // This drive has been recognized as MMC. 
       
   200         TDriveNumber drv = TDriveNumber( driveNumber );
       
   201 
       
   202         TUint drvStatus( 0 );
       
   203 
       
   204         const TInt err = DriveInfo::GetDriveStatus( iFsSession, driveNumber, drvStatus );
       
   205         if ( err ) 
       
   206             {
       
   207             continue;  // should not happen
       
   208             }
       
   209 
       
   210         if ( drvStatus & DriveInfo::EDrivePresent )
       
   211             {
       
   212             CPIXLOGSTRING("CMMCMonitorUtil::RunL insert event");
       
   213             // Notify observer for handleing event
       
   214             iObserver->HandleMMCEventL(drv,ETrue);
       
   215             }
       
   216         else
       
   217             {
       
   218             CPIXLOGSTRING("CMMCMonitorUtil::RunL eject event");
       
   219             // If the MMC has been ejected, then need to dismount 
       
   220             // Notify observer for handleing event
       
   221             iObserver->HandleMMCEventL(drv,EFalse);
       
   222             }
       
   223         }
       
   224     CPIXLOGSTRING("END CMMCMonitorUtil::RunL");
       
   225     }
       
   226 
       
   227 // End Of File