|
1 /* |
|
2 * Copyright (c) 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: Methods for CNSmlDMSyncAppEngine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "NSmlDMSyncAppEngine.h" |
|
20 #include "NSmlDMSyncDebug.h" |
|
21 #include "NSmlDMSyncHandler.h" |
|
22 #include <collate.h> |
|
23 #include <e32property.h> |
|
24 #include "nsmldmsyncinternalpskeys.h" |
|
25 #include "dminforetrieval.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS ============================== |
|
28 // |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine() : iProgressShown( ETrue ) |
|
37 { |
|
38 FLOG( "[OMADM] CNSmlDMSyncAppEngine::CNSmlDMSyncAppEngine:" ); |
|
39 |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CNSmlDMSyncAppEngine::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CNSmlDMSyncAppEngine::ConstructL(DmInfo* dmcallback) |
|
48 { |
|
49 FLOG( "[OMADM] CNSmlDMSyncAppEngine::ConstructL:" ); |
|
50 |
|
51 iSyncMLSession.OpenL(); |
|
52 iDmcallback = dmcallback; |
|
53 iSyncHandler = CNSmlDMSyncHandler::NewL( &iSyncMLSession, |
|
54 this ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CNSmlDMSyncAppEngine::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CNSmlDMSyncAppEngine* CNSmlDMSyncAppEngine::NewL(DmInfo* dmcallback ) |
|
63 { |
|
64 FLOG( "[OMADM] CNSmlDMSyncAppEngine::NewL:" ); |
|
65 |
|
66 CNSmlDMSyncAppEngine* self = new( ELeave ) CNSmlDMSyncAppEngine(); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL( dmcallback ); |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 // ------------------------------------------------------------------------------ |
|
75 // Destructor |
|
76 // ------------------------------------------------------------------------------ |
|
77 // |
|
78 CNSmlDMSyncAppEngine::~CNSmlDMSyncAppEngine() |
|
79 { |
|
80 FLOG( "[OMADM] CNSmlDMSyncAppEngine::~CNSmlDMSyncAppEngine:" ); |
|
81 |
|
82 delete iSyncHandler; |
|
83 delete iProfile; |
|
84 iSyncMLSession.Close(); |
|
85 } |
|
86 |
|
87 // ------------------------------------------------------------------------------ |
|
88 // CNSmlDMSyncAppEngine::DeleteProfileL |
|
89 // ------------------------------------------------------------------------------ |
|
90 // |
|
91 void CNSmlDMSyncAppEngine::DeleteProfileL( TInt aProfileId ) |
|
92 { |
|
93 FLOG( "[OMADM] CNSmlDMSyncAppEngine::DeleteProfileL:" ); |
|
94 |
|
95 delete iProfile; |
|
96 iProfile = NULL; |
|
97 iSyncMLSession.DeleteProfileL( aProfileId ); |
|
98 } |
|
99 |
|
100 // ------------------------------------------------------------------------------ |
|
101 // CNSmlDMSyncAppEngine::CreateProfileL |
|
102 // ------------------------------------------------------------------------------ |
|
103 // |
|
104 TInt CNSmlDMSyncAppEngine::CreateProfileL() |
|
105 { |
|
106 FLOG( "[OMADM] CNSmlDMSyncAppEngine::CreateProfileL:" ); |
|
107 |
|
108 delete iProfile; |
|
109 iProfile = NULL; |
|
110 iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession ); |
|
111 return iProfile->CreateL(); |
|
112 } |
|
113 |
|
114 // ------------------------------------------------------------------------------ |
|
115 // CNSmlDMSyncAppEngine::Profile |
|
116 // ------------------------------------------------------------------------------ |
|
117 // |
|
118 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::Profile( ) |
|
119 { |
|
120 FLOG( "[OMADM] CNSmlDMSyncAppEngine::Profile:" ); |
|
121 |
|
122 return iProfile; |
|
123 } |
|
124 |
|
125 // ------------------------------------------------------------------------------ |
|
126 // CNSmlDMSyncAppEngine::CreateCopyProfileL |
|
127 // ------------------------------------------------------------------------------ |
|
128 // |
|
129 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::CreateCopyProfileL( TInt aProfileId ) |
|
130 { |
|
131 FLOG( "[OMADM] CNSmlDMSyncAppEngine::CreateCopyProfileL:" ); |
|
132 |
|
133 delete iProfile; |
|
134 iProfile = NULL; |
|
135 iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession ); |
|
136 |
|
137 iProfile->CreateCopyL( aProfileId ); |
|
138 return iProfile; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CNSmlDMSyncAppEngine::Session |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 RSyncMLSession* CNSmlDMSyncAppEngine::Session() |
|
146 { |
|
147 FLOG( "[OMADM] CNSmlDMSyncAppEngine::Session:" ); |
|
148 |
|
149 return &iSyncMLSession; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CNSmlDMSyncAppEngine::OpenL |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 CNSmlDMSyncProfile* CNSmlDMSyncAppEngine::OpenProfileL( TInt aProfileId, |
|
157 TInt aOpenMode ) |
|
158 { |
|
159 FLOG( "[OMADM] CNSmlDMSyncAppEngine::OpenL:" ); |
|
160 |
|
161 delete iProfile; |
|
162 iProfile = NULL; |
|
163 iProfile = CNSmlDMSyncProfile::NewL( KUidSmlSyncApp.iUid, &iSyncMLSession ); |
|
164 iProfile->OpenL( aProfileId, aOpenMode ); |
|
165 return iProfile; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CNSmlDMSyncAppEngine::Close |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CNSmlDMSyncAppEngine::CloseProfile() |
|
173 { |
|
174 FLOG( "[OMADM] CNSmlDMSyncAppEngine::Close:" ); |
|
175 |
|
176 delete iProfile; |
|
177 iProfile = NULL; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CNSmlDMSyncAppEngine::SynchronizeL |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CNSmlDMSyncAppEngine::SynchronizeL( TDesC& aServerName, |
|
185 TInt aProfileId, |
|
186 TInt aConnectionBearer, |
|
187 const TBool aUseFotaProgressNote ) |
|
188 { |
|
189 FLOG( "[OMADM] CNSmlDMSyncAppEngine::SynchronizeL:" ); |
|
190 |
|
191 iProgressShown = ETrue; |
|
192 iSyncHandler->SynchronizeL( aServerName, |
|
193 aProfileId, |
|
194 aConnectionBearer, |
|
195 aUseFotaProgressNote ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CNSmlDMSyncAppEngine::SynchronizeL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CNSmlDMSyncAppEngine::SynchronizeL( TDesC& aServerName, |
|
203 TInt aProfileId, |
|
204 TInt aJobId, |
|
205 TInt aConnectionBearer, |
|
206 const TBool aUseFotaProgressNote ) |
|
207 { |
|
208 FLOG( "[OMADM] CNSmlDMSyncAppEngine::SynchronizeL:" ); |
|
209 |
|
210 iProgressShown = ETrue; |
|
211 TInt err = RProperty::Set( KPSUidNSmlDMSyncApp, |
|
212 KDmJobCancel, KErrNone ); |
|
213 FTRACE(FPrint( |
|
214 _L("CNSmlDMSyncAppEngine::SynchronizeL()KDmJobCancel reset to 0 err = %d"), |
|
215 err ) ); |
|
216 iSyncHandler->SynchronizeL( aServerName, |
|
217 aProfileId, |
|
218 aJobId, |
|
219 aConnectionBearer, |
|
220 aUseFotaProgressNote ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CNSmlDMSyncAppEngine::ShowProgressDialogL |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 void CNSmlDMSyncAppEngine::ShowProgressDialogL( TBool aShow ) |
|
228 { |
|
229 FLOG( "[OMADM] CNSmlDMSyncAppEngine::ShowProgressDialog()" ); |
|
230 |
|
231 if ( aShow != iProgressShown ) |
|
232 { |
|
233 if ( aShow ) |
|
234 { |
|
235 iSyncHandler->ShowProgressDialogL(); |
|
236 } |
|
237 else |
|
238 { |
|
239 iSyncHandler->HideProgressDialogL(); |
|
240 } |
|
241 iProgressShown = aShow; |
|
242 } |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CNSmlDMSyncAppEngine::ServerIdFoundL |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TBool CNSmlDMSyncAppEngine::ServerIdFoundL( const TDesC& aServerId, |
|
250 const TInt aProfileId ) |
|
251 { |
|
252 FLOG( "[OMADM] CNSmlDMSyncAppEngine::ServerIdFoundL:" ); |
|
253 |
|
254 RArray<TSmlProfileId> arr; |
|
255 iSyncMLSession.ListProfilesL( arr, ESmlDevMan ); |
|
256 TBool ret = EFalse; |
|
257 CleanupClosePushL(arr); |
|
258 |
|
259 for ( TInt index = 0; index < arr.Count(); index++ ) |
|
260 { |
|
261 TRAPD( error, OpenProfileL( arr[index], ESmlOpenRead ) ); |
|
262 if ( error == KErrNone ) |
|
263 { |
|
264 if ( aProfileId != Profile()->ProfileId() ) |
|
265 { |
|
266 TBuf<KNSmlMaxItemLength> buf; |
|
267 Profile()->GetServerId( buf ); |
|
268 if ( buf.Compare( aServerId ) == 0 ) |
|
269 { |
|
270 FLOG( "[OMADM] CNSmlDMSyncAppEngine::ServerIdFoundL: Match" ); |
|
271 ret = ETrue; |
|
272 CloseProfile(); |
|
273 break; |
|
274 } |
|
275 } |
|
276 CloseProfile(); |
|
277 } |
|
278 } |
|
279 CleanupStack::PopAndDestroy( &arr ); |
|
280 return ret; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CNSmlDMSyncAppEngine::Compare |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 TInt CNSmlDMSyncAppEngine::Compare( const TDesC& aLeft, const TDesC& aRight ) |
|
288 { |
|
289 FLOG( "[OMADM] CNSmlDMSyncAppEngine::Compare:" ); |
|
290 |
|
291 // Empty Name() is always greater than non-empty Name() |
|
292 if (aLeft.Length() == 0 && aRight.Length() == 0) |
|
293 { |
|
294 return 0; |
|
295 } |
|
296 if (aLeft.Length() == 0) |
|
297 { |
|
298 return 1; |
|
299 } |
|
300 if (aRight.Length() == 0) |
|
301 { |
|
302 return -1; |
|
303 } |
|
304 |
|
305 // None of the Name()s was empty, use TDesC::CompareC to do the comparison. |
|
306 // This is from cntmodel. |
|
307 TCollationMethod collateMethod; |
|
308 // get the standard method |
|
309 collateMethod = *Mem::CollationMethodByIndex(0); |
|
310 // dont ignore punctuation and spaces |
|
311 collateMethod.iFlags |= TCollationMethod::EIgnoreNone; |
|
312 TInt comparison( aLeft.CompareC(aRight, 3, &collateMethod) ); |
|
313 return comparison; |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CNSmlDMSyncAppEngine::SyncRunning |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 TBool CNSmlDMSyncAppEngine::SyncRunning() |
|
321 { |
|
322 FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncRunning:" ); |
|
323 |
|
324 return iSyncHandler->SyncRunning(); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CNSmlDMSyncAppEngine::CancelSyncL |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CNSmlDMSyncAppEngine::CancelSyncL() |
|
332 { |
|
333 FLOG( "[OMADM] CNSmlDMSyncAppEngine::CancelSyncL()" ); |
|
334 iSyncHandler->CancelSynchronizeL(); |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CNSmlDMSyncAppEngine::SyncCompleted |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CNSmlDMSyncAppEngine::SyncCompleted( TNSmlStatus aStatus ) |
|
342 { |
|
343 FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncCompleted:" ); |
|
344 iDmcallback->synccomplete(aStatus); |
|
345 if( iSyncObserver ) |
|
346 { |
|
347 FLOG( "[OMADM] CNSmlDMSyncAppEngine::SyncCompleted: inform observer" ); |
|
348 iSyncObserver->SyncComplete( aStatus ); |
|
349 } |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CNSmlDMSyncAppEngine::RequestSyncStatus |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 void CNSmlDMSyncAppEngine::RequestSyncStatus( |
|
357 MNSmlDMSyncObserver* aSyncObserver ) |
|
358 { |
|
359 FLOG( "[OMADM] CNSmlDMSyncAppEngine::RequestSyncStatus:" ); |
|
360 if( aSyncObserver ) |
|
361 { |
|
362 FLOG( "[OMADM] CNSmlDMSyncAppEngine::RequestSyncStatus: added observer" ); |
|
363 iSyncObserver = aSyncObserver; |
|
364 } |
|
365 } |
|
366 |
|
367 // End of File |