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