voicerecorder/RecViewSrc/CVRMediaRemovalMonitor.cpp
branchRCL_3
changeset 21 c6bafb5162d8
parent 10 bb90e4148332
equal deleted inserted replaced
20:072a5fa0c63b 21:c6bafb5162d8
       
     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 "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:  Monitors for Media removal
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <f32file.h>
       
    21 #include "CVRMediaRemovalMonitor.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // C++ Constructor
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CVRMediaRemovalMonitor::CVRMediaRemovalMonitor
       
    28                   ( TInt aDrive, RFs& aFs, MVRMediaRemovalObserver* aObserver ) 
       
    29                                                        : CActive(EPriorityHigh),
       
    30                                                          iDrive( aDrive ),
       
    31                                                          iFs( aFs ),
       
    32                                                          iDiskRemoved( EFalse ),
       
    33                                                          iObserver( aObserver )
       
    34                                                          
       
    35     {
       
    36     CActiveScheduler::Add(this);
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // 2nd Phase Constructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CVRMediaRemovalMonitor::ConstructL()
       
    45     {
       
    46  
       
    47     // Initial state
       
    48     TDriveInfo drive;
       
    49   	User::LeaveIfError(iFs.Drive(drive, TInt(iDrive)));
       
    50    	iDiskRemoved = (drive.iType == EMediaNotPresent);
       
    51 
       
    52     // Start listening
       
    53     TNotifyType notType(ENotifyDisk);
       
    54     iFs.NotifyChange( notType, iStatus );
       
    55     SetActive();
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Two-Phased Constructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CVRMediaRemovalMonitor* CVRMediaRemovalMonitor::NewL
       
    64                 ( TInt aDrive, RFs& aFs, MVRMediaRemovalObserver* aObserver )
       
    65     {
       
    66     CVRMediaRemovalMonitor* self
       
    67                                = CVRMediaRemovalMonitor::NewLC( aDrive,
       
    68                                                                  aFs,
       
    69                                                                  aObserver );
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // Two-Phased Constructor
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CVRMediaRemovalMonitor* CVRMediaRemovalMonitor::NewLC
       
    80                ( TInt aDrive, RFs& aFs, MVRMediaRemovalObserver* aObserver )
       
    81     {
       
    82     CVRMediaRemovalMonitor* self = 
       
    83                           new( ELeave ) CVRMediaRemovalMonitor( aDrive,
       
    84                                                                  aFs,
       
    85                                                                  aObserver );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // Destructor
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 CVRMediaRemovalMonitor::~CVRMediaRemovalMonitor()
       
    97     {
       
    98     Cancel();
       
    99     }
       
   100 
       
   101     
       
   102 // ---------------------------------------------------------------------------
       
   103 // Service the request
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CVRMediaRemovalMonitor::RunL()
       
   107     {
       
   108     // Re-subscribe to event.
       
   109     TNotifyType notType(ENotifyDisk);
       
   110     iFs.NotifyChange( notType, iStatus );
       
   111     SetActive();
       
   112     
       
   113     // Check state
       
   114     TDriveInfo drive;
       
   115 	User::LeaveIfError(iFs.Drive(drive, TInt(iDrive)));
       
   116 	
       
   117 	  // Notify Observer
       
   118     switch(drive.iType)
       
   119         {
       
   120         case EMediaNotPresent:
       
   121             {
       
   122             if (!iDiskRemoved)
       
   123                 {
       
   124                 iObserver->HandleMMCEjectEventL( );
       
   125                 }
       
   126                 iDiskRemoved = ETrue;
       
   127             break;
       
   128             }
       
   129         default:
       
   130             {
       
   131             if ( iDiskRemoved &&
       
   132         		 ( drive.iMediaAtt & ( KMediaAttLockable|KMediaAttLocked|KMediaAttHasPassword ) ) != 
       
   133  				 ( KMediaAttLockable|KMediaAttLocked|KMediaAttHasPassword ) ) 
       
   134                 {
       
   135                 //do nothing
       
   136                 iDiskRemoved = EFalse;
       
   137                 }
       
   138             break;
       
   139             }
       
   140         }
       
   141     
       
   142     }
       
   143     
       
   144 // ---------------------------------------------------------------------------
       
   145 // Cancel NotifyChange request from file system
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CVRMediaRemovalMonitor::DoCancel()
       
   149     {
       
   150     iFs.NotifyChangeCancel();
       
   151     }
       
   152     
       
   153 // ----------------------------------------------------------------------------
       
   154 // Handles a leave occurring in the request completion event handler RunL()
       
   155 // Don't care if client has a User::Leave() in RunL(), keep monitoring for events
       
   156 // ----------------------------------------------------------------------------
       
   157 //
       
   158 TInt CVRMediaRemovalMonitor::RunError(TInt aError)
       
   159     {
       
   160     return KErrNone;
       
   161     }