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