|
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 the License "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: Implementation of CPushMtmGcOperation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "PushMtmGcOperation.h" |
|
23 #include "PushMtmCliSrvPanic.h" |
|
24 #include "PushMtmUtil.h" |
|
25 #include "PushMtmLog.h" |
|
26 #include <CSIPushMsgEntry.h> |
|
27 #include <msvids.h> |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CPushMtmGcOperation::NewL |
|
33 // --------------------------------------------------------- |
|
34 // |
|
35 CPushMtmGcOperation* CPushMtmGcOperation::NewL( |
|
36 CMsvSession& aSession, |
|
37 TMsvId aFolderId, |
|
38 TRequestStatus& aObserverRequestStatus ) |
|
39 { |
|
40 PUSHLOG_ENTERFN("CPushMtmGcOperation::NewL") |
|
41 |
|
42 CPushMtmGcOperation* self = new (ELeave) CPushMtmGcOperation |
|
43 ( aSession, aFolderId, aObserverRequestStatus ); |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(); // self |
|
47 |
|
48 PUSHLOG_LEAVEFN("CPushMtmGcOperation::NewL") |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CPushMtmGcOperation::~CPushMtmGcOperation |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CPushMtmGcOperation::~CPushMtmGcOperation() |
|
57 { |
|
58 PUSHLOG_ENTERFN("CPushMtmGcOperation::~CPushMtmGcOperation") |
|
59 |
|
60 Cancel(); |
|
61 delete iEntrySel; |
|
62 delete iEntryWrapper; |
|
63 delete iUtil; |
|
64 |
|
65 PUSHLOG_LEAVEFN("CPushMtmGcOperation::~CPushMtmGcOperation") |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CPushMtmGcOperation::DoSyncL |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 void CPushMtmGcOperation::DoSyncL() |
|
73 { |
|
74 PUSHLOG_ENTERFN("CPushMtmGcOperation::DoSyncL") |
|
75 |
|
76 InitL(); |
|
77 |
|
78 for ( iCurrentIndex = 0; iCurrentIndex < iCount; ++iCurrentIndex ) |
|
79 { |
|
80 // iCurrentIndex indicate the current entry in the selection. |
|
81 GcCurrentL(); |
|
82 } |
|
83 |
|
84 // Release unnecessary resources. |
|
85 delete iEntrySel; |
|
86 iEntrySel = NULL; |
|
87 |
|
88 PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoSyncL") |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CPushMtmGcOperation::CPushMtmGcOperation |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 CPushMtmGcOperation::CPushMtmGcOperation( CMsvSession& aSession, |
|
96 TMsvId aFolderId, |
|
97 TRequestStatus& aObserverRequestStatus ) |
|
98 : CPushMtmOperation( aSession, KMsvNullIndexEntryId, aObserverRequestStatus ), |
|
99 iState( EInit ), iFolderId( aFolderId ), iCurrentIndex( 0 ) |
|
100 { |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CPushMtmGcOperation::ConstructL |
|
105 // --------------------------------------------------------- |
|
106 // |
|
107 void CPushMtmGcOperation::ConstructL() |
|
108 { |
|
109 // Do nothing here. |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CPushMtmGcOperation::InitL |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 void CPushMtmGcOperation::InitL() |
|
117 { |
|
118 PUSHLOG_ENTERFN("CPushMtmGcOperation::InitL") |
|
119 |
|
120 if ( !iUtil ) |
|
121 { |
|
122 iUtil = CPushMtmUtil::NewL( iMsvSession ); |
|
123 } |
|
124 |
|
125 CMsvEntrySelection* folders = NULL; |
|
126 if ( iFolderId == KMsvNullIndexEntryId ) |
|
127 { |
|
128 folders = iUtil->FindPushFoldersL(); |
|
129 CleanupStack::PushL( folders ); |
|
130 } |
|
131 else |
|
132 { |
|
133 folders = new (ELeave) CMsvEntrySelection; |
|
134 CleanupStack::PushL( folders ); |
|
135 folders->AppendL( iFolderId ); |
|
136 } |
|
137 |
|
138 // Get SIs from the given folder(s). |
|
139 delete iEntrySel; |
|
140 iEntrySel = NULL; |
|
141 iEntrySel = iUtil->FindMessagesL( *folders, KUidWapPushMsgSI ); |
|
142 CleanupStack::PopAndDestroy(); // folders |
|
143 |
|
144 // Reset count. |
|
145 iCount = iEntrySel->Count(); |
|
146 PUSHLOG_WRITE_FORMAT(" iCount: %d",iCount) |
|
147 // Reset index. |
|
148 iCurrentIndex = 0; |
|
149 |
|
150 // We need a wrapper only if there is entry to delete. |
|
151 if ( iCount && !iEntryWrapper ) |
|
152 { |
|
153 iEntryWrapper = CSIPushMsgEntry::NewL(); |
|
154 } |
|
155 |
|
156 PUSHLOG_LEAVEFN("CPushMtmGcOperation::InitL") |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CPushMtmGcOperation::GcCurrentL |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 void CPushMtmGcOperation::GcCurrentL() |
|
164 { |
|
165 PUSHLOG_ENTERFN("CPushMtmGcOperation::GcCurrentL") |
|
166 |
|
167 PUSHLOG_WRITE_FORMAT(" iCurrentIndex: %d",iCurrentIndex) |
|
168 TMsvId entryId( iEntrySel->At(iCurrentIndex) ); |
|
169 |
|
170 #ifdef _DEBUG |
|
171 TMsvEntry tEntry; |
|
172 TMsvId dummyService; |
|
173 User::LeaveIfError |
|
174 ( iMsvSession.GetEntry( entryId, dummyService, tEntry ) ); |
|
175 |
|
176 __ASSERT_DEBUG( tEntry.iMtm == KUidMtmWapPush && |
|
177 tEntry.iBioType == KUidWapPushMsgSI.iUid, |
|
178 CliSrvPanic( EPushMtmCliSrvPanBadType ) ); |
|
179 #endif // _DEBUG |
|
180 |
|
181 iEntryWrapper->RetrieveL( iMsvSession, entryId ); |
|
182 // Check expiration if expiration time was set. |
|
183 if ( iEntryWrapper->Expires() != Time::NullTTime() ) |
|
184 { |
|
185 TTime today; |
|
186 today.UniversalTime(); |
|
187 if ( iEntryWrapper->Expires() < today ) |
|
188 { |
|
189 PUSHLOG_WRITE(" Expired") |
|
190 // The message has expired. Delete it. |
|
191 CMsvEntry* cParent = |
|
192 iMsvSession.GetEntryL( iEntryWrapper->Entry().Parent() ); |
|
193 CleanupStack::PushL( cParent ); |
|
194 // Delete the message. |
|
195 cParent->DeleteL( entryId ); |
|
196 CleanupStack::PopAndDestroy(); // cParent |
|
197 } |
|
198 } |
|
199 |
|
200 PUSHLOG_LEAVEFN("CPushMtmGcOperation::GcCurrentL") |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CPushMtmGcOperation::RunL |
|
205 // --------------------------------------------------------- |
|
206 // |
|
207 void CPushMtmGcOperation::RunL() |
|
208 { |
|
209 PUSHLOG_ENTERFN("CPushMtmGcOperation::RunL") |
|
210 |
|
211 if ( iState == EInit ) |
|
212 { |
|
213 InitL(); |
|
214 if ( !iCount ) |
|
215 { |
|
216 // Ready. |
|
217 SignalObserver( KErrNone ); |
|
218 } |
|
219 else |
|
220 { |
|
221 iState = EGarbageCollecting; |
|
222 SetActive(); |
|
223 InvokeRun(); |
|
224 } |
|
225 } |
|
226 else if ( iState == EGarbageCollecting ) |
|
227 { |
|
228 __ASSERT_DEBUG( iCount, |
|
229 CliSrvPanic( EPushMtmCliSrvPanEmptySelection ) ); |
|
230 // iCurrentIndex indicate the current entry in the selection. |
|
231 GcCurrentL(); |
|
232 if ( ++iCurrentIndex < iCount ) |
|
233 { |
|
234 // Delete next. |
|
235 SetActive(); |
|
236 InvokeRun(); |
|
237 } |
|
238 else |
|
239 { |
|
240 // No more to delete. |
|
241 SignalObserver( KErrNone ); |
|
242 } |
|
243 } |
|
244 else |
|
245 { |
|
246 __ASSERT_DEBUG( EFalse, |
|
247 CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) ); |
|
248 } |
|
249 |
|
250 PUSHLOG_LEAVEFN("CPushMtmGcOperation::RunL") |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------- |
|
254 // CPushMtmGcOperation::DoCancel |
|
255 // --------------------------------------------------------- |
|
256 // |
|
257 void CPushMtmGcOperation::DoCancel() |
|
258 { |
|
259 PUSHLOG_ENTERFN("CPushMtmGcOperation::DoCancel") |
|
260 |
|
261 CPushMtmOperation::DoCancel(); |
|
262 |
|
263 PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoCancel") |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CPushMtmGcOperation::RunError |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 TInt CPushMtmGcOperation::RunError( TInt aError ) |
|
271 { |
|
272 PUSHLOG_ENTERFN("CPushMtmGcOperation::RunError") |
|
273 PUSHLOG_WRITE_FORMAT(" aError: %d",aError) |
|
274 |
|
275 TBool doContinue( EFalse ); |
|
276 |
|
277 PUSHLOG_WRITE_FORMAT(" iState: %d",iState) |
|
278 if ( iState == EInit ) |
|
279 { |
|
280 // We cannot continue. |
|
281 } |
|
282 else if ( iState == EGarbageCollecting ) |
|
283 { |
|
284 if ( aError == KErrNotFound ) |
|
285 { |
|
286 // Try to continue with next. |
|
287 if ( ++iCurrentIndex < iCount ) |
|
288 { |
|
289 // Delete next. |
|
290 doContinue = ETrue; |
|
291 SetActive(); |
|
292 InvokeRun(); |
|
293 } |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 __ASSERT_DEBUG( EFalse, |
|
299 CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) ); |
|
300 } |
|
301 |
|
302 TInt ret = KErrNone; |
|
303 if ( doContinue ) |
|
304 { |
|
305 ret = KErrNone; |
|
306 } |
|
307 else |
|
308 { |
|
309 // Report error. |
|
310 ret = CPushMtmOperation::RunError( aError ); |
|
311 } |
|
312 |
|
313 PUSHLOG_LEAVEFN("CPushMtmGcOperation::RunError") |
|
314 return ret; |
|
315 } |
|
316 |
|
317 // End of file. |