1 /* |
|
2 * Copyright (c) 2006 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: Contains logic for watching certain disk's space |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "irdebug.h" |
|
20 #include "irdiskspacesession.h" |
|
21 #include "irdiskspacewatcherobserver.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // C++ Constructor |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 CIRDiskSpaceSession::CIRDiskSpaceSession( |
|
28 MIRDiskSpaceWatcherObserver& aDiskSpaceWatcherObserver, |
|
29 const TDriveNumber& aDriveNumber, |
|
30 const TInt64& aCriticalLevel, |
|
31 RFs& aFs ) : |
|
32 CActive( CActive::EPriorityStandard ), |
|
33 iObserver( aDiskSpaceWatcherObserver ), |
|
34 iDriveNumber( aDriveNumber ), |
|
35 iCriticalLevel ( aCriticalLevel ), |
|
36 iFs ( aFs ) |
|
37 { |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Constructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CIRDiskSpaceSession* CIRDiskSpaceSession::NewL( |
|
46 MIRDiskSpaceWatcherObserver& aDiskSpaceWatcherObserver, |
|
47 const TDriveNumber& aDriveNumber, |
|
48 const TInt64& aCriticalLevel, |
|
49 RFs& aFs ) |
|
50 { |
|
51 |
|
52 CIRDiskSpaceSession* self = new( ELeave ) CIRDiskSpaceSession( |
|
53 aDiskSpaceWatcherObserver, |
|
54 aDriveNumber, |
|
55 aCriticalLevel, |
|
56 aFs ); |
|
57 |
|
58 CleanupStack::PushL( self ); |
|
59 |
|
60 self->ConstructL(); |
|
61 |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // Destructor |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CIRDiskSpaceSession::~CIRDiskSpaceSession() |
|
73 { |
|
74 Cancel(); |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Second stage constructor |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CIRDiskSpaceSession::ConstructL() |
|
83 { |
|
84 CActiveScheduler::Add( this ); |
|
85 RunL(); |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // DriveNumber |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 TDriveNumber CIRDiskSpaceSession::DriveNumber() |
|
94 { |
|
95 return iDriveNumber; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // SetObserverCount |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CIRDiskSpaceSession::SetObserverCount( TInt aObserverCount ) |
|
104 { |
|
105 iObserverCount = aObserverCount; |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // ObserverCount |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 TInt CIRDiskSpaceSession::ObserverCount() |
|
114 { |
|
115 return iObserverCount; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // From class CActive. |
|
121 // Cancels the pending request. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CIRDiskSpaceSession::DoCancel() |
|
125 { |
|
126 iFs.NotifyDiskSpaceCancel( iStatus ); |
|
127 } |
|
128 |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // From class CActive. |
|
132 // Invoked when the observed disk's free disk space has run below |
|
133 // the supplied critical level. |
|
134 // Notifies the observer and regenerates the request to RFs' NotifyDiskSpace. |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CIRDiskSpaceSession::RunL() |
|
138 { |
|
139 IRRDEBUG2("CIRDiskSpaceSession::RunL - iDriveNumber=%d", iDriveNumber); |
|
140 IRRDEBUG2("CIRDiskSpaceSession::RunL - iCriticalLevel=%d", iCriticalLevel); |
|
141 iFs.NotifyDiskSpace( iCriticalLevel, iDriveNumber, iStatus ); |
|
142 SetActive(); |
|
143 |
|
144 if ( IsBelowCriticalLevel( iDriveNumber ) ) |
|
145 { |
|
146 IRRDEBUG2("CIRDiskSpaceSession::RunL - LOW MEMORY detected", KNullDesC); |
|
147 TRAP_IGNORE( iObserver.NotifyLowDiskSpaceL() ) |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // Returns ETrue if below the critical level in defined disk, otherwise EFalse |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 TBool CIRDiskSpaceSession::IsBelowCriticalLevel( |
|
157 const TDriveNumber& aDriveNumber ) const |
|
158 { |
|
159 TBool ret = EFalse; |
|
160 |
|
161 TVolumeInfo volInfo; |
|
162 if ( iFs.Volume( volInfo, aDriveNumber ) == KErrNone ) |
|
163 { |
|
164 if ( volInfo.iFree < iCriticalLevel ) |
|
165 { |
|
166 IRRDEBUG3( "CIRDiskSpaceSession::IsBelowCriticalLevel - Low Memory. Disk space [%d] is under the critical [%d] level!", |
|
167 static_cast<TInt>( volInfo.iFree ), |
|
168 static_cast<TInt>( iCriticalLevel ) ); |
|
169 ret = ETrue; |
|
170 } |
|
171 else |
|
172 { |
|
173 IRRDEBUG3( "CIRDiskSpaceSession::IsBelowCriticalLevel - Enough Disk space [%d] in DriveNumber [%d].", |
|
174 static_cast<TInt>( volInfo.iFree ), |
|
175 static_cast<TInt>( aDriveNumber ) ); |
|
176 } |
|
177 } |
|
178 |
|
179 return ret; |
|
180 } |
|