commonservices/PlatformEnv/disknotifyhandler/src/dismountwatcher.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Class for dismount watcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include <e32std.h>
       
    21 #include <f32file.h>
       
    22 #include "dismountwatcher.h"
       
    23 #include "disknotifyhandler.h"
       
    24 #include "disknotifyhandlerdebug.h"
       
    25 
       
    26 
       
    27 // ======== LOCAL FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // SetEvent
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 inline static void SetEvent(
       
    34         MDiskNotifyHandlerCallback::TDismountEvent& aEvent,
       
    35         TInt aDrive )
       
    36     {
       
    37     aEvent.iDrive = aDrive;
       
    38     }
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CDismountWatcher::CDismountWatcher
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CDismountWatcher::CDismountWatcher(
       
    48         MDiskNotifyHandlerCallback& aCallback,
       
    49         RFs& aFs,
       
    50         RPointerArray< CDismountWatcher >& aWatcherList,
       
    51         TInt aDrive ) :
       
    52     CDiskWatcherBase( aCallback, aFs ),
       
    53     iWatcherList( aWatcherList ),
       
    54     iDrive( aDrive )
       
    55     {
       
    56     FUNC_LOG
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CDismountWatcher::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CDismountWatcher::ConstructL()
       
    64     {
       
    65     FUNC_LOG
       
    66 
       
    67     iWatcherList.InsertInOrderL( this, CompareFindObject );
       
    68     Activate();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CDismountWatcher::NewL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CDismountWatcher* CDismountWatcher::NewL(
       
    76         MDiskNotifyHandlerCallback& aCallback,
       
    77         RFs& aFs,
       
    78         RPointerArray< CDismountWatcher >& aWatcherList,
       
    79         TInt aDrive )
       
    80     {
       
    81     FUNC_LOG
       
    82 
       
    83     CDismountWatcher* self = new ( ELeave ) CDismountWatcher(
       
    84         aCallback, aFs, aWatcherList, aDrive );
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop( self );
       
    88     return self;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CDismountWatcher::~CDismountWatcher
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CDismountWatcher::~CDismountWatcher()
       
    96     {
       
    97     FUNC_LOG
       
    98 
       
    99     Cancel();
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CDismountWatcher::CompareFind
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 TInt CDismountWatcher::CompareFind(
       
   107         const TInt* aDrive,
       
   108         const CDismountWatcher& aWatcher )
       
   109     {
       
   110     return Compare( *aDrive, aWatcher.iDrive );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CDismountWatcher::CompareFindObject
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TInt CDismountWatcher::CompareFindObject(
       
   118         const CDismountWatcher& aWatcher1,
       
   119         const CDismountWatcher& aWatcher2 )
       
   120     {
       
   121     return Compare( aWatcher1.iDrive, aWatcher2.iDrive );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CDismountWatcher::WatcherError
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CDismountWatcher::WatcherError(
       
   129         TInt aError,
       
   130         const TBool& aKilled )
       
   131     {
       
   132     FUNC_LOG
       
   133 
       
   134     LOG_IF_ERROR2(
       
   135         aError,
       
   136         "CDismountWatcher::WatcherError-iDrive=%d,aError=%d",
       
   137         iDrive, aError )
       
   138 
       
   139     MDiskNotifyHandlerCallback::TDismountEvent event;
       
   140     SetEvent( event, iDrive );
       
   141     Callback().HandleNotifyDismount( aError, event );
       
   142     if ( aKilled )
       
   143         {
       
   144         return;
       
   145         }
       
   146     // Remove useless watcher if not manually activated from callback
       
   147     if ( !IsActive() )
       
   148         {
       
   149         RemoveFromListAndDestroy();
       
   150         }
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CDismountWatcher::ReactivateWatcher
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 void CDismountWatcher::ReactivateWatcher()
       
   158     {
       
   159     FUNC_LOG
       
   160 
       
   161     // Automatic reactivation is not required
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // CDismountWatcher::RunWatcher
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 void CDismountWatcher::RunWatcher( const TBool& aKilled )
       
   169     {
       
   170     FUNC_LOG
       
   171 
       
   172     INFO_LOG1( "CDismountWatcher::RunWatcher-iDrive=%d", iDrive )
       
   173 
       
   174     iWaitConfirm = ETrue;
       
   175     MDiskNotifyHandlerCallback::TDismountEvent event;
       
   176     SetEvent( event, iDrive );
       
   177     Callback().HandleNotifyDismount( KErrNone, event );
       
   178     if ( aKilled )
       
   179         {
       
   180         return;
       
   181         }
       
   182     iWaitConfirm = EFalse;
       
   183     // Remove useless watcher if not manually activated from callback
       
   184     if ( !IsActive() )
       
   185         {
       
   186         RemoveFromListAndDestroy();
       
   187         }
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CDismountWatcher::CancelWatcher
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CDismountWatcher::CancelWatcher()
       
   195     {
       
   196     FUNC_LOG
       
   197 
       
   198     INFO_LOG1( "CDismountWatcher::CancelWatcher-iDrive=%d", iDrive )
       
   199 
       
   200     Fs().NotifyDismountCancel( iStatus );
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CDismountWatcher::Activate
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CDismountWatcher::Activate()
       
   208     {
       
   209     FUNC_LOG
       
   210 
       
   211     if ( !IsActive() )
       
   212         {
       
   213         INFO_LOG1( "CDismountWatcher::Activate-iDrive=%d", iDrive )
       
   214         Fs().NotifyDismount( iDrive, iStatus, EFsDismountRegisterClient );
       
   215         SetActive();
       
   216         }
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // CDismountWatcher::AllowDismount
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 TInt CDismountWatcher::AllowDismount()
       
   224     {
       
   225     FUNC_LOG
       
   226 
       
   227     INFO_LOG2(
       
   228         "CDismountWatcher::AllowDismount-iDrive=%d,iWaitConfirm=%d",
       
   229         iDrive, iWaitConfirm )
       
   230 
       
   231     if ( !iWaitConfirm )
       
   232         {
       
   233         return KErrNone;
       
   234         }
       
   235 
       
   236     TInt ret( Fs().AllowDismount( iDrive ) );
       
   237     LOG_IF_ERROR2(
       
   238         ret,
       
   239         "CDismountWatcher::AllowDismount-iDrive=%d,ret=%d",
       
   240         iDrive, ret )
       
   241     return ret;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CDismountWatcher::RemoveFromListAndDestroy
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 void CDismountWatcher::RemoveFromListAndDestroy()
       
   249     {
       
   250     FUNC_LOG
       
   251 
       
   252     TInt i( iWatcherList.FindInOrder( this, CompareFindObject ) );
       
   253     if ( i >= 0 && i < iWatcherList.Count() )
       
   254         {
       
   255         INFO_LOG2(
       
   256             "CDismountWatcher::RemoveFromListAndDestroy-iDrive=%d,i=%d",
       
   257             iDrive, i )
       
   258         iWatcherList.Remove( i );
       
   259         delete this;
       
   260         }
       
   261     }
       
   262 
       
   263 // End of File