messagingappbase/msgerrorwatcher/src/MsgErrorDiskSpaceObserver.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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 *     CMsgErrorDiskSpaceObserver implementation file
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    <e32base.h>
       
    23 
       
    24 #include    "MsgErrorWatcher.h"
       
    25 #include    "MsgErrorDiskSpaceObserver.h"
       
    26 
       
    27 #ifdef USE_LOGGER
       
    28 #include "MsgErrorWatcherLogging.h"
       
    29 #endif
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CMsgErrorDiskSpaceObserver::CMsgErrorDiskSpaceObserver
       
    35 //
       
    36 // C++ constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 CMsgErrorDiskSpaceObserver::CMsgErrorDiskSpaceObserver( 
       
    41         CMsgErrorWatcher* aWatcher, 
       
    42         CMsvSession& aSession, 
       
    43         RFs& aFs )
       
    44     : CActive( CActive::EPriorityStandard ),
       
    45     iWatcher( aWatcher ),
       
    46     iSession( aSession ),
       
    47     iFs( aFs ),
       
    48     iLimit( 0 )
       
    49     {
       
    50     CActiveScheduler::Add( this );
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CMsgErrorDiskSpaceObserver::NewL
       
    55 //
       
    56 // Two-phased constructor.
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 CMsgErrorDiskSpaceObserver* CMsgErrorDiskSpaceObserver::NewL( 
       
    60         CMsgErrorWatcher* aWatcher, 
       
    61         CMsvSession& aSession, 
       
    62         RFs& aFs )
       
    63     {
       
    64     CMsgErrorDiskSpaceObserver* self = new ( ELeave )
       
    65         CMsgErrorDiskSpaceObserver( aWatcher, aSession, aFs );
       
    66     return self;
       
    67     }
       
    68 
       
    69     
       
    70 // ---------------------------------------------------------
       
    71 // CMsgErrorDiskSpaceObserver::~CMsgErrorDiskSpaceObserver
       
    72 //
       
    73 // Destructor
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CMsgErrorDiskSpaceObserver::~CMsgErrorDiskSpaceObserver()
       
    77     {
       
    78     Cancel();
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // CMsgErrorDiskSpaceObserver::DoCancel
       
    84 //
       
    85 // From active object framework
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CMsgErrorDiskSpaceObserver::DoCancel()
       
    89     {
       
    90     iFs.NotifyDiskSpaceCancel( iStatus );
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CMsgErrorDiskSpaceObserver::RunL
       
    95 //
       
    96 // From active object framework
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 void CMsgErrorDiskSpaceObserver::RunL()
       
   100     {
       
   101 #ifdef USE_LOGGER
       
   102     MEWLOGGER_WRITEF( _L("DiskSpace: RunL, iStatus: %d"), iStatus.Int() );
       
   103 #endif
       
   104     TInt status = iStatus.Int();
       
   105     if ( status < 0 )
       
   106         {
       
   107         //Reset the observer.
       
   108         TRAP_IGNORE ( SetLimitAndActivateL( iLimit ) );
       
   109         return;
       
   110         }
       
   111     
       
   112     //We shouldn't have to check whether we're above the limit,
       
   113     //because we were below when we activated and the event comes
       
   114     //when we cross the limit
       
   115 
       
   116     TRAP_IGNORE( iWatcher->HandleDiskSpaceEventL() );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CMsgErrorDiskSpaceObserver::SetLimitAndActivateL
       
   121 //
       
   122 // Sets the disk space trigger level for active object
       
   123 // and activates it.
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 void CMsgErrorDiskSpaceObserver::SetLimitAndActivateL( TInt32 aLimit )
       
   127     {
       
   128 #ifdef USE_LOGGER
       
   129     MEWLOGGER_ENTERFN( "DiskSpace: SetLimitAndActivateL" );
       
   130     MEWLOGGER_WRITEF( _L("DiskSpace: aLimit %d"), aLimit );
       
   131 #endif
       
   132     __ASSERT_DEBUG( aLimit >= 0, User::Leave( KErrArgument ) );
       
   133     if ( aLimit < 0 )
       
   134         {
       
   135         return;
       
   136         }
       
   137     if ( iLimit == 0 || iLimit > aLimit )
       
   138         {
       
   139         Cancel();
       
   140         iLimit = aLimit;
       
   141 
       
   142         TInt currentDrive = TInt( iSession.CurrentDriveL() );
       
   143         TVolumeInfo volInfo;
       
   144         User::LeaveIfError( iFs.Volume( volInfo, currentDrive ) );
       
   145 #ifdef USE_LOGGER
       
   146         MEWLOGGER_WRITEF( _L("DiskSpace: free/hi %d"), I64HIGH( volInfo.iFree ) );
       
   147         MEWLOGGER_WRITEF( _L("DiskSpace: free/lo %d"), I64LOW( volInfo.iFree ) );
       
   148 #endif
       
   149         //check if we're already above the limit
       
   150         if ( I64HIGH( volInfo.iFree ) != 0 ||
       
   151             I64LOW( volInfo.iFree ) > (TUint)iLimit ) //iLimit is always positive.
       
   152             {
       
   153             iWatcher->HandleDiskSpaceEventL();
       
   154             return;
       
   155             }
       
   156         else
       
   157             {
       
   158 #ifdef USE_LOGGER
       
   159             MEWLOGGER_WRITE( "DiskSpace: notify activated" );
       
   160 #endif
       
   161             TInt64 treshold = iLimit;
       
   162             iFs.NotifyDiskSpace( treshold, currentDrive, iStatus );
       
   163             // No need to check IsActive since object is cancelled 
       
   164             // anyway above
       
   165             SetActive();
       
   166             }
       
   167         }
       
   168     }
       
   169 
       
   170 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   171 
       
   172 //  End of File  
       
   173