contentstorage/casrv/cawidgetscanner/src/cawidgetmmcwatcher.cpp
changeset 66 32469d7d46ff
parent 61 8e5041d13c84
child 73 4bc7b118b3df
equal deleted inserted replaced
61:8e5041d13c84 66:32469d7d46ff
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15  *
       
    16 */
       
    17 
       
    18 #include <driveinfo.h>
       
    19 
       
    20 #include "cawidgetmmcwatcher.h"
       
    21 
       
    22 // ================= MEMBER FUNCTIONS =======================
       
    23 
       
    24 // ---------------------------------------------------------
       
    25 // CCaWidgetMmcWatcher::NewL
       
    26 // Second phase constructor
       
    27 // ---------------------------------------------------------
       
    28 //
       
    29 CCaWidgetMmcWatcher* CCaWidgetMmcWatcher::NewL( RFs& aFs, 
       
    30         MWidgetMmcWatcherCallback* aObserver )
       
    31     {
       
    32     CCaWidgetMmcWatcher* self = NewLC( aFs, aObserver );
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36     
       
    37 // ---------------------------------------------------------
       
    38 // CCaWidgetMmcWatcher::NewLC
       
    39 // Second phase constructor
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 CCaWidgetMmcWatcher* CCaWidgetMmcWatcher::NewLC( RFs& aFs,
       
    43         MWidgetMmcWatcherCallback* aObserver )
       
    44     {
       
    45     CCaWidgetMmcWatcher* self = new (ELeave) CCaWidgetMmcWatcher( aFs, 
       
    46             aObserver );
       
    47     CleanupStack::PushL ( self );
       
    48     self->ConstructL();
       
    49     return self;
       
    50     }
       
    51     
       
    52 // ---------------------------------------------------------
       
    53 // CCaWidgetMmcWatcher::~CCaWidgetMmcWatcher
       
    54 // Destructor
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CCaWidgetMmcWatcher::~CCaWidgetMmcWatcher()
       
    58     {    
       
    59     Cancel();
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CCaWidgetMmcWatcher::CCaWidgetMmcWatcher
       
    64 // Default constructor
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CCaWidgetMmcWatcher::CCaWidgetMmcWatcher( RFs& aFs,
       
    68         MWidgetMmcWatcherCallback* aObserver )
       
    69     : CActive( CActive::EPriorityStandard ),
       
    70     iFs(aFs),
       
    71     iObserver(aObserver)
       
    72     {
       
    73     CActiveScheduler::Add(this);
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CCaWidgetMmcWatcher::ConstructL
       
    78 // default Symbian OS constructor
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CCaWidgetMmcWatcher::ConstructL()
       
    82     {
       
    83     WaitForChangeL();
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CCaWidgetMmcWatcher::WaitForChangeL
       
    88 // Request notification for disk change
       
    89 // ---------------------------------------------------------
       
    90 //    
       
    91 void CCaWidgetMmcWatcher::WaitForChangeL()
       
    92     {
       
    93     TInt mmcDrive;
       
    94     User::LeaveIfError( DriveInfo::GetDefaultDrive(
       
    95         DriveInfo::EDefaultRemovableMassStorage, mmcDrive ) );
       
    96     TDriveName mmcDriveName( TDriveUnit( mmcDrive ).Name() );
       
    97     iFs.NotifyChange( ENotifyEntry, iStatus, mmcDriveName );
       
    98     SetActive();
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------
       
   102 // CCaWidgetMmcWatcher::DoCancel
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 void CCaWidgetMmcWatcher::DoCancel()
       
   106     {
       
   107     iFs.NotifyChangeCancel();
       
   108     }
       
   109     
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCaWidgetMmcWatcher::RunError
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TInt CCaWidgetMmcWatcher::RunError( TInt /*aError*/ )
       
   115     {
       
   116     // No need to do anything  
       
   117     return KErrNone;
       
   118     }    
       
   119 
       
   120 // ---------------------------------------------------------
       
   121 // CCaWidgetMmcWatcher::RunL
       
   122 // ---------------------------------------------------------
       
   123 //    
       
   124 void CCaWidgetMmcWatcher::RunL()
       
   125     {
       
   126     TInt status( iStatus.Int() );
       
   127     WaitForChangeL();
       
   128     if ( status >= KErrNone ) 
       
   129         {
       
   130         iObserver->MmcChangeL();
       
   131         }
       
   132     }
       
   133