1 /* |
|
2 * Copyright (c) 2009 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 #include <pathinfo.h> |
|
18 #include "irqdiskspaceobserver.h" |
|
19 #include "irqdiskspaceobserverinterface.h" |
|
20 |
|
21 const TDriveNumber KQtIRDefaultDrive = EDriveC; |
|
22 |
|
23 const TUint KDriveAValue = 'A'; |
|
24 const TUint KDriveZValue = 'Z'; |
|
25 const TUint KDriveaValue = 'a'; |
|
26 const TUint KDrivezValue = 'z'; |
|
27 |
|
28 static TDriveNumber phoneMemRootDrive(); |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Constructor |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 IRQDiskSpaceObserver* IRQDiskSpaceObserver::NewL(MIRQDiskSpaceObserver* aObserver) |
|
35 { |
|
36 IRQDiskSpaceObserver* self = new (ELeave) IRQDiskSpaceObserver(aObserver); |
|
37 |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Second stage constructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void IRQDiskSpaceObserver::ConstructL() |
|
50 { |
|
51 CActiveScheduler::Add(this); |
|
52 User::LeaveIfError(iFs.Connect()); |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // C++ Constructor |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 IRQDiskSpaceObserver::IRQDiskSpaceObserver( MIRQDiskSpaceObserver* aObserver ) |
|
60 : CActive( CActive::EPriorityStandard ), |
|
61 iObserver( aObserver ), |
|
62 iCriticalLevel(0) |
|
63 { |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Destructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 IRQDiskSpaceObserver::~IRQDiskSpaceObserver() |
|
71 { |
|
72 Cancel(); |
|
73 iFs.Close(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Critical Level |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 TInt64 IRQDiskSpaceObserver::criticalLevel() const |
|
81 { |
|
82 if(IsActive()) |
|
83 { |
|
84 return iCriticalLevel; |
|
85 } |
|
86 else |
|
87 { |
|
88 return -1; |
|
89 } |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Start Monitoring |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void IRQDiskSpaceObserver::start(const TInt64 aCriticalLevel) |
|
97 { |
|
98 Cancel(); |
|
99 iCriticalLevel = aCriticalLevel; |
|
100 run(); |
|
101 } |
|
102 |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // From class CActive. |
|
106 // Cancels the pending request. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void IRQDiskSpaceObserver::DoCancel() |
|
110 { |
|
111 iFs.NotifyDiskSpaceCancel(iStatus); |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // From class CActive. |
|
117 // Invoked when the observed disk's free disk space has run below |
|
118 // the supplied critical level. |
|
119 // Notifies the observer and regenerates the request to RFs' NotifyDiskSpace. |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void IRQDiskSpaceObserver::RunL() |
|
123 { |
|
124 run(); |
|
125 } |
|
126 |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // Returns true if below the critical level in defined disk, otherwise false |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 bool IRQDiskSpaceObserver::isBelowCriticalLevel(const TInt64 aCriticalLevel) const |
|
133 { |
|
134 TVolumeInfo volInfo; |
|
135 if(KErrNone == iFs.Volume(volInfo, KQtIRDefaultDrive)) |
|
136 { |
|
137 if(volInfo.iFree < aCriticalLevel) |
|
138 { |
|
139 return true; |
|
140 } |
|
141 } |
|
142 |
|
143 return false; |
|
144 } |
|
145 |
|
146 void IRQDiskSpaceObserver::run() |
|
147 { |
|
148 if( iObserver && isBelowCriticalLevel(iCriticalLevel)) |
|
149 { |
|
150 iObserver->notifyLowDiskSpace((qint64)iCriticalLevel); |
|
151 } |
|
152 |
|
153 iFs.NotifyDiskSpace(iCriticalLevel, phoneMemRootDrive(), iStatus); |
|
154 SetActive(); |
|
155 } |
|
156 |
|
157 TDriveNumber phoneMemRootDrive() |
|
158 { |
|
159 TParsePtrC phoneMemoryRootPath( PathInfo::PhoneMemoryRootPath() ); |
|
160 TPtrC drive( phoneMemoryRootPath.Drive() ); |
|
161 TUint driveValue = drive[0]; |
|
162 TUint delta = 0; |
|
163 if( driveValue >= KDriveAValue && |
|
164 driveValue <= KDriveZValue) |
|
165 { |
|
166 delta = driveValue - KDriveAValue; |
|
167 } |
|
168 else if( driveValue >= KDriveaValue && |
|
169 driveValue <= KDrivezValue) |
|
170 { |
|
171 delta = driveValue - KDriveaValue; |
|
172 } |
|
173 else |
|
174 { |
|
175 return KQtIRDefaultDrive; |
|
176 } |
|
177 |
|
178 return static_cast<TDriveNumber>(EDriveA + delta); |
|
179 } |
|