|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 compress policy manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2CompressPolicyManager.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2CompressPolicyTimer.h" |
|
23 #include "CPbk2CompressPolicyDiskSpace.h" |
|
24 #include <MPbk2StoreObservationRegister.h> |
|
25 |
|
26 // Virtual Phonebook |
|
27 #include <CVPbkContactManager.h> |
|
28 #include <MVPbkContactOperationBase.h> |
|
29 |
|
30 // System includes |
|
31 #include <systemwarninglevels.hrh> |
|
32 |
|
33 // Debugging headers |
|
34 #include <Pbk2Debug.h> |
|
35 |
|
36 |
|
37 /// Unnamed namespace for local definitions |
|
38 namespace { |
|
39 |
|
40 /// Time (in seconds) to wait after last database event before starting |
|
41 /// compression. The timeout tries to prevent compression from starting |
|
42 /// if there is a lot of database activity. |
|
43 const TInt KIntervalInSeconds(10); |
|
44 |
|
45 #ifdef _DEBUG |
|
46 |
|
47 enum TPanic |
|
48 { |
|
49 EPreCondPanic_OperationComplete = 1, |
|
50 EPreCondPanic_AlreadyExist |
|
51 }; |
|
52 |
|
53 _LIT(KPanicCat, "CPbk2CompressPolicyManager"); |
|
54 |
|
55 void Panic(TPanic aPanic) |
|
56 { |
|
57 User::Panic(KPanicCat, aPanic); |
|
58 } |
|
59 |
|
60 #endif // _DEBUG |
|
61 |
|
62 } /// namespace |
|
63 |
|
64 |
|
65 // -------------------------------------------------------------------------- |
|
66 // CPbk2CompressPolicyManager::CPbk2CompressPolicyManager |
|
67 // -------------------------------------------------------------------------- |
|
68 // |
|
69 CPbk2CompressPolicyManager::CPbk2CompressPolicyManager |
|
70 ( MPbk2StoreObservationRegister& aStoreObservationRegister, |
|
71 CVPbkContactManager& aContactManager ) : |
|
72 iStoreObservationRegister( aStoreObservationRegister ), |
|
73 iContactManager( aContactManager ) |
|
74 { |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CPbk2CompressPolicyManager::~CPbk2CompressPolicyManager |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 CPbk2CompressPolicyManager::~CPbk2CompressPolicyManager() |
|
82 { |
|
83 iPolicyArray.ResetAndDestroy(); |
|
84 delete iCompressOperation; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2CompressPolicyManager::NewL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 CPbk2CompressPolicyManager* CPbk2CompressPolicyManager::NewL |
|
92 ( MPbk2StoreObservationRegister& aStoreObservationRegister, |
|
93 CVPbkContactManager& aContactManager ) |
|
94 { |
|
95 CPbk2CompressPolicyManager* self = |
|
96 new ( ELeave ) CPbk2CompressPolicyManager |
|
97 ( aStoreObservationRegister, aContactManager ); |
|
98 CleanupStack::PushL(self); |
|
99 self->ConstructL(); |
|
100 CleanupStack::Pop(self); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CPbk2CompressPolicyManager::ConstructL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 void CPbk2CompressPolicyManager::ConstructL() |
|
109 { |
|
110 ConstructPoliciesL(); |
|
111 } |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CPbk2CompressPolicyManager::CompressStores |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 void CPbk2CompressPolicyManager::CompressStores() |
|
118 { |
|
119 __ASSERT_DEBUG( !iCompressOperation, Panic(EPreCondPanic_AlreadyExist)); |
|
120 |
|
121 TRAPD( err, |
|
122 iCompressOperation = iContactManager.CompressStoresL( *this ) ); |
|
123 |
|
124 if (err != KErrNone) |
|
125 { |
|
126 // if error occured here, restart all policies |
|
127 StartAllPolicies(); |
|
128 } |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CPbk2CompressPolicyManager::CancelCompress |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 void CPbk2CompressPolicyManager::CancelCompress() |
|
136 { |
|
137 delete iCompressOperation; |
|
138 iCompressOperation = NULL; |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CPbk2CompressPolicyManager::StartAllPolicies |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 void CPbk2CompressPolicyManager::StartAllPolicies() |
|
146 { |
|
147 for (TInt i = 0; i < iPolicyArray.Count(); ++i) |
|
148 { |
|
149 MPbk2CompressPolicy* policy = iPolicyArray[i]; |
|
150 policy->Start(); |
|
151 } |
|
152 } |
|
153 |
|
154 // -------------------------------------------------------------------------- |
|
155 // CPbk2CompressPolicyManager::StopAllPolicies |
|
156 // -------------------------------------------------------------------------- |
|
157 // |
|
158 void CPbk2CompressPolicyManager::StopAllPolicies() |
|
159 { |
|
160 CancelCompress(); |
|
161 for (TInt i = 0; i < iPolicyArray.Count(); ++i) |
|
162 { |
|
163 iPolicyArray[i]->Stop(); |
|
164 } |
|
165 } |
|
166 |
|
167 // -------------------------------------------------------------------------- |
|
168 // CPbk2CompressPolicyManager::StepComplete |
|
169 // -------------------------------------------------------------------------- |
|
170 // |
|
171 void CPbk2CompressPolicyManager::StepComplete |
|
172 ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aStepSize*/ ) |
|
173 { |
|
174 // Do nothing |
|
175 } |
|
176 |
|
177 // -------------------------------------------------------------------------- |
|
178 // CPbk2CompressPolicyManager::StepFailed |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 TBool CPbk2CompressPolicyManager::StepFailed |
|
182 ( MVPbkContactOperationBase& /*aOperation*/, TInt /*aStepSize*/, |
|
183 TInt /*aError*/ ) |
|
184 { |
|
185 // The process should be stopped |
|
186 return EFalse; |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CPbk2CompressPolicyManager::OperationComplete |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 void CPbk2CompressPolicyManager::OperationComplete |
|
194 ( MVPbkContactOperationBase& PBK2_DEBUG_ONLY( aOperation ) ) |
|
195 { |
|
196 __ASSERT_DEBUG(iCompressOperation == &aOperation, |
|
197 Panic(EPreCondPanic_OperationComplete)); |
|
198 delete iCompressOperation; |
|
199 iCompressOperation = NULL; |
|
200 |
|
201 // After compress operation complete, restart the policies |
|
202 StartAllPolicies(); |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CPbk2CompressPolicyManager::ConstructPoliciesL |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 void CPbk2CompressPolicyManager::ConstructPoliciesL() |
|
210 { |
|
211 // Timer policy |
|
212 CPbk2CompressPolicyTimer* timerPolicy = CPbk2CompressPolicyTimer::NewL |
|
213 ( iStoreObservationRegister, *this, KIntervalInSeconds ); |
|
214 CleanupStack::PushL(timerPolicy); |
|
215 iPolicyArray.AppendL(timerPolicy); |
|
216 CleanupStack::Pop(timerPolicy); |
|
217 |
|
218 // Disk space policy |
|
219 CPbk2CompressPolicyDiskSpace* diskspacePolicy = |
|
220 CPbk2CompressPolicyDiskSpace::NewL |
|
221 ( *this, iContactManager.FsSession(), KDRIVECCRITICALTHRESHOLD ); |
|
222 CleanupStack::PushL(diskspacePolicy); |
|
223 iPolicyArray.AppendL(diskspacePolicy); |
|
224 CleanupStack::Pop(diskspacePolicy); |
|
225 } |
|
226 |
|
227 // End of File |