|
1 /* |
|
2 * Copyright (c) 2002-2005 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "AspSyncHandler.h" |
|
22 #include "AspDebug.h" |
|
23 #include "AspSettingDialog.h" |
|
24 |
|
25 #include <aspsyncutil.mbg> // for progress dialog bitmap enumerations |
|
26 |
|
27 #include <SyncMLErr.h> // sync error codes |
|
28 |
|
29 #include <ecom/ecom.h> |
|
30 #include <ecom/implementationinformation.h> |
|
31 #include <rconnmon.h> |
|
32 #include <e32std.h> //For TRequestStatus |
|
33 #include <e32property.h> |
|
34 #include "CPreSyncPlugin.h" |
|
35 #include "AspPreSyncPluginInterface.h" |
|
36 |
|
37 #include <DataSyncInternalPSKeys.h> |
|
38 #include <featmgr.h> |
|
39 |
|
40 /****************************************************************************** |
|
41 * class TAspSyncParam |
|
42 ******************************************************************************/ |
|
43 |
|
44 |
|
45 // ------------------------------------------------------------------------------- |
|
46 // TAspSyncParam::TAspSyncParam |
|
47 // |
|
48 // ------------------------------------------------------------------------------- |
|
49 // |
|
50 TAspSyncParam::TAspSyncParam(TInt aApplicationId) |
|
51 : iApplicationId(aApplicationId), iProfileId(KErrNotFound), iJobId(KErrNotFound), |
|
52 iTaskId(KErrNotFound), iSyncDirection(KErrNotFound), iDialogMode(EModeDialogNoWait) |
|
53 { |
|
54 } |
|
55 |
|
56 |
|
57 |
|
58 /****************************************************************************** |
|
59 * class CAspSyncHandler |
|
60 ******************************************************************************/ |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CAspSyncHandler::NewL |
|
65 // |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CAspSyncHandler* CAspSyncHandler::NewL(const TAspParam& aParam) |
|
69 { |
|
70 FLOG( _L("CAspSyncHandler::NewL START") ); |
|
71 |
|
72 CAspSyncHandler* self = new (ELeave) CAspSyncHandler(aParam); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(self); |
|
76 |
|
77 FLOG( _L("CAspSyncHandler::NewL END") ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // Destructor |
|
84 // |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CAspSyncHandler::~CAspSyncHandler() |
|
88 { |
|
89 FLOG( _L("CAspSyncHandler::~CAspSyncHandler START") ); |
|
90 |
|
91 delete iProgressDialog; |
|
92 delete iState; |
|
93 delete iResHandler; |
|
94 delete iActiveCaller; |
|
95 delete iTextResolver; |
|
96 |
|
97 delete iContentList; |
|
98 |
|
99 if (iWait && iWait->IsStarted()) |
|
100 { |
|
101 iWait->AsyncStop(); |
|
102 } |
|
103 delete iWait; |
|
104 |
|
105 RProperty::Delete(KPSUidNSmlDSSyncApp, KDsJobCancel); |
|
106 |
|
107 CloseSyncSession(); |
|
108 |
|
109 FLOG( _L("CAspSyncHandler::~CAspSyncHandler END") ); |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CAspSyncHandler::ConstructL |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CAspSyncHandler::ConstructL() |
|
119 { |
|
120 FLOG( _L("CAspSyncHandler::ConstructL START") ); |
|
121 |
|
122 iState = CAspState::NewL(); |
|
123 |
|
124 iActiveCaller = CAspActiveCaller::NewL(this); |
|
125 iTextResolver = CTextResolver::NewL(); |
|
126 |
|
127 iServerAlertSync = EFalse; |
|
128 iSyncRunning = EFalse; |
|
129 iSyncError = KErrNone; |
|
130 iCurrentSyncJobId = KErrNotFound; |
|
131 iSyncSessionOpen = EFalse; |
|
132 |
|
133 iWait = new (ELeave) CActiveSchedulerWait(); |
|
134 //Define property for cancel operation. |
|
135 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
|
136 static _LIT_SECURITY_POLICY_C1(KAllowWriteDeviceDataPolicy, ECapabilityWriteDeviceData); |
|
137 RProperty::Define( KPSUidNSmlDSSyncApp,KDsJobCancel,RProperty::EInt, |
|
138 KAllowAllPolicy,KAllowWriteDeviceDataPolicy); |
|
139 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
140 KDsJobCancel, KErrNone ); |
|
141 FLOG( _L("CAspSyncHandler::ConstructL END") ); |
|
142 } |
|
143 |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CAspSyncHandler::CAspSyncHandler |
|
147 // |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 CAspSyncHandler::CAspSyncHandler(const TAspParam& /*aParam*/) |
|
151 { |
|
152 } |
|
153 |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CAspSyncHandler::SetObserver |
|
157 // |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CAspSyncHandler::SetObserver(MAspSyncObserver* aObserver) |
|
161 { |
|
162 iSyncObserver = aObserver; |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CAspSyncHandler::HandleDialogEventL (from MAspProgressDialogObserver) |
|
168 // |
|
169 // |
|
170 // Canceling sequence after user presses "Cancel": |
|
171 // |
|
172 // 1. framework calls CAspProgressDialog2::OkToExitL |
|
173 // 2. OkToExitL calls CAspProgressDialog::DialogDismissedL |
|
174 // 3. DialogDismissedL calls CAspSyncHandler::HandleDialogEventL |
|
175 // 4. HandleDialogEventL cancels sync (RSyncMLDataSyncJob::StopL) |
|
176 // and updates progress dialog text ("Cancelling") |
|
177 // 5. MSyncMLEventObserver::EJobStop arrives (asynchronously) |
|
178 // and CAspProgressDialog is closed |
|
179 // |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CAspSyncHandler::HandleDialogEventL(TInt aButtonId) |
|
183 { |
|
184 FLOG( _L("CAspSyncHandler::HandleDialogEventL START") ); |
|
185 |
|
186 TBool syncRunning = SyncRunning(); |
|
187 |
|
188 // close handling (eg. end key) |
|
189 if (aButtonId == EKeyPhoneEnd && syncRunning) |
|
190 { |
|
191 //Set Cancel property when user cancel the Caopy All from Server. |
|
192 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
193 KDsJobCancel, KErrCancel ); |
|
194 TRAPD(err, iSyncJob.StopL()); |
|
195 |
|
196 if (err != KErrNone) |
|
197 { |
|
198 FLOG( _L("### RSyncMLDataSyncJob::StopL failed (%d) ###"), err ); |
|
199 } |
|
200 |
|
201 iSyncJob.Close(); // this can be done when job has not been opened |
|
202 |
|
203 CloseSyncSession(); |
|
204 |
|
205 iSyncRunning = EFalse; |
|
206 |
|
207 if (iIsSynchronousOperation && iWait->IsStarted()) |
|
208 { |
|
209 iWait->AsyncStop(); |
|
210 } |
|
211 |
|
212 |
|
213 FLOG( _L("CAspSyncHandler::HandleDialogEventL: end key handling done") ); |
|
214 FLOG( _L("CAspSyncHandler::HandleDialogEventL END") ); |
|
215 return; |
|
216 } |
|
217 |
|
218 // cancel key handling |
|
219 if (aButtonId == EEikBidCancel && syncRunning) |
|
220 { |
|
221 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
222 KDsJobCancel, KErrCancel ); |
|
223 |
|
224 if (iStopEventReceived) |
|
225 { |
|
226 CompleteWithDelay(KErrNone); |
|
227 FLOG( _L("### EJobStop already received ###") ); |
|
228 FLOG( _L("CAspSyncHandler::HandleDialogEventL END") ); |
|
229 return; |
|
230 } |
|
231 |
|
232 TInt jobId = CAspProfile::CurrentJob(&iSyncSession); |
|
233 if (jobId != iCurrentSyncJobId) |
|
234 { |
|
235 CompleteWithDelay(KErrNotFound); |
|
236 |
|
237 FLOG( _L("### job conflict (%d/%d) ###"), iCurrentSyncJobId, jobId ); |
|
238 FLOG( _L("CAspSyncHandler::HandleDialogEventL END") ); |
|
239 return; |
|
240 } |
|
241 |
|
242 TRAPD(err, iSyncJob.StopL()); |
|
243 if (err != KErrNone) |
|
244 { |
|
245 CompleteWithDelay(err); |
|
246 |
|
247 FLOG( _L("### RSyncMLDataSyncJob::StopL failed (%d) ###"), err ); |
|
248 FLOG( _L("CAspSyncHandler::HandleDialogEventL END") ); |
|
249 return; |
|
250 } |
|
251 |
|
252 State()->SetSyncPhase(CAspState::EPhaseCanceling); |
|
253 UpdateDialog(); |
|
254 |
|
255 FLOG( _L("CAspSyncHandler::HandleDialogEventL: cancel key handling done") ); |
|
256 } |
|
257 |
|
258 FLOG( _L("CAspSyncHandler::HandleDialogEventL END") ); |
|
259 } |
|
260 |
|
261 |
|
262 TBool CAspSyncHandler::IsRoamingL() |
|
263 { |
|
264 RConnectionMonitor conMon; |
|
265 |
|
266 conMon.ConnectL(); |
|
267 |
|
268 TRequestStatus status; |
|
269 TInt registrationStatus(0); |
|
270 |
|
271 //check network status |
|
272 conMon.GetIntAttribute(EBearerIdGSM, 0, KNetworkRegistration, |
|
273 registrationStatus, status); |
|
274 |
|
275 User::WaitForRequest(status); |
|
276 conMon.Close(); |
|
277 |
|
278 if (registrationStatus == ENetworkRegistrationRoaming) |
|
279 { |
|
280 return ETrue; |
|
281 } |
|
282 |
|
283 return EFalse; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CAspSyncHandler::ReadRepositoryL |
|
288 // |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CAspSyncHandler::ReadRepositoryL(TInt aKey, TInt& aValue) |
|
292 { |
|
293 CRepository* rep = CRepository::NewLC(KCRUidNSmlDSApp); |
|
294 TInt err = rep->Get(aKey, aValue); |
|
295 User::LeaveIfError(err); |
|
296 |
|
297 CleanupStack::PopAndDestroy(rep); |
|
298 } |
|
299 |
|
300 TInt CAspSyncHandler::BearerTypeL(TInt aProfileId) |
|
301 { |
|
302 TInt BearerType = KErrNotFound; |
|
303 |
|
304 // sync session |
|
305 RSyncMLSession syncSession; |
|
306 syncSession.OpenL(); |
|
307 CleanupClosePushL( syncSession ); |
|
308 |
|
309 RSyncMLDataSyncProfile syncProfile; |
|
310 syncProfile.OpenL( syncSession, aProfileId, ESmlOpenRead ); |
|
311 CleanupClosePushL( syncProfile ); |
|
312 |
|
313 // Check if always ask is selected as accesspoint |
|
314 RSyncMLConnection connection; |
|
315 |
|
316 TInt err = KErrNone; |
|
317 RArray<TSmlTransportId> arr; |
|
318 |
|
319 TRAP(err, syncProfile.ListConnectionsL(arr)); |
|
320 if (err != KErrNone) |
|
321 { |
|
322 syncProfile.Close(); |
|
323 CleanupStack::Pop( &syncProfile ); |
|
324 return KErrNotFound; |
|
325 } |
|
326 if (arr.Count() == 0) |
|
327 { |
|
328 syncProfile.Close(); |
|
329 CleanupStack::Pop( &syncProfile ); |
|
330 arr.Close(); |
|
331 return KErrNotFound; // no connection |
|
332 } |
|
333 |
|
334 TInt transportId = arr[0]; |
|
335 arr.Close(); |
|
336 |
|
337 TRAP(err, connection.OpenL( syncProfile, transportId ) ); |
|
338 CleanupClosePushL( connection ); |
|
339 |
|
340 if ( err == KErrNone ) |
|
341 { |
|
342 TInt id = connection.Identifier(); |
|
343 if (id == KUidNSmlMediumTypeInternet.iUid) |
|
344 { |
|
345 BearerType = EAspBearerInternet; |
|
346 } |
|
347 else if (id == KUidNSmlMediumTypeBluetooth.iUid) |
|
348 { |
|
349 BearerType = EAspBearerBlueTooth; |
|
350 } |
|
351 else if (id == KUidNSmlMediumTypeUSB.iUid) |
|
352 { |
|
353 BearerType = EAspBearerUsb; |
|
354 } |
|
355 else if (id == KUidNSmlMediumTypeIrDA.iUid) |
|
356 { |
|
357 BearerType = EAspBearerIrda; |
|
358 } |
|
359 } |
|
360 |
|
361 connection.Close(); |
|
362 CleanupStack::Pop( &connection ); |
|
363 |
|
364 syncProfile.Close(); |
|
365 CleanupStack::Pop( &syncProfile ); |
|
366 |
|
367 syncSession.Close(); |
|
368 CleanupStack::Pop( &syncSession ); |
|
369 return BearerType; |
|
370 } |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CAspSyncHandler::SynchronizeL |
|
373 // |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CAspSyncHandler::SynchronizeL(TAspSyncParam& aSyncParam) |
|
377 { |
|
378 iServerAlertSync = EFalse; |
|
379 iSyncRunning = EFalse; |
|
380 iCurrentSyncJobId = KErrNotFound; |
|
381 iSyncError = KErrNone; |
|
382 iCompleteEventReceived = EFalse; |
|
383 iStopEventReceived = EFalse; |
|
384 iIsSynchronousOperation = EFalse; |
|
385 TBool bCanSync = ETrue; |
|
386 |
|
387 TInt aValue = 0; |
|
388 ReadRepositoryL(KNSmlDSRoamingFeature, aValue); |
|
389 if(( IsRoamingL() ) && (aValue == EAspRoamingSettingFeatureEnabled)) |
|
390 { |
|
391 TInt bearerType = BearerTypeL(aSyncParam.iProfileId); |
|
392 if (bearerType == EAspBearerInternet) |
|
393 { |
|
394 CPreSyncPluginInterface* syncPluginInterface = CPreSyncPluginInterface::NewL(); |
|
395 CPreSyncPlugin* syncPlugin = |
|
396 syncPluginInterface->InstantiateRoamingPluginLC(aSyncParam.iProfileId); |
|
397 |
|
398 if(syncPlugin->IsSupported()) |
|
399 { |
|
400 bCanSync = syncPlugin->CanSyncL(); |
|
401 } |
|
402 |
|
403 CleanupStack::PopAndDestroy(syncPlugin); |
|
404 //syncPluginInterface->UnloadPlugIns(); |
|
405 delete syncPluginInterface; |
|
406 |
|
407 if(!bCanSync) |
|
408 { |
|
409 return; |
|
410 } |
|
411 } |
|
412 } |
|
413 |
|
414 State()->SetSyncPhase(CAspState::EPhaseConnecting); |
|
415 State()->ResetProgress(); |
|
416 //State()->SetTotalProgress(KTotalProgress); |
|
417 |
|
418 TRAPD(err, DoSynchronizeL(aSyncParam)); |
|
419 |
|
420 if (err != KErrNone) |
|
421 { |
|
422 SynchronizeCompleted(err); |
|
423 return; |
|
424 } |
|
425 } |
|
426 |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CAspSyncHandler::DoSynchronizeL |
|
430 // |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 void CAspSyncHandler::DoSynchronizeL(TAspSyncParam& aSyncParam) |
|
434 { |
|
435 FLOG( _L("CAspSyncHandler::DoSynchronizeL START") ); |
|
436 |
|
437 //set the cancel Pub sub key to none |
|
438 if(aSyncParam.iSyncDirection == ESyncDirectionRefreshFromServer) |
|
439 { |
|
440 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
441 KDsJobCancel, KErrNone ); |
|
442 } |
|
443 iApplicationId = aSyncParam.iApplicationId; |
|
444 iProfileId = aSyncParam.iProfileId; |
|
445 if (aSyncParam.iDialogMode == EModeDialogWait) |
|
446 { |
|
447 iIsSynchronousOperation = ETrue; // email 3.2 needs synchronous syncing |
|
448 } |
|
449 |
|
450 |
|
451 ShowProgressDialogL(); |
|
452 OpenSyncSessionL(); |
|
453 CreateContentListL(); |
|
454 |
|
455 iSyncSession.RequestEventL(*this); // for MSyncMLEventObserver events |
|
456 iSyncSession.RequestProgressL(*this); // for MSyncMLProgressObserver events |
|
457 |
|
458 if (aSyncParam.iTaskId != KErrNotFound && iProfileId != KErrNotFound) |
|
459 { |
|
460 RArray<TSmlTaskId> arr(1); |
|
461 CleanupClosePushL(arr); |
|
462 User::LeaveIfError(arr.Append(aSyncParam.iTaskId)); |
|
463 if (aSyncParam.iSyncDirection != KErrNotFound) |
|
464 { |
|
465 TSmlSyncType syncDirection = TAspTask::SmlSyncDirection(aSyncParam.iSyncDirection); |
|
466 iSyncJob.CreateL(iSyncSession, iProfileId, syncDirection, arr); |
|
467 } |
|
468 else |
|
469 { |
|
470 iSyncJob.CreateL(iSyncSession, iProfileId, arr); |
|
471 } |
|
472 |
|
473 CleanupStack::PopAndDestroy(&arr); |
|
474 } |
|
475 else if (iProfileId != KErrNotFound) |
|
476 { |
|
477 if (aSyncParam.iSyncDirection != KErrNotFound) |
|
478 { |
|
479 TSmlSyncType syncDirection = TAspTask::SmlSyncDirection(aSyncParam.iSyncDirection); |
|
480 iSyncJob.CreateL(iSyncSession, iProfileId, syncDirection); |
|
481 } |
|
482 else |
|
483 { |
|
484 iSyncJob.CreateL(iSyncSession, iProfileId); |
|
485 } |
|
486 } |
|
487 else |
|
488 { |
|
489 User::Leave(KErrArgument); |
|
490 } |
|
491 |
|
492 iCurrentSyncJobId = iSyncJob.Identifier(); |
|
493 iSyncRunning = ETrue; |
|
494 |
|
495 if (iIsSynchronousOperation) |
|
496 { |
|
497 iWait->Start(); // stop here until sync has completed |
|
498 } |
|
499 |
|
500 FLOG( _L("sync job created: app=%d, profile=%d, job=%d, task=%d"), iApplicationId, iProfileId, aSyncParam.iJobId, aSyncParam.iTaskId ); |
|
501 FLOG( _L("CAspSyncHandler::DoSynchronizeL END") ); |
|
502 } |
|
503 |
|
504 |
|
505 // ----------------------------------------------------------------------------- |
|
506 // CAspSyncHandler::SynchronizeCompleted |
|
507 // |
|
508 // ----------------------------------------------------------------------------- |
|
509 // |
|
510 void CAspSyncHandler::SynchronizeCompleted(TInt aError) |
|
511 { |
|
512 FLOG( _L("CAspSyncHandler::SynchronizeCompleted START") ); |
|
513 |
|
514 iSyncRunning = EFalse; |
|
515 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
516 KDsJobCancel, KErrNone ); |
|
517 if (aError != KErrNone) |
|
518 { |
|
519 iSyncError = aError; |
|
520 } |
|
521 |
|
522 iSyncJob.Close(); // this can be done when job has not been opened |
|
523 |
|
524 TRAP_IGNORE(Dialog()->CancelProgressDialogL()); |
|
525 |
|
526 if (iSyncError != KErrNone) |
|
527 { |
|
528 CloseSyncSession(); |
|
529 ShowErrorNote(); |
|
530 |
|
531 FLOG( _L("### sync failed (%d) ###"), iSyncError ); |
|
532 } |
|
533 else |
|
534 { |
|
535 CloseSyncSession(); |
|
536 TRAP_IGNORE(TDialogUtil::ShowInformationNoteL(R_ASP_SYNC_COMPLETED)); |
|
537 } |
|
538 |
|
539 if (iSyncObserver) |
|
540 { |
|
541 TRAP_IGNORE(iSyncObserver->HandleSyncEventL(iSyncError, iProfileId)); |
|
542 } |
|
543 |
|
544 if (iIsSynchronousOperation && iWait->IsStarted()) |
|
545 { |
|
546 iWait->AsyncStop(); |
|
547 } |
|
548 |
|
549 FLOG( _L("CAspSyncHandler::SynchronizeCompleted END") ); |
|
550 } |
|
551 |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // CAspSyncHandler::OnSyncMLSessionEvent (from MSyncMLEventObserver) |
|
555 // |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CAspSyncHandler::OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier, TInt aError, TInt /*aAdditionalData*/) |
|
559 { |
|
560 FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent START") ); |
|
561 |
|
562 #ifdef _DEBUG |
|
563 LogSessionEvent(aEvent, aIdentifier, aError); |
|
564 #endif |
|
565 |
|
566 if (iCurrentSyncJobId != aIdentifier) |
|
567 { |
|
568 FLOG( _L("### job conflict (%d/%d) ###"), iCurrentSyncJobId, aIdentifier ); |
|
569 FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent END") ); |
|
570 return; // not our sync job |
|
571 } |
|
572 |
|
573 if (aEvent == EJobStop) |
|
574 { |
|
575 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
576 KDsJobCancel, KErrNone ); |
|
577 |
|
578 iStopEventReceived = ETrue; |
|
579 if (aError != KErrNone) |
|
580 { |
|
581 iSyncError = aError; |
|
582 } |
|
583 |
|
584 if (State()->SyncPhase() == CAspState::EPhaseCanceling) |
|
585 { |
|
586 CompleteWithDelay(aError); |
|
587 } |
|
588 else if (iCompleteEventReceived || iSyncError != KErrNone) |
|
589 { |
|
590 CompleteWithDelay(aError); |
|
591 } |
|
592 } |
|
593 |
|
594 if (aEvent == EJobStartFailed || aEvent == EJobRejected) |
|
595 { |
|
596 RProperty::Set( KPSUidNSmlDSSyncApp, |
|
597 KDsJobCancel, KErrNone ); |
|
598 CompleteWithDelay(aError); |
|
599 } |
|
600 |
|
601 FLOG( _L("CAspSyncHandler::OnSyncMLSessionEvent END") ); |
|
602 } |
|
603 |
|
604 |
|
605 // ----------------------------------------------------------------------------- |
|
606 // CAspSyncHandler::CompleteWithDelay |
|
607 // |
|
608 // ----------------------------------------------------------------------------- |
|
609 // |
|
610 void CAspSyncHandler::CompleteWithDelay(TInt aError) |
|
611 { |
|
612 iActiveCaller->Start(aError, 0); // call SynchronizeCompleted with delay |
|
613 } |
|
614 |
|
615 |
|
616 // ----------------------------------------------------------------------------- |
|
617 // CAspSyncHandler::OnSyncMLSyncError (from MSyncMLProgressObserver) |
|
618 // |
|
619 // ----------------------------------------------------------------------------- |
|
620 // |
|
621 void CAspSyncHandler::OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, TInt /*aTaskId*/, TInt /*aInfo1*/, TInt /*aInfo2*/) |
|
622 { |
|
623 FLOG( _L("CAspSyncHandler::OnSyncMLSyncError START") ); |
|
624 |
|
625 // just store error code - sync is terminated only in function OnSyncMLSessionEvent |
|
626 if (aErrorLevel == ESmlFatalError || aErrorLevel == ESmlWarning) |
|
627 { |
|
628 iSyncError = aError; |
|
629 } |
|
630 |
|
631 #ifdef _DEBUG |
|
632 LogErrorEvent(aErrorLevel, aError); |
|
633 #endif |
|
634 |
|
635 FLOG( _L("CAspSyncHandler::OnSyncMLSyncError END") ); |
|
636 } |
|
637 |
|
638 |
|
639 // ----------------------------------------------------------------------------- |
|
640 // CAspSyncHandler::OnSyncMLSyncProgress (from MSyncMLProgressObserver) |
|
641 // |
|
642 // ----------------------------------------------------------------------------- |
|
643 // |
|
644 void CAspSyncHandler::OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt /*aInfo2*/) |
|
645 { |
|
646 FLOG( _L("CAspSyncHandler::OnSyncMLSyncProgress START") ); |
|
647 |
|
648 if (State()->SyncPhase() == CAspState::EPhaseCanceling) |
|
649 { |
|
650 return; // no progress dialog updating while canceling |
|
651 } |
|
652 |
|
653 #ifdef _DEBUG |
|
654 LogProgressEvent(aStatus, aInfo1); |
|
655 #endif |
|
656 |
|
657 switch (aStatus) |
|
658 { |
|
659 case ESmlConnecting: |
|
660 State()->SetSyncPhase(CAspState::EPhaseConnecting); |
|
661 UpdateDialog(); |
|
662 break; |
|
663 case ESmlConnected: |
|
664 break; |
|
665 case ESmlLoggingOn: |
|
666 break; |
|
667 case ESmlLoggedOn: |
|
668 State()->SetSyncPhase(CAspState::EPhaseSynchronizing); |
|
669 UpdateDialog(); |
|
670 break; |
|
671 case ESmlDisconnected: |
|
672 State()->SetSyncPhase(CAspState::EPhaseDisconnecting); |
|
673 UpdateDialog(); |
|
674 break; |
|
675 case ESmlCompleted: |
|
676 iCompleteEventReceived = ETrue; |
|
677 |
|
678 if (iStopEventReceived) |
|
679 { |
|
680 FLOG( _L("### EJobStop already received ###") ); |
|
681 CompleteWithDelay(iSyncError); |
|
682 } |
|
683 else |
|
684 { |
|
685 State()->SetSyncPhase(CAspState::EPhaseDisconnecting); |
|
686 UpdateDialog(); |
|
687 } |
|
688 break; |
|
689 |
|
690 case ESmlSendingModificationsToServer: |
|
691 State()->SetSyncPhase(CAspState::EPhaseSending); |
|
692 State()->ResetProgress(); |
|
693 State()->SetTotalProgress(aInfo1); // set total sync event count |
|
694 |
|
695 UpdateDialog(); |
|
696 break; |
|
697 case ESmlReceivingModificationsFromServer: |
|
698 State()->SetSyncPhase(CAspState::EPhaseReceiving); |
|
699 State()->ResetProgress(); |
|
700 State()->SetTotalProgress(aInfo1); // set total sync event count |
|
701 |
|
702 UpdateDialog(); |
|
703 break; |
|
704 |
|
705 case ESmlSendingMappingsToServer: |
|
706 State()->SetSyncPhase(CAspState::EPhaseSynchronizing); |
|
707 UpdateDialog(); |
|
708 break; |
|
709 |
|
710 default: |
|
711 break; |
|
712 } |
|
713 |
|
714 FLOG( _L("CAspSyncHandler::OnSyncMLSyncProgress END") ); |
|
715 } |
|
716 |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CAspSyncHandler::OnSyncMLDataSyncModifications (from MSyncMLProgressObserver) |
|
720 // |
|
721 // ----------------------------------------------------------------------------- |
|
722 // |
|
723 void CAspSyncHandler::OnSyncMLDataSyncModifications(TInt aTaskId, |
|
724 const TSyncMLDataSyncModifications& aClientModifications, |
|
725 const TSyncMLDataSyncModifications& aServerModifications) |
|
726 { |
|
727 |
|
728 if (!Dialog()->ProgressDialog()) |
|
729 { |
|
730 //it is observed that some times this call back comes |
|
731 //just after deleting progress dialog. |
|
732 return; |
|
733 } |
|
734 |
|
735 TRAPD(err, OnSyncMLDataSyncModificationsL(aTaskId, aClientModifications, aServerModifications)); |
|
736 if (err != KErrNone) |
|
737 { |
|
738 FLOG( _L("### CAspSyncHandler::OnSyncMLDataSyncModificationsL failed (%d) ###"), err ); |
|
739 FLOG( _L("### CAspSyncHandler::OnSyncMLDataSyncModificationsL failed (%d) ###"), err ); |
|
740 } |
|
741 } |
|
742 |
|
743 |
|
744 // ----------------------------------------------------------------------------- |
|
745 // CAspSyncHandler::OnSyncMLDataSyncModificationsL |
|
746 // |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 void CAspSyncHandler::OnSyncMLDataSyncModificationsL(TInt aTaskId, |
|
750 const TSyncMLDataSyncModifications& aClientModifications, |
|
751 const TSyncMLDataSyncModifications& aServerModifications) |
|
752 { |
|
753 FLOG( _L("CAspSyncHandler::OnSyncMLDataSyncModificationsL START") ); |
|
754 |
|
755 |
|
756 if (State()->Progress() == 0) |
|
757 { |
|
758 TInt index = iContentList->FindProviderIndexForTask(aTaskId); |
|
759 |
|
760 if (index != KErrNotFound) |
|
761 { |
|
762 TAspProviderItem& item = iContentList->ProviderItem(index); |
|
763 HBufC* hBuf = CAspResHandler::GetContentNameLC(item.iDataProviderId, |
|
764 item.iDisplayName); |
|
765 State()->SetContentL(hBuf->Des()); |
|
766 |
|
767 #ifdef _DEBUG |
|
768 LogModificationEvent(aTaskId, hBuf->Des()); |
|
769 #endif |
|
770 |
|
771 CleanupStack::PopAndDestroy(hBuf); |
|
772 } |
|
773 else |
|
774 { |
|
775 State()->SetContentL(KNullDesC); |
|
776 FLOG( _L("### task not found (%d) ###"), aTaskId ); |
|
777 } |
|
778 } |
|
779 |
|
780 // Set sync event count. On last OnSyncMLDataSyncModifications call it |
|
781 // must match total sync event count (set in OnSyncMLSyncProgress). |
|
782 TInt count = ProgressCount(aClientModifications, aServerModifications); |
|
783 State()->IncreaseProgress(count); |
|
784 |
|
785 UpdateDialog(); |
|
786 |
|
787 |
|
788 #ifdef _DEBUG |
|
789 LogModificationEvent(aTaskId, aClientModifications, aServerModifications); |
|
790 #endif |
|
791 |
|
792 |
|
793 FLOG( _L("CAspSyncHandler::OnSyncMLDataSyncModificationsL END") ); |
|
794 FLOG( _L(" ") ); |
|
795 } |
|
796 |
|
797 |
|
798 |
|
799 // ----------------------------------------------------------------------------- |
|
800 // CAspSyncHandler::UpdateDialog |
|
801 // |
|
802 // ----------------------------------------------------------------------------- |
|
803 // |
|
804 void CAspSyncHandler::UpdateDialog() |
|
805 { |
|
806 TRAPD(err, UpdateDialogL()); |
|
807 |
|
808 if (err != KErrNone) |
|
809 { |
|
810 FLOG( _L("### CAspSyncHandler::UpdateDialogL failed (%d) ###"), err ); |
|
811 } |
|
812 } |
|
813 |
|
814 |
|
815 // ----------------------------------------------------------------------------- |
|
816 // CAspSyncHandler::UpdateDialogL |
|
817 // |
|
818 // ----------------------------------------------------------------------------- |
|
819 // |
|
820 void CAspSyncHandler::UpdateDialogL() |
|
821 { |
|
822 if (!SyncRunning()) |
|
823 { |
|
824 FLOG( _L("### CAspSyncHandler::UpdateDialogL: Sync not running ###") ); |
|
825 return; |
|
826 } |
|
827 |
|
828 TInt phase = State()->SyncPhase(); |
|
829 |
|
830 if (phase == CAspState::EPhaseConnecting) |
|
831 { |
|
832 Dialog()->StartAnimationL(); |
|
833 HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_CONN); // "Connecting" |
|
834 Dialog()->UpdateTextL(hBuf->Des()); |
|
835 CleanupStack::PopAndDestroy(hBuf); |
|
836 } |
|
837 |
|
838 if (phase == CAspState::EPhaseSynchronizing) |
|
839 { |
|
840 Dialog()->StartAnimationL(); |
|
841 HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_SYNC); // "Synchronizing" |
|
842 Dialog()->UpdateTextL(hBuf->Des()); |
|
843 CleanupStack::PopAndDestroy(hBuf); |
|
844 } |
|
845 |
|
846 if (phase == CAspState::EPhaseDisconnecting) |
|
847 { |
|
848 Dialog()->StartAnimationL(); |
|
849 HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_SYNC_DISC); // "Disconnecting" |
|
850 Dialog()->UpdateTextL(hBuf->Des()); |
|
851 CleanupStack::PopAndDestroy(hBuf); |
|
852 } |
|
853 |
|
854 if (phase == CAspState::EPhaseCanceling) |
|
855 { |
|
856 Dialog()->StartAnimationL(); |
|
857 HBufC* hBuf = ResHandlerL()->ReadLC(R_SYNCSTATUS_CANC); // "Canceling" |
|
858 Dialog()->UpdateTextL(hBuf->Des()); |
|
859 CleanupStack::PopAndDestroy(hBuf); |
|
860 Dialog()->HideButtonL(); |
|
861 } |
|
862 |
|
863 //The number of Emails-Synced NOT printed if Sync is started from Sync E-mail Application |
|
864 if (iApplicationId == EApplicationIdEmail) |
|
865 return; |
|
866 |
|
867 if (phase == CAspState::EPhaseSending || phase == CAspState::EPhaseReceiving) |
|
868 { |
|
869 if (State()->Progress() == 0 || State()->TotalProgress() == 0) |
|
870 { |
|
871 return; |
|
872 } |
|
873 |
|
874 if (State()->FirstProgress()) |
|
875 { |
|
876 if (State()->ProgressKnown()) |
|
877 { |
|
878 Dialog()->CancelAnimation(); |
|
879 Dialog()->SetFinalProgress(State()->TotalProgress()); |
|
880 Dialog()->SetProgress(State()->Progress()); |
|
881 } |
|
882 else |
|
883 { |
|
884 Dialog()->SetFinalProgress(0); |
|
885 Dialog()->StartAnimationL(); |
|
886 } |
|
887 } |
|
888 else if (State()->ProgressKnown()) |
|
889 { |
|
890 Dialog()->SetProgress(State()->Progress()); |
|
891 } |
|
892 |
|
893 /* Implementation of CMCC PIM v3 begins*/ |
|
894 HBufC* hBuf = NULL; |
|
895 if ( FeatureManager::FeatureSupported(KFeatureIdFfTdCmccpimsynchronizationprogressindicatorui) ) |
|
896 { |
|
897 // CMCC sync progress indicator enabled |
|
898 hBuf = ResHandlerL()->ReadProgressTextLC(State()->Content(), State()->Progress(), State()->TotalProgress(), phase); |
|
899 } |
|
900 else |
|
901 { |
|
902 hBuf = ResHandlerL()->ReadProgressTextLC(State()->Content(), phase); |
|
903 } |
|
904 /* Implementation of CMCC PIM v3 ends*/ |
|
905 |
|
906 |
|
907 #ifdef _DEBUG |
|
908 TBuf<KBufSize> buf1; TBuf<KBufSize> buf2; |
|
909 buf1 = hBuf->Des(); |
|
910 buf2.Format(_L("%S\n (%d/%d)"), &buf1, State()->Progress(), State()->TotalProgress()); |
|
911 CleanupStack::PopAndDestroy(hBuf); |
|
912 hBuf = NULL; |
|
913 hBuf = buf2.AllocLC(); |
|
914 #endif |
|
915 |
|
916 |
|
917 Dialog()->UpdateTextL(hBuf->Des()); |
|
918 CleanupStack::PopAndDestroy(hBuf); |
|
919 } |
|
920 } |
|
921 |
|
922 |
|
923 // ----------------------------------------------------------------------------- |
|
924 // CAspSyncHandler::UpdateRequired |
|
925 // |
|
926 // ----------------------------------------------------------------------------- |
|
927 // |
|
928 TBool CAspSyncHandler::UpdateRequired() |
|
929 { |
|
930 const TInt KProgressLevel_1 = 10; |
|
931 const TInt KProgressLevel_2 = 20; |
|
932 const TInt KProgressLevel_3 = 50; |
|
933 |
|
934 const TInt KProgressStep_1 = 5; |
|
935 const TInt KProgressStep_2 = 10; |
|
936 const TInt KProgressStep_3 = 20; |
|
937 |
|
938 TInt total = State()->TotalProgress(); |
|
939 TInt current = State()->Progress(); |
|
940 TBool firstProgress = State()->FirstProgress(); |
|
941 TBool progressKnown = State()->ProgressKnown(); |
|
942 |
|
943 // always show first progress |
|
944 if (firstProgress) |
|
945 { |
|
946 return ETrue; |
|
947 } |
|
948 |
|
949 // handle case where total progress count is not known |
|
950 if (!progressKnown) |
|
951 { |
|
952 if (current <= KProgressStep_2) |
|
953 { |
|
954 return ETrue; |
|
955 } |
|
956 else if (current % KProgressStep_1 == 0) |
|
957 { |
|
958 return ETrue; |
|
959 } |
|
960 |
|
961 return EFalse; |
|
962 } |
|
963 |
|
964 // handle case where total progress count is known |
|
965 if (current == total) |
|
966 { |
|
967 return ETrue; // always show last progress |
|
968 } |
|
969 else if (total <= KProgressLevel_1) |
|
970 { |
|
971 return ETrue; |
|
972 } |
|
973 else if (total > KProgressLevel_1 && total <= KProgressLevel_2) |
|
974 { |
|
975 if (current % KProgressStep_1 == 0) |
|
976 { |
|
977 return ETrue; |
|
978 } |
|
979 } |
|
980 else if (total > KProgressLevel_2 && total <= KProgressLevel_3) |
|
981 { |
|
982 if (current % KProgressStep_2 == 0) |
|
983 { |
|
984 return ETrue; |
|
985 } |
|
986 } |
|
987 else if (total > KProgressLevel_3) |
|
988 { |
|
989 if (current % KProgressStep_3 == 0) |
|
990 { |
|
991 return ETrue; |
|
992 } |
|
993 } |
|
994 |
|
995 return EFalse; |
|
996 } |
|
997 |
|
998 |
|
999 // ----------------------------------------------------------------------------- |
|
1000 // CAspSyncHandler::HandleActiveCallL (from MAspActiveCallerObserver) |
|
1001 // |
|
1002 // ----------------------------------------------------------------------------- |
|
1003 // |
|
1004 void CAspSyncHandler::HandleActiveCallL(TInt aCallId) |
|
1005 { |
|
1006 SynchronizeCompleted(aCallId); |
|
1007 } |
|
1008 |
|
1009 |
|
1010 // ----------------------------------------------------------------------------- |
|
1011 // CAspSyncHandler::ShowErrorNote |
|
1012 // |
|
1013 // ----------------------------------------------------------------------------- |
|
1014 // |
|
1015 void CAspSyncHandler::ShowErrorNote() |
|
1016 { |
|
1017 if (iSyncError == KErrNone || iSyncError == KErrCancel) |
|
1018 { |
|
1019 return; // nothing to show |
|
1020 } |
|
1021 |
|
1022 // show sync engine error |
|
1023 if (iSyncError <= SyncMLError::KErrSyncEngineErrorBase) |
|
1024 { |
|
1025 HBufC* hBuf = NULL; |
|
1026 hBuf = TAspSyncError::GetSmlErrorText(iSyncError, 0); |
|
1027 if (hBuf) // hBuf can be NULL |
|
1028 { |
|
1029 TRAP_IGNORE(TDialogUtil::ShowErrorQueryL(hBuf->Des())); |
|
1030 delete hBuf; |
|
1031 } |
|
1032 |
|
1033 return; |
|
1034 } |
|
1035 |
|
1036 // show system error |
|
1037 TPtrC errorMsg; |
|
1038 |
|
1039 errorMsg.Set(iTextResolver->ResolveErrorString(iSyncError, CTextResolver::ECtxNoCtxNoSeparator)); |
|
1040 |
|
1041 TRAP_IGNORE(TDialogUtil::ShowErrorQueryL(errorMsg)); |
|
1042 } |
|
1043 |
|
1044 // ----------------------------------------------------------------------------- |
|
1045 // CAspSyncHandler::ShowProgressDialogL |
|
1046 // |
|
1047 // ----------------------------------------------------------------------------- |
|
1048 // |
|
1049 void CAspSyncHandler::ShowProgressDialogL() |
|
1050 { |
|
1051 delete iProgressDialog; |
|
1052 iProgressDialog = NULL; |
|
1053 iProgressDialog = CAspProgressDialog::NewL(this); |
|
1054 |
|
1055 TInt resId = R_SYNCSTATUS_SYNC_CONN; |
|
1056 if (iApplicationId == EApplicationIdEmail) |
|
1057 { |
|
1058 resId = R_SYNCSTATUS_SYNC_SYNC; |
|
1059 } |
|
1060 |
|
1061 HBufC* hBuf = CAspResHandler::ReadLC(resId); |
|
1062 |
|
1063 iProgressDialog->SetApplicationId(iApplicationId); |
|
1064 |
|
1065 TFileName bitmapName; |
|
1066 CAspResHandler::GetBitmapFileName(bitmapName); |
|
1067 |
|
1068 iProgressDialog->LaunchProgressDialogL(hBuf->Des(), |
|
1069 KAknsIIDQgnNoteSml, |
|
1070 bitmapName, |
|
1071 EMbmAspsyncutilQgn_note_sml, |
|
1072 EMbmAspsyncutilQgn_note_sml_mask); |
|
1073 CleanupStack::PopAndDestroy(hBuf); |
|
1074 } |
|
1075 |
|
1076 |
|
1077 // ----------------------------------------------------------------------------- |
|
1078 // CAspSyncHandler::CreateContentListL |
|
1079 // |
|
1080 // ----------------------------------------------------------------------------- |
|
1081 // |
|
1082 void CAspSyncHandler::CreateContentListL() |
|
1083 { |
|
1084 TAspParam param(iApplicationId, &iSyncSession); |
|
1085 |
|
1086 CAspProfile* profile = CAspProfile::NewLC(param); |
|
1087 profile->OpenL(iProfileId, CAspProfile::EOpenRead, CAspProfile::EBaseProperties); |
|
1088 |
|
1089 param.iProfile = profile; |
|
1090 param.iMode = CAspContentList::EInitAll; |
|
1091 |
|
1092 delete iContentList; |
|
1093 iContentList = NULL; |
|
1094 iContentList = CAspContentList::NewL(param); |
|
1095 |
|
1096 CleanupStack::PopAndDestroy(profile); |
|
1097 } |
|
1098 |
|
1099 |
|
1100 // ----------------------------------------------------------------------------- |
|
1101 // CAspSyncHandler::CheckLocalDatabaseL |
|
1102 // |
|
1103 // ----------------------------------------------------------------------------- |
|
1104 // |
|
1105 void CAspSyncHandler::CheckLocalDatabaseL(TInt aProfileId) |
|
1106 { |
|
1107 TAspParam param(iApplicationId, &iSyncSession); |
|
1108 |
|
1109 CAspProfile* profile = CAspProfile::NewLC(param); |
|
1110 profile->OpenL(aProfileId, CAspProfile::EOpenRead, CAspProfile::EBaseProperties); |
|
1111 |
|
1112 TInt dataProviderId = KErrNotFound; |
|
1113 TBool databaseFound = TAspTask::CheckLocalDatabase(profile, dataProviderId); |
|
1114 CleanupStack::PopAndDestroy(profile); |
|
1115 |
|
1116 if (!databaseFound) |
|
1117 { |
|
1118 User::Leave(SyncMLError::KErrClientDatabaseNotFound); |
|
1119 } |
|
1120 } |
|
1121 |
|
1122 |
|
1123 |
|
1124 // ----------------------------------------------------------------------------- |
|
1125 // CAspSyncHandler::Dialog |
|
1126 // |
|
1127 // ----------------------------------------------------------------------------- |
|
1128 // |
|
1129 CAspProgressDialog* CAspSyncHandler::Dialog() |
|
1130 { |
|
1131 __ASSERT_DEBUG(iProgressDialog, TUtil::Panic(KErrGeneral)); |
|
1132 |
|
1133 return iProgressDialog; |
|
1134 } |
|
1135 |
|
1136 |
|
1137 // ----------------------------------------------------------------------------- |
|
1138 // CAspSyncHandler::State |
|
1139 // |
|
1140 // ----------------------------------------------------------------------------- |
|
1141 // |
|
1142 CAspState* CAspSyncHandler::State() |
|
1143 { |
|
1144 __ASSERT_DEBUG(iState, TUtil::Panic(KErrGeneral)); |
|
1145 |
|
1146 return iState; |
|
1147 } |
|
1148 |
|
1149 |
|
1150 // ----------------------------------------------------------------------------- |
|
1151 // CAspSyncHandler::ResHandlerL |
|
1152 // |
|
1153 // ----------------------------------------------------------------------------- |
|
1154 // |
|
1155 CAspResHandler* CAspSyncHandler::ResHandlerL() |
|
1156 { |
|
1157 if (!iResHandler) |
|
1158 { |
|
1159 iResHandler = CAspResHandler::NewL(); |
|
1160 } |
|
1161 |
|
1162 return iResHandler; |
|
1163 } |
|
1164 |
|
1165 |
|
1166 // ----------------------------------------------------------------------------- |
|
1167 // SyncRunning |
|
1168 // |
|
1169 // ----------------------------------------------------------------------------- |
|
1170 // |
|
1171 TBool CAspSyncHandler::SyncRunning() |
|
1172 { |
|
1173 return iSyncRunning; |
|
1174 } |
|
1175 |
|
1176 // ----------------------------------------------------------------------------- |
|
1177 // IsServerAlertSync |
|
1178 // |
|
1179 // ----------------------------------------------------------------------------- |
|
1180 // |
|
1181 TBool CAspSyncHandler::IsServerAlertSync() |
|
1182 { |
|
1183 return iServerAlertSync; |
|
1184 } |
|
1185 |
|
1186 |
|
1187 // ----------------------------------------------------------------------------- |
|
1188 // OpenSyncSessionL |
|
1189 // |
|
1190 // ----------------------------------------------------------------------------- |
|
1191 // |
|
1192 void CAspSyncHandler::OpenSyncSessionL() |
|
1193 { |
|
1194 if (!iSyncSessionOpen) |
|
1195 { |
|
1196 TRAPD(err, iSyncSession.OpenL()); |
|
1197 |
|
1198 if (err != KErrNone) |
|
1199 { |
|
1200 FLOG( _L("### CAspSyncHandler: RSyncMLSession::OpenL failed (%d) ###"), err ); |
|
1201 User::Leave(err); |
|
1202 } |
|
1203 |
|
1204 iSyncSessionOpen = ETrue; |
|
1205 } |
|
1206 } |
|
1207 |
|
1208 |
|
1209 // ----------------------------------------------------------------------------- |
|
1210 // CloseSyncSession |
|
1211 // |
|
1212 // ----------------------------------------------------------------------------- |
|
1213 // |
|
1214 void CAspSyncHandler::CloseSyncSession() |
|
1215 { |
|
1216 if (iSyncSessionOpen) |
|
1217 { |
|
1218 iSyncSession.Close(); |
|
1219 iSyncSessionOpen = EFalse; |
|
1220 } |
|
1221 } |
|
1222 |
|
1223 |
|
1224 // ----------------------------------------------------------------------------- |
|
1225 // ProgressCount |
|
1226 // |
|
1227 // ----------------------------------------------------------------------------- |
|
1228 // |
|
1229 TInt CAspSyncHandler::ProgressCount(const TSyncMLDataSyncModifications& aC, |
|
1230 const TSyncMLDataSyncModifications& aS) |
|
1231 { |
|
1232 TInt num1 = aC.iNumAdded + aC.iNumReplaced + aC.iNumMoved + aC.iNumDeleted + aC.iNumFailed; |
|
1233 TInt num2 = aS.iNumAdded + aS.iNumReplaced + aS.iNumMoved + aS.iNumDeleted + aS.iNumFailed; |
|
1234 |
|
1235 return num1 + num2; |
|
1236 } |
|
1237 |
|
1238 |
|
1239 |
|
1240 #ifdef _DEBUG |
|
1241 |
|
1242 |
|
1243 // ----------------------------------------------------------------------------- |
|
1244 // LogModificationEvent |
|
1245 // |
|
1246 // ----------------------------------------------------------------------------- |
|
1247 // |
|
1248 void CAspSyncHandler::LogModificationEvent(TInt aTaskId, const TSyncMLDataSyncModifications& aC, const TSyncMLDataSyncModifications& aS) |
|
1249 { |
|
1250 TInt num1 = State()->Progress(); |
|
1251 TInt num2 = State()->TotalProgress(); |
|
1252 |
|
1253 if (num1 > num2 && num2 != -1) |
|
1254 { |
|
1255 FTRACE( RDebug::Print(_L("### syncui: task=%d, progress=%d, totalprogress=%d ###"), aTaskId, num1, num2) ); |
|
1256 FLOG(_L("### syncui: task=%d, progress=%d, totalprogress=%d ###"), aTaskId, num1, num2); |
|
1257 } |
|
1258 else |
|
1259 { |
|
1260 FTRACE( RDebug::Print(_L("syncui: task=%d, progress=%d, totalprogress=%d"), aTaskId, num1, num2) ); |
|
1261 FLOG(_L("syncui: task=%d, progress=%d, totalprogress=%d"), aTaskId, num1, num2); |
|
1262 } |
|
1263 |
|
1264 num1 = aC.iNumAdded + aC.iNumReplaced + aC.iNumMoved + aC.iNumDeleted + aC.iNumFailed; |
|
1265 num2 = aS.iNumAdded + aS.iNumReplaced + aS.iNumMoved + aS.iNumDeleted + aS.iNumFailed; |
|
1266 |
|
1267 if ( (num1>0 && num2>0) || (num1<0 || num2<0) || (num1==0 && num2==0) ) |
|
1268 { |
|
1269 FLOG( _L("### parameter error ###") ); |
|
1270 } |
|
1271 |
|
1272 FTRACE( RDebug::Print(_L("client: add=%d, rep=%d, mov=%d del=%d fai=%d"), aC.iNumAdded, aC.iNumReplaced, aC.iNumMoved, aC.iNumDeleted, aC.iNumFailed) ); |
|
1273 FTRACE( RDebug::Print(_L("server: add=%d, rep=%d, mov=%d del=%d fai=%d"), aS.iNumAdded, aS.iNumReplaced, aS.iNumMoved, aS.iNumDeleted, aS.iNumFailed) ); |
|
1274 |
|
1275 FLOG(_L("client: add=%d, rep=%d, mov=%d del=%d fai=%d"), aC.iNumAdded, aC.iNumReplaced, aC.iNumMoved, aC.iNumDeleted, aC.iNumFailed); |
|
1276 FLOG(_L("server: add=%d, rep=%d, mov=%d del=%d fai=%d"), aS.iNumAdded, aS.iNumReplaced, aS.iNumMoved, aS.iNumDeleted, aS.iNumFailed); |
|
1277 } |
|
1278 |
|
1279 |
|
1280 // ----------------------------------------------------------------------------- |
|
1281 // LogModificationEvent |
|
1282 // |
|
1283 // ----------------------------------------------------------------------------- |
|
1284 // |
|
1285 void CAspSyncHandler::LogModificationEvent(TInt aTaskId, const TDesC& aText) |
|
1286 { |
|
1287 FTRACE( RDebug::Print(_L("progress = 0, task id = %d, task name ='%S'"), aTaskId, &aText) ); |
|
1288 FLOG(_L("progress = 0, task id = %d, task name ='%S'"), aTaskId, &aText); |
|
1289 } |
|
1290 |
|
1291 |
|
1292 // ----------------------------------------------------------------------------- |
|
1293 // LogSessionEvent |
|
1294 // |
|
1295 // ----------------------------------------------------------------------------- |
|
1296 // |
|
1297 void CAspSyncHandler::LogSessionEvent(TEvent& aEvent, TInt aIdentifier, TInt aError) |
|
1298 { |
|
1299 TBuf<KBufSize> eventStr; |
|
1300 GetSyncEventText(eventStr, aEvent); |
|
1301 |
|
1302 TBuf<KBufSize> errStr; |
|
1303 TAspSyncError::GetSyncMLErrorText(errStr, aError); |
|
1304 |
|
1305 if (aError == KErrNone) |
|
1306 { |
|
1307 FTRACE( RDebug::Print(_L("event='%S' err='%S' job= %d curjob= %d"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId) ); |
|
1308 FLOG(_L("event='%S' err='%S' job= %d curjob= %d"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId); |
|
1309 } |
|
1310 else |
|
1311 { |
|
1312 FTRACE( RDebug::Print(_L("### event='%S' err='%S' job= %d curjob= %d ###"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId) ); |
|
1313 FLOG(_L("### event='%S' err='%S' job= %d curjob= %d ###"), &eventStr, &errStr, aIdentifier, iCurrentSyncJobId); |
|
1314 } |
|
1315 } |
|
1316 |
|
1317 |
|
1318 // ----------------------------------------------------------------------------- |
|
1319 // LogProgressEvent |
|
1320 // |
|
1321 // ----------------------------------------------------------------------------- |
|
1322 // |
|
1323 void CAspSyncHandler::LogProgressEvent(TStatus& aStatus, TInt aInfo1) |
|
1324 { |
|
1325 TBuf<KBufSize> statusStr; |
|
1326 GetSyncStatusText(statusStr, aStatus); |
|
1327 FTRACE( RDebug::Print(_L("OnSyncMLSyncProgress: status = '%S' info1 = %d"), &statusStr, aInfo1) ); |
|
1328 FLOG(_L("OnSyncMLSyncProgress: status = '%S' info1 = %d"), &statusStr, aInfo1); |
|
1329 |
|
1330 TInt num1 = State()->Progress(); |
|
1331 TInt num2 = State()->TotalProgress(); |
|
1332 if (num1 != num2 && num2 != -1) |
|
1333 { |
|
1334 FTRACE( RDebug::Print(_L("### progress count error (%d/%d) ###"), num1, num2) ); |
|
1335 FLOG(_L("### progress count error (%d/%d) ###"), num1, num2); |
|
1336 } |
|
1337 } |
|
1338 |
|
1339 |
|
1340 // ----------------------------------------------------------------------------- |
|
1341 // LogErrorEvent |
|
1342 // |
|
1343 // ----------------------------------------------------------------------------- |
|
1344 // |
|
1345 void CAspSyncHandler::LogErrorEvent(TErrorLevel aErrorLevel, TInt aError) |
|
1346 { |
|
1347 TBuf<KBufSize> errStr; |
|
1348 TAspSyncError::GetSyncMLErrorText(errStr, aError); |
|
1349 |
|
1350 if (aErrorLevel == ESmlFatalError) |
|
1351 { |
|
1352 FTRACE( RDebug::Print(_L("### OnSyncMLSyncError: fatalerror = %S ###"), &errStr) ); |
|
1353 FLOG(_L("### OnSyncMLSyncError: fatalerror = %S ###"), &errStr); |
|
1354 } |
|
1355 else |
|
1356 { |
|
1357 FTRACE( RDebug::Print(_L("### OnSyncMLSyncError: error = %S ###"), &errStr) ); |
|
1358 FLOG(_L("### OnSyncMLSyncError: error = %S ###"), &errStr); |
|
1359 } |
|
1360 } |
|
1361 |
|
1362 |
|
1363 |
|
1364 // ----------------------------------------------------------------------------- |
|
1365 // GetSyncStatusText |
|
1366 // |
|
1367 // ----------------------------------------------------------------------------- |
|
1368 // |
|
1369 void CAspSyncHandler::GetSyncStatusText(TDes& aText, MSyncMLProgressObserver::TStatus aStatus) |
|
1370 { |
|
1371 aText = _L("Unknown"); |
|
1372 |
|
1373 if (aStatus == MSyncMLProgressObserver::ESmlConnecting) |
|
1374 { |
|
1375 aText = _L("ESmlConnecting"); |
|
1376 } |
|
1377 if (aStatus == MSyncMLProgressObserver::ESmlConnected) |
|
1378 { |
|
1379 aText = _L("ESmlConnected"); |
|
1380 } |
|
1381 if (aStatus == MSyncMLProgressObserver::ESmlLoggingOn) |
|
1382 { |
|
1383 aText = _L("ESmlLoggingOn"); |
|
1384 } |
|
1385 if (aStatus == MSyncMLProgressObserver::ESmlLoggedOn) |
|
1386 { |
|
1387 aText = _L("ESmlLoggedOn"); |
|
1388 } |
|
1389 if (aStatus == MSyncMLProgressObserver::ESmlDisconnected) |
|
1390 { |
|
1391 aText = _L("ESmlDisconnected"); |
|
1392 } |
|
1393 if (aStatus == MSyncMLProgressObserver::ESmlCompleted) |
|
1394 { |
|
1395 aText = _L("ESmlCompleted"); |
|
1396 } |
|
1397 if (aStatus == MSyncMLProgressObserver::ESmlSendingModificationsToServer) |
|
1398 { |
|
1399 aText = _L("ESmlSendingModificationsToServer"); |
|
1400 } |
|
1401 if (aStatus == MSyncMLProgressObserver::ESmlReceivingModificationsFromServer) |
|
1402 { |
|
1403 aText = _L("ESmlReceivingModificationsFromServer"); |
|
1404 } |
|
1405 if (aStatus == MSyncMLProgressObserver::ESmlSendingMappingsToServer) |
|
1406 { |
|
1407 aText = _L("ESmlSendingMappingsToServer"); |
|
1408 } |
|
1409 } |
|
1410 |
|
1411 |
|
1412 // ----------------------------------------------------------------------------- |
|
1413 // GetSyncEventText |
|
1414 // |
|
1415 // ----------------------------------------------------------------------------- |
|
1416 // |
|
1417 void CAspSyncHandler::GetSyncEventText(TDes& aText, MSyncMLEventObserver::TEvent aEvent) |
|
1418 { |
|
1419 aText = _L("Unknown"); |
|
1420 |
|
1421 if (aEvent == MSyncMLEventObserver::EJobStart) |
|
1422 { |
|
1423 aText = _L("EJobStart"); |
|
1424 } |
|
1425 if (aEvent == MSyncMLEventObserver::EJobStartFailed) |
|
1426 { |
|
1427 aText = _L("EJobStartFailed"); |
|
1428 } |
|
1429 if (aEvent == MSyncMLEventObserver::EJobStop) |
|
1430 { |
|
1431 aText = _L("EJobStop"); |
|
1432 } |
|
1433 if (aEvent == MSyncMLEventObserver::EJobRejected) |
|
1434 { |
|
1435 aText = _L("EJobRejected"); |
|
1436 } |
|
1437 if (aEvent == MSyncMLEventObserver::EProfileCreated) |
|
1438 { |
|
1439 aText = _L("EProfileCreated"); |
|
1440 } |
|
1441 if (aEvent == MSyncMLEventObserver::EProfileChanged) |
|
1442 { |
|
1443 aText = _L("EProfileChanged"); |
|
1444 } |
|
1445 if (aEvent == MSyncMLEventObserver::EProfileDeleted) |
|
1446 { |
|
1447 aText = _L("EProfileDeleted"); |
|
1448 } |
|
1449 if (aEvent == MSyncMLEventObserver::ETransportTimeout) |
|
1450 { |
|
1451 aText = _L("ETransportTimeout"); |
|
1452 } |
|
1453 if (aEvent == MSyncMLEventObserver::EServerSuspended) |
|
1454 { |
|
1455 aText = _L("EServerSuspended"); |
|
1456 } |
|
1457 if (aEvent == MSyncMLEventObserver::EServerTerminated) |
|
1458 { |
|
1459 aText = _L("EServerTerminated"); |
|
1460 } |
|
1461 } |
|
1462 |
|
1463 #endif |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 // End of file |
|
1470 |