|
1 /* |
|
2 * Copyright (c) 2002-2007 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: A notifier that gets refresh events from the SAT server |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CSatRefreshNotifier.h" |
|
22 |
|
23 #include <RSatSession.h> |
|
24 #include <RSatRefresh.h> |
|
25 #include <VPbkDebug.h> |
|
26 #include "MSimRefreshObject.h" |
|
27 |
|
28 namespace VPbkSimStoreImpl { |
|
29 |
|
30 |
|
31 // ============================= LOCAL FUNCTIONS =============================== |
|
32 |
|
33 namespace { |
|
34 // ----------------------------------------------------------------------------- |
|
35 // ConvertFromSatFormat() Converts from SAT server format to own format |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 TUint32 ConvertFromSatFormat( |
|
39 const TSatRefreshFiles& aFiles ) // List of files which has been refreshed |
|
40 { |
|
41 FUNC_ENTRY(); |
|
42 TUint32 result = 0; |
|
43 |
|
44 // KAdnEf -> KADNRefresh |
|
45 TChar ef( KAdnEf ); |
|
46 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
47 { |
|
48 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
49 "VPbkSimStoreImpl: ConvertFromSatFormat 1")); |
|
50 result |= KADNRefresh; |
|
51 } |
|
52 |
|
53 // KExt1Ef -> KADNExtRefresh |
|
54 ef = KExt1Ef; |
|
55 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
56 { |
|
57 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
58 "VPbkSimStoreImpl: ConvertFromSatFormat 2")); |
|
59 result |= KADNExtRefresh; |
|
60 } |
|
61 |
|
62 // KFdnEf -> KFDNRefresh |
|
63 ef = KFdnEf; |
|
64 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
65 { |
|
66 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
67 "VPbkSimStoreImpl: ConvertFromSatFormat 3")); |
|
68 result |= KFDNRefresh; |
|
69 } |
|
70 |
|
71 // KExt2Ef -> KFDNExtRefresh |
|
72 ef = KExt2Ef; |
|
73 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
74 { |
|
75 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
76 "VPbkSimStoreImpl: ConvertFromSatFormat 4")); |
|
77 result |= KFDNExtRefresh; |
|
78 } |
|
79 |
|
80 // KSdnEf -> KSDNRefresh |
|
81 ef = KSdnEf; |
|
82 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
83 { |
|
84 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
85 "VPbkSimStoreImpl: ConvertFromSatFormat 5")); |
|
86 result |= KSDNRefresh; |
|
87 } |
|
88 |
|
89 // KExt3Ef -> KSDNExtRefresh |
|
90 ef = KExt3Ef; |
|
91 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
92 { |
|
93 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
94 "VPbkSimStoreImpl: ConvertFromSatFormat 6")); |
|
95 result |= KSDNExtRefresh; |
|
96 } |
|
97 |
|
98 // KSstEf -> KSTRefresh |
|
99 ef = KSstEf; |
|
100 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
101 { |
|
102 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
103 "VPbkSimStoreImpl: ConvertFromSatFormat 7")); |
|
104 result |= KSTRefresh; |
|
105 } |
|
106 |
|
107 // KMsisdnEf -> KONRefresh |
|
108 ef = KMsisdnEf; |
|
109 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
110 { |
|
111 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
112 "VPbkSimStoreImpl: ConvertFromSatFormat 8")); |
|
113 result |= KONRefresh; |
|
114 } |
|
115 |
|
116 // KExt5Ef -> KONExtRefresh |
|
117 ef = KExt5Ef; |
|
118 if ( aFiles.Locate( ef ) != KErrNotFound ) |
|
119 { |
|
120 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
121 "VPbkSimStoreImpl: ConvertFromSatFormat 9")); |
|
122 result |= KONExtRefresh; |
|
123 } |
|
124 |
|
125 // Check all 0x4FXX files |
|
126 const TInt count( aFiles.Length() ); |
|
127 for( TInt i(0); i < count; ++i ) |
|
128 { |
|
129 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
130 "VPbkSimStoreImpl: ConvertFromSatFormat 10")); |
|
131 if ( !(0x4F ^ aFiles[i] >> 8 ) ) |
|
132 { |
|
133 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
134 "VPbkSimStoreImpl: ConvertFromSatFormat 11")); |
|
135 // USIM ADN file updated |
|
136 result |= KADNRefresh; |
|
137 result |= KADNExtRefresh; |
|
138 } |
|
139 } |
|
140 FUNC_EXIT(); |
|
141 return result; |
|
142 } |
|
143 |
|
144 TUint32 ConvertFromSatFormat( |
|
145 const TSatRefreshType& aType ) // List of files which has been refreshed |
|
146 { |
|
147 FUNC_ENTRY(); |
|
148 TUint result(0); |
|
149 |
|
150 if( aType == ESimReset ) |
|
151 { |
|
152 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
153 "VPbkSimStoreImpl: ConvertFromSatFormat ESimReset")); |
|
154 result |= KSimReset; |
|
155 } |
|
156 |
|
157 if( aType == ESimInitFullFileChangeNotification ) |
|
158 { |
|
159 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
160 "VPbkSimStoreImpl: ConvertFromSatFormat ESimInitFullFileChangeNotification")); |
|
161 result |= KSimInitFullFileChangeNotification; |
|
162 } |
|
163 |
|
164 if( aType == EUsimApplicationReset ) |
|
165 { |
|
166 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
167 "VPbkSimStoreImpl: ConvertFromSatFormat EUsimApplicationReset")); |
|
168 result |= KUsimApplicationReset; |
|
169 } |
|
170 |
|
171 if( aType == E3GSessionReset ) |
|
172 { |
|
173 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
174 "VPbkSimStoreImpl: ConvertFromSatFormat E3GSessionReset")); |
|
175 result |= K3GSessionReset; |
|
176 } |
|
177 |
|
178 if( aType == ESimInit ) |
|
179 { |
|
180 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
181 "VPbkSimStoreImpl: ConvertFromSatFormat ESimInit")); |
|
182 result |= KSimInit; |
|
183 } |
|
184 |
|
185 FUNC_EXIT(); |
|
186 return result; |
|
187 } |
|
188 |
|
189 |
|
190 } // unnamed namespace |
|
191 |
|
192 // ============================ MEMBER FUNCTIONS =============================== |
|
193 |
|
194 NONSHARABLE_CLASS(CSatRefreshNotifier::CSatSession) : public CBase |
|
195 { |
|
196 public: // Constructors and destructor |
|
197 CSatSession( MSatRefreshObserver& aSatObserver ); |
|
198 ~CSatSession(); |
|
199 |
|
200 public: // New functions |
|
201 /** |
|
202 * Opens SAT session |
|
203 */ |
|
204 void OpenL(); |
|
205 |
|
206 /** |
|
207 * Returns ETrue if session has been opened |
|
208 */ |
|
209 TBool IsOpen(); |
|
210 |
|
211 /** |
|
212 * @return the refresh subsession |
|
213 */ |
|
214 RSatRefresh& Refresh(); |
|
215 |
|
216 private: // Data |
|
217 /// The main session to SAT server |
|
218 RSatSession iSatSession; |
|
219 /// The subsession that implements SAT refresh notifying |
|
220 RSatRefresh iSatRefresh; |
|
221 TBool iIsOpen; |
|
222 }; |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CSatRefreshNotifier::CSatSession::CSatSession |
|
226 // C++ default constructor can NOT contain any code, that |
|
227 // might leave. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 CSatRefreshNotifier::CSatSession::CSatSession( MSatRefreshObserver& aSatObserver ) |
|
231 : iSatRefresh( aSatObserver ) |
|
232 { |
|
233 } |
|
234 |
|
235 // Destructor |
|
236 CSatRefreshNotifier::CSatSession::~CSatSession() |
|
237 { |
|
238 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
239 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::~CSatSession,\ |
|
240 Cancel refresh h%d"), |
|
241 iSatRefresh.SubSessionHandle() ); |
|
242 iSatRefresh.Cancel(); |
|
243 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
244 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::~CSatSession,\ |
|
245 Close refresh h%d"), |
|
246 iSatRefresh.SubSessionHandle() ); |
|
247 iSatRefresh.Close(); |
|
248 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
249 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::~CSatSession,\ |
|
250 Close session h%d"), |
|
251 iSatSession.Handle() ); |
|
252 iSatSession.Close(); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CSatRefreshNotifier::CSatSession::OpenL |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CSatRefreshNotifier::CSatSession::OpenL() |
|
260 { |
|
261 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
262 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::OpenL")); |
|
263 iSatSession.ConnectL(); |
|
264 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
265 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::OpenL, Session Connected h%d"), |
|
266 iSatSession.Handle() ); |
|
267 iSatRefresh.OpenL( iSatSession ); |
|
268 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
269 "VPbkSimStoreImpl:CSatRefreshNotifier::CSatSession::OpenL, Refresh Opened h%d"), |
|
270 iSatRefresh.SubSessionHandle() ); |
|
271 iIsOpen = ETrue; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CSatRefreshNotifier::CSatSession::IsOpen |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 TBool CSatRefreshNotifier::CSatSession::IsOpen() |
|
279 { |
|
280 return iIsOpen; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CSatRefreshNotifier::CSatSession::Refresh |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 RSatRefresh& CSatRefreshNotifier::CSatSession::Refresh() |
|
288 { |
|
289 return iSatRefresh; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CSatRefreshNotifier::CSatRefreshNotifier |
|
294 // C++ default constructor can NOT contain any code, that |
|
295 // might leave. |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 CSatRefreshNotifier::CSatRefreshNotifier() |
|
299 { |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CSatRefreshNotifier::ConstructL |
|
304 // Symbian 2nd phase constructor can leave. |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CSatRefreshNotifier::ConstructL() |
|
308 { |
|
309 iSatSession = new( ELeave ) CSatSession( *this ); |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CSatRefreshNotifier::NewL |
|
314 // Two-phased constructor. |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 CSatRefreshNotifier* CSatRefreshNotifier::NewL() |
|
318 { |
|
319 CSatRefreshNotifier* self = new( ELeave ) CSatRefreshNotifier; |
|
320 CleanupStack::PushL( self ); |
|
321 self->ConstructL(); |
|
322 CleanupStack::Pop( self ); |
|
323 return self; |
|
324 } |
|
325 |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CSatRefreshNotifier::~CSatRefreshNotifier |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 CSatRefreshNotifier::~CSatRefreshNotifier() |
|
332 { |
|
333 delete iSatSession; |
|
334 iObjects.Close(); |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CSatRefreshNotifier::IsActive |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 TBool CSatRefreshNotifier::IsActive() |
|
342 { |
|
343 return iSatSession->IsOpen(); |
|
344 } |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CSatRefreshNotifier::ActivateL |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 void CSatRefreshNotifier::ActivateL( MSimRefreshObject& aSimRefreshObject ) |
|
351 { |
|
352 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
353 "VPbkSimStoreImpl:CSatRefreshNotifier::ActivateL")); |
|
354 |
|
355 // Open the session to SAT server if not opened |
|
356 if ( !iSatSession->IsOpen() ) |
|
357 { |
|
358 iSatSession->OpenL(); |
|
359 } |
|
360 |
|
361 // Listen to all changes |
|
362 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
363 "VPbkSimStoreImpl:CSatRefreshNotifier::ActivateL: NotifyFileChangeL ALL")); |
|
364 iSatSession->Refresh().NotifyFileChangeL(); |
|
365 |
|
366 if ( iObjects.Find( &aSimRefreshObject ) == KErrNotFound ) |
|
367 { |
|
368 iObjects.AppendL( &aSimRefreshObject ); |
|
369 } |
|
370 } |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CSatRefreshNotifier::DeActivate |
|
374 // ----------------------------------------------------------------------------- |
|
375 // |
|
376 void CSatRefreshNotifier::DeActivate( MSimRefreshObject& aSimRefreshObject ) |
|
377 { |
|
378 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
379 "VPbkSimStoreImpl:CSatRefreshNotifier::DeActivate")); |
|
380 |
|
381 TInt index = iObjects.Find( &aSimRefreshObject ); |
|
382 if ( index != KErrNotFound ) |
|
383 { |
|
384 iObjects.Remove( index ); |
|
385 } |
|
386 |
|
387 // Cancel the request if session is open and this was the last object |
|
388 if ( iSatSession->IsOpen() && iObjects.Count() == 0 ) |
|
389 { |
|
390 iSatSession->Refresh().Cancel(); |
|
391 } |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CSatRefreshNotifier::AllowRefresh |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 TBool CSatRefreshNotifier::AllowRefresh( TSatRefreshType aType, |
|
399 const TSatRefreshFiles& aFiles ) |
|
400 { |
|
401 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
402 "VPbkSimStoreImpl:CSatRefreshNotifier::AllowRefresh:type=%d, aFiles=%S"), |
|
403 aType,&aFiles); |
|
404 // First check files... |
|
405 TUint32 flags = ConvertFromSatFormat( aFiles ); |
|
406 // ...and then refresh types |
|
407 flags |= ConvertFromSatFormat( aType ); |
|
408 |
|
409 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
410 "VPbkSimStoreImpl:CSatRefreshNotifier::AllowRefresh:Converted flags=%x"), |
|
411 flags); |
|
412 |
|
413 TBool result = ETrue; |
|
414 const TInt count = iObjects.Count(); |
|
415 for( TInt i = count - 1; i >= 0 && result; --i ) |
|
416 { |
|
417 if ( !iObjects[i]->AllowRefresh( flags ) ) |
|
418 { |
|
419 result = EFalse; |
|
420 } |
|
421 } |
|
422 |
|
423 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
424 "VPbkSimStoreImpl:CSatRefreshNotifier::AllowRefresh:return %d"), |
|
425 result); |
|
426 // The refresh doesn't necessary start |
|
427 // because other clients or TSY can deny the refresh. |
|
428 return result; |
|
429 } |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // CSatRefreshNotifier::Refresh |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 void CSatRefreshNotifier::Refresh( TSatRefreshType aType, |
|
436 const TSatRefreshFiles& aFiles ) |
|
437 { |
|
438 FUNC_ENTRY(); |
|
439 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
440 "VPbkSimStoreImpl:CSatRefreshNotifier::Refresh:type=%d, aFiles=%S"), |
|
441 aType,&aFiles); |
|
442 |
|
443 // Refresh has happened. Clients must update their content |
|
444 iRefreshedObjects = 0; |
|
445 iAdditionalEFsRead = EFalse; |
|
446 // First check files... |
|
447 TUint32 flags = ConvertFromSatFormat( aFiles ); |
|
448 // ...and then refresh types |
|
449 flags |= ConvertFromSatFormat( aType ); |
|
450 |
|
451 const TInt count = iObjects.Count(); |
|
452 for( TInt i = count - 1; i >= 0; --i ) |
|
453 { |
|
454 iObjects[i]->SimRefreshed( flags, *this ); |
|
455 } |
|
456 FUNC_EXIT(); |
|
457 } |
|
458 |
|
459 // ----------------------------------------------------------------------------- |
|
460 // CSatRefreshNotifier::SatRefreshCompleted |
|
461 // ----------------------------------------------------------------------------- |
|
462 // |
|
463 void CSatRefreshNotifier::SatRefreshCompleted( |
|
464 MSimRefreshObject& /*aSimRefreshObject*/, |
|
465 TBool aReadAdditionalFiles ) |
|
466 { |
|
467 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
468 "VPbkSimStoreImpl:CSatRefreshNotifier::SatRefreshCompleted:total=%d,cur=%d"), |
|
469 iObjects.Count(), iRefreshedObjects + 1); |
|
470 |
|
471 ++iRefreshedObjects; |
|
472 if ( aReadAdditionalFiles ) |
|
473 { |
|
474 iAdditionalEFsRead = ETrue; |
|
475 } |
|
476 |
|
477 // Complete refresh to SAT server when all the objects have completed |
|
478 if ( iRefreshedObjects == iObjects.Count() ) |
|
479 { |
|
480 iSatSession->Refresh().RefreshEFRead( iAdditionalEFsRead ); |
|
481 } |
|
482 } |
|
483 } // namespace VPbkSimStoreImpl |
|
484 // End of File |