|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // [INCLUDE FILES] - do not remove |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <Stiftestinterface.h> |
|
24 #include "testprofileutil.h" |
|
25 //SyncML headers |
|
26 #include <SyncMLDef.h> |
|
27 #include <SyncMLClient.h> |
|
28 #include <SyncMLClientDS.h> |
|
29 #include <SyncMLClientDM.h> |
|
30 #include <SyncMLTransportProperties.h> |
|
31 #include <commdb.h> |
|
32 #include "nsmlconstants.h" |
|
33 |
|
34 #include "NsmlProfileUtil.h" |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 // ============================== MEMBER FUNCTIONS ============================ |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // CSync::NewL |
|
43 // Two Phase Construction |
|
44 // ---------------------------------------------------------------------------- |
|
45 CSync* CSync::NewL(TInt aParam) |
|
46 { |
|
47 |
|
48 CSync* self = new (ELeave) CSync; |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aParam); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // CSync::CSync |
|
57 // Constructor |
|
58 // ---------------------------------------------------------------------------- |
|
59 CSync::CSync() : CActive(CActive::EPriorityHigh) |
|
60 { |
|
61 CActiveScheduler::Add(this); |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CSync::ConstructL |
|
66 // Second phase constructor |
|
67 // ---------------------------------------------------------------------------- |
|
68 void CSync::ConstructL(TInt aParam) |
|
69 { |
|
70 iPrgPrevStatus = TStatus(-1); |
|
71 iPrgCurStatus = TStatus(-1); |
|
72 iState = ERegister; |
|
73 iInterruptStage=aParam; |
|
74 IssueRequest(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CSync::~CSync |
|
79 // Destructor* |
|
80 // ---------------------------------------------------------------------------- |
|
81 CSync::~CSync() |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CSync::RunL |
|
87 // --------------------------------------------------------------------------- |
|
88 void CSync::RunL() |
|
89 { |
|
90 switch ( iState ) |
|
91 { |
|
92 case ERegister: |
|
93 RegisterL(); |
|
94 break; |
|
95 case ESyncOk: |
|
96 StartSyncL(); |
|
97 break; |
|
98 case EInitSync: |
|
99 break; |
|
100 case EComplete: |
|
101 Complete(); |
|
102 break; |
|
103 case ECancel: |
|
104 SyncCancel(); |
|
105 default: |
|
106 break; |
|
107 } |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CSync::RunError |
|
112 // ---------------------------------------------------------------------------- |
|
113 TInt CSync::RunError ( TInt aError ) |
|
114 { |
|
115 return aError; |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // CSync::DoCancel |
|
120 // ---------------------------------------------------------------------------- |
|
121 void CSync::DoCancel() |
|
122 { |
|
123 // Cleanup sync session |
|
124 CloseSyncSession(); |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // CSync::RegisterL |
|
129 // ---------------------------------------------------------------------------- |
|
130 void CSync::RegisterL() |
|
131 { |
|
132 // Wait for events |
|
133 iState = ESyncOk; |
|
134 IssueRequest(); |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CSync::RegisterL |
|
139 // ---------------------------------------------------------------------------- |
|
140 void CSync::StartSyncL() |
|
141 { |
|
142 TBool doSync = EFalse; |
|
143 |
|
144 OpenSyncSessionL(); |
|
145 |
|
146 // Trigger sync here |
|
147 // Register for sync events |
|
148 iSyncSession.RequestEventL(*this); // for MSyncMLEventObserver events |
|
149 iSyncSession.RequestProgressL(*this); // for MSyncMLProgressObserver events |
|
150 |
|
151 iSyncJob.CreateL(iSyncSession, 5); |
|
152 |
|
153 iState = EInitSync; |
|
154 IssueRequest(); |
|
155 |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // CSync::SyncCancel |
|
160 // ---------------------------------------------------------------------------- |
|
161 |
|
162 void CSync::SyncCancel() |
|
163 { |
|
164 iSyncSession.CancelEvent(); |
|
165 iSyncSession.Close(); |
|
166 |
|
167 Cancel(); |
|
168 // Close the server |
|
169 CActiveScheduler::Stop(); |
|
170 } |
|
171 |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // CSync::OpenSyncSessionL |
|
175 // ---------------------------------------------------------------------------- |
|
176 void CSync::OpenSyncSessionL() |
|
177 { |
|
178 TRAPD(err, iSyncSession.OpenL()); |
|
179 |
|
180 if (err != KErrNone) |
|
181 { |
|
182 User::Leave(err); |
|
183 } |
|
184 |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CSync::Complete |
|
189 // ---------------------------------------------------------------------------- |
|
190 void CSync::Complete() |
|
191 { |
|
192 |
|
193 Cancel(); |
|
194 |
|
195 // Close the server |
|
196 CActiveScheduler::Stop(); |
|
197 |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // CSync::CloseSyncSession |
|
202 // ---------------------------------------------------------------------------- |
|
203 void CSync::CloseSyncSession() |
|
204 { |
|
205 iSyncSession.CancelEvent(); |
|
206 iSyncSession.Close(); |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CSync::EventL |
|
211 // ---------------------------------------------------------------------------- |
|
212 void CSync::IssueRequest() |
|
213 { |
|
214 TRequestStatus* status = &iStatus; |
|
215 User::RequestComplete(status, KErrNone); |
|
216 SetActive(); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CSync::OnSyncMLSessionEvent |
|
221 // ---------------------------------------------------------------------------- |
|
222 void CSync::OnSyncMLSessionEvent(TEvent aEvent, |
|
223 TInt /*aIdentifier*/, |
|
224 TInt /*aError*/, |
|
225 TInt /*aAdditionalData*/) |
|
226 { |
|
227 |
|
228 switch ( aEvent ) |
|
229 { |
|
230 case EJobStart: |
|
231 break; |
|
232 case EJobStartFailed: |
|
233 case EJobRejected: |
|
234 case ETransportTimeout: |
|
235 case EServerSuspended: |
|
236 case EServerTerminated: |
|
237 case EJobStop: |
|
238 TInt err(KErrNone); |
|
239 iState = EComplete; |
|
240 IssueRequest(); |
|
241 break; |
|
242 } |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CSync::OnSyncMLSyncError (from MSyncMLProgressObserver) |
|
247 // |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CSync::OnSyncMLSyncError(TErrorLevel aErrorLevel, TInt aError, TInt /*aTaskId*/, TInt /*aInfo1*/, TInt /*aInfo2*/) |
|
251 { |
|
252 //nothing |
|
253 } |
|
254 |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CSync::OnSyncMLSyncProgress (from MSyncMLProgressObserver) |
|
258 // |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CSync::OnSyncMLSyncProgress(TStatus aStatus, TInt aInfo1, TInt /*aInfo2*/) |
|
262 { |
|
263 iPrgPrevStatus = iPrgCurStatus; |
|
264 |
|
265 iPrgCurStatus = aStatus; |
|
266 |
|
267 switch(iInterruptStage) |
|
268 { |
|
269 case 1:if(aStatus==ESmlConnecting) |
|
270 { |
|
271 iProfileEngine = CreateProfileEngineExtendedL(); |
|
272 iProfileEngine->SetActiveProfileL( 5); |
|
273 iProfileEngine->Release(); |
|
274 } |
|
275 break; |
|
276 case 2:if(aStatus==ESmlConnected) |
|
277 { |
|
278 iProfileEngine = CreateProfileEngineExtendedL(); |
|
279 iProfileEngine->SetActiveProfileL( 5); |
|
280 iProfileEngine->Release(); |
|
281 } |
|
282 |
|
283 break; |
|
284 case 3:if(aStatus==ESmlLoggingOn) |
|
285 { |
|
286 iProfileEngine = CreateProfileEngineExtendedL(); |
|
287 iProfileEngine->SetActiveProfileL( 5); |
|
288 iProfileEngine->Release(); |
|
289 } |
|
290 break; |
|
291 case 4:if(aStatus==ESmlLoggedOn) |
|
292 { |
|
293 iProfileEngine = CreateProfileEngineExtendedL(); |
|
294 iProfileEngine->SetActiveProfileL( 5); |
|
295 iProfileEngine->Release(); |
|
296 } |
|
297 break; |
|
298 case 5:if(aStatus==ESmlSendingModificationsToServer) |
|
299 { |
|
300 iProfileEngine = CreateProfileEngineExtendedL(); |
|
301 iProfileEngine->SetActiveProfileL( 5); |
|
302 iProfileEngine->Release(); |
|
303 } |
|
304 break; |
|
305 |
|
306 case 6:if(aStatus==ESmlReceivingModificationsFromServer) |
|
307 { |
|
308 iProfileEngine = CreateProfileEngineExtendedL(); |
|
309 iProfileEngine->SetActiveProfileL( 5); |
|
310 iProfileEngine->Release(); |
|
311 } |
|
312 break; |
|
313 case 7:if(aStatus==ESmlSendingMappingsToServer) |
|
314 { |
|
315 iProfileEngine = CreateProfileEngineExtendedL(); |
|
316 iProfileEngine->SetActiveProfileL( 5); |
|
317 iProfileEngine->Release(); |
|
318 } |
|
319 break; |
|
320 default: |
|
321 break; |
|
322 |
|
323 } |
|
324 |
|
325 |
|
326 } |
|
327 |
|
328 void CSync::OnSyncMLDataSyncModifications(TInt aTaskId, |
|
329 const TSyncMLDataSyncModifications& aClientModifications, |
|
330 const TSyncMLDataSyncModifications& aServerModifications) |
|
331 { |
|
332 //Do Nothing |
|
333 } |
|
334 |
|
335 |
|
336 |