|
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 * CAlwaysOnlineDiskSpaceObserver implementation file |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32base.h> |
|
23 #include <app/MuiuMsvUiServiceUtilities.h> // Muiu Utilities |
|
24 #include <systemwarninglevels.hrh> |
|
25 |
|
26 #include "AlwaysOnlineManagerDiskSpaceObserver.h" |
|
27 #include "AlwaysOnlineManager.h" |
|
28 #include "AlwaysOnlineManagerLogging.h" |
|
29 |
|
30 |
|
31 // ================= MEMBER FUNCTIONS ======================= |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CAlwaysOnlineDiskSpaceObserver::CAlwaysOnlineDiskSpaceObserver |
|
35 // |
|
36 // C++ constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ---------------------------------------------------------------------------- |
|
39 // |
|
40 CAlwaysOnlineDiskSpaceObserver::CAlwaysOnlineDiskSpaceObserver( |
|
41 CAlwaysOnlineManager* aManager, |
|
42 CMsvSession& aSession ) |
|
43 : |
|
44 CActive( CActive::EPriorityStandard ), |
|
45 iManager( *aManager ), |
|
46 iSession( aSession ), |
|
47 iNewLimit( 0 ), |
|
48 iCurrentLimit( 0 ) |
|
49 { |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CAlwaysOnlineDiskSpaceObserver::NewL |
|
55 // |
|
56 // Two-phased constructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CAlwaysOnlineDiskSpaceObserver* CAlwaysOnlineDiskSpaceObserver::NewL( |
|
60 CAlwaysOnlineManager* aManager, |
|
61 CMsvSession& aSession ) |
|
62 { |
|
63 CAlwaysOnlineDiskSpaceObserver* self = new ( ELeave ) |
|
64 CAlwaysOnlineDiskSpaceObserver( aManager, aSession ); |
|
65 return self; |
|
66 } |
|
67 |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CAlwaysOnlineDiskSpaceObserver::~CAlwaysOnlineDiskSpaceObserver |
|
71 // |
|
72 // Destructor |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 CAlwaysOnlineDiskSpaceObserver::~CAlwaysOnlineDiskSpaceObserver() |
|
76 { |
|
77 Cancel(); |
|
78 } |
|
79 |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // CAlwaysOnlineDiskSpaceObserver::DoCancel |
|
83 // |
|
84 // From active object framework |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 void CAlwaysOnlineDiskSpaceObserver::DoCancel() |
|
88 { |
|
89 if ( IsActive() ) |
|
90 { |
|
91 iSession.FileSession().NotifyDiskSpaceCancel( iStatus ); |
|
92 } |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CAlwaysOnlineDiskSpaceObserver::RunL |
|
97 // |
|
98 // From active object framework |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 void CAlwaysOnlineDiskSpaceObserver::RunL() |
|
102 { |
|
103 if ( iStatus.Int() == KErrNone ) |
|
104 { |
|
105 // timer or file server event? |
|
106 SetLimitAndActivateL(); |
|
107 } |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CAlwaysOnlineDiskSpaceObserver::RunError() |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CAlwaysOnlineDiskSpaceObserver::RunError( TInt /* aError */ ) |
|
115 { |
|
116 // Just ignore any error and continue without |
|
117 // any handling to allow smooth execution. |
|
118 return KErrNone; |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------- |
|
122 // CAlwaysOnlineDiskSpaceObserver::SetLimitAndActivateL |
|
123 // ---------------------------------------------------------------------------- |
|
124 // |
|
125 void CAlwaysOnlineDiskSpaceObserver::SetLimitAndActivateL() |
|
126 { |
|
127 KAOMANAGER_LOGGER_WRITE("CAlwaysOnlineDiskSpaceObserver::SetLimitAndActivateL() Received DISKSPACE event"); |
|
128 Cancel(); |
|
129 |
|
130 // Handle the possible change |
|
131 HandleLimitChange(); |
|
132 |
|
133 // Get current drive |
|
134 TInt currentDrive = iSession.CurrentDriveL(); |
|
135 |
|
136 // Make the disk space check. The safety margin is used to keep disk space |
|
137 // from dropping below critical level |
|
138 if ( !MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelWithOverheadL( |
|
139 iSession, 0, KAOSafetyMargin ) ) |
|
140 { |
|
141 KAOMANAGER_LOGGER_WRITE("CAlwaysOnlineDiskSpaceObserver::SetLimitAndActivateL() Event: Above Critical"); |
|
142 iManager.HandleDiskSpaceEventL( EAOManagerDiskSpaceAboveCritical ); |
|
143 } |
|
144 else |
|
145 { |
|
146 KAOMANAGER_LOGGER_WRITE("CAlwaysOnlineDiskSpaceObserver::SetLimitAndActivateL() Event: Below Critical"); |
|
147 iManager.HandleDiskSpaceEventL( EAOManagerDiskSpaceBelowCritical ); |
|
148 } |
|
149 |
|
150 // Issue new request |
|
151 iSession.FileSession().NotifyDiskSpace( iCurrentLimit, currentDrive, iStatus ); |
|
152 SetActive(); |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CImumDiskSpaceObserverOperation::HandleLimitChange() |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 void CAlwaysOnlineDiskSpaceObserver::HandleLimitChange() |
|
160 { |
|
161 if( !iNewLimit ) |
|
162 { |
|
163 iCurrentLimit = KDRIVECCRITICALTHRESHOLD + KAOSafetyMargin; |
|
164 } |
|
165 else |
|
166 { |
|
167 iCurrentLimit = iNewLimit; |
|
168 } |
|
169 } |
|
170 |
|
171 // End of File |
|
172 |