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