63
|
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 remote sim store implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "CRemoteStore.h"
|
|
22 |
|
|
23 |
// From Virtual Phonebook
|
|
24 |
#include "VPbkSimStoreError.h"
|
|
25 |
#include "CRemoteView.h"
|
|
26 |
|
|
27 |
#include <MVPbkSimStoreObserver.h>
|
|
28 |
#include <MVPbkSimContactObserver.h>
|
|
29 |
#include <MVPbkSimFindObserver.h>
|
|
30 |
#include <VPbkSimServerOpCodes.h>
|
|
31 |
#include <VPbkSimStoreTemplateFunctions.h>
|
|
32 |
#include <CVPbkSimContactBuf.h>
|
|
33 |
#include <MVPbkSimPhoneObserver.h>
|
|
34 |
#include <CVPbkETelCntConverter.h>
|
|
35 |
#include <CVPbkSimFieldTypeFilter.h>
|
|
36 |
#include <MVPbkSimStoreOperation.h>
|
|
37 |
#include <MVPbkSimCntView.h>
|
|
38 |
#include <VPbkSimStoreCommonUtil.h>
|
|
39 |
#include <CVPbkAsyncOperation.h>
|
|
40 |
#include <CVPbkAsyncCallback.h>
|
|
41 |
|
|
42 |
#include <VPbkDebug.h>
|
|
43 |
|
|
44 |
// System includes
|
|
45 |
#include <s32mem.h>
|
|
46 |
|
|
47 |
namespace VPbkSimStore {
|
|
48 |
|
|
49 |
// CONSTANTS
|
|
50 |
// The initial buffer size for number match results, 10 indexes
|
|
51 |
const TInt KInitSimIndexBufSize = 10 * sizeof(TInt);
|
|
52 |
// The maximum buffer size for number match results if server behaves badly
|
|
53 |
const TInt KMaxSimIndexBufSize = 100 * KInitSimIndexBufSize;
|
|
54 |
|
|
55 |
// ============================= LOCAL FUNCTIONS ============================
|
|
56 |
|
|
57 |
// --------------------------------------------------------------------------
|
|
58 |
// SendStoreEventMessage
|
|
59 |
// --------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
template<class Function, class Param>
|
|
62 |
inline void SendStoreEventMessage(
|
|
63 |
RPointerArray<MVPbkSimStoreObserver>& aObservers, Function aFunction,
|
|
64 |
Param& aParam )
|
|
65 |
{
|
|
66 |
const TInt count = aObservers.Count();
|
|
67 |
for ( TInt i = count - 1; i >= 0; --i )
|
|
68 |
{
|
|
69 |
( aObservers[i]->*aFunction )( aParam );
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
// --------------------------------------------------------------------------
|
|
74 |
// SendStoreErrorMessage
|
|
75 |
// --------------------------------------------------------------------------
|
|
76 |
//
|
|
77 |
inline void SendStoreErrorMessage(
|
|
78 |
RPointerArray<MVPbkSimStoreObserver>& aObservers, MVPbkSimCntStore& aStore,
|
|
79 |
TInt aError )
|
|
80 |
{
|
|
81 |
const TInt count = aObservers.Count();
|
|
82 |
for ( TInt i = count - 1; i >= 0; --i )
|
|
83 |
{
|
|
84 |
aObservers[i]->StoreError( aStore, aError );
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
// --------------------------------------------------------------------------
|
|
89 |
// SendStoreEventMessage
|
|
90 |
// --------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
inline void SendStoreEventMessage(
|
|
93 |
RPointerArray<MVPbkSimStoreObserver>& aObservers,
|
|
94 |
void (MVPbkSimStoreObserver::*aEvent)(MVPbkSimStoreObserver::TEvent, TInt),
|
|
95 |
MVPbkSimStoreObserver::TEvent aEventType,
|
|
96 |
TInt aParam1)
|
|
97 |
{
|
|
98 |
for (TInt i = aObservers.Count() - 1; i >= 0; --i)
|
|
99 |
{
|
|
100 |
(aObservers[i]->*aEvent)( aEventType, aParam1 );
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
// ============================ MEMBER FUNCTIONS ============================
|
|
105 |
|
|
106 |
// --------------------------------------------------------------------------
|
|
107 |
// CAsyncSave::CAsyncSave
|
|
108 |
// C++ default constructor can NOT contain any code, that
|
|
109 |
// might leave.
|
|
110 |
// --------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
CAsyncSave::CAsyncSave( RVPbkSimStore& aStore )
|
|
113 |
: CActive( EPriorityStandard ),
|
|
114 |
iStore( aStore )
|
|
115 |
{
|
|
116 |
CActiveScheduler::Add( this );
|
|
117 |
}
|
|
118 |
|
|
119 |
// Destructor
|
|
120 |
CAsyncSave::~CAsyncSave()
|
|
121 |
{
|
|
122 |
Cancel();
|
|
123 |
}
|
|
124 |
|
|
125 |
// --------------------------------------------------------------------------
|
|
126 |
// CAsyncSave::DoRequestL
|
|
127 |
// --------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
void CAsyncSave::DoRequestL( const TDesC8& aData,
|
|
130 |
TInt& aSimIndex, MVPbkSimContactObserver& aObserver )
|
|
131 |
{
|
|
132 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
|
|
133 |
"CAsyncSave::DoRequestL: aSimIndex %d"),
|
|
134 |
aSimIndex );
|
|
135 |
|
|
136 |
iObserver = &aObserver;
|
|
137 |
iStore.SaveL( iStatus, aData, aSimIndex );
|
|
138 |
SetActive();
|
|
139 |
}
|
|
140 |
|
|
141 |
// --------------------------------------------------------------------------
|
|
142 |
// CAsyncSave::RunL
|
|
143 |
// --------------------------------------------------------------------------
|
|
144 |
//
|
|
145 |
void CAsyncSave::RunL()
|
|
146 |
{
|
|
147 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
|
|
148 |
"CAsyncSave::RunL: iStatus %d"),
|
|
149 |
iStatus.Int() );
|
|
150 |
|
|
151 |
TInt result = iStatus.Int();
|
|
152 |
if ( result == KErrNone )
|
|
153 |
{
|
|
154 |
iObserver->ContactEventComplete( MVPbkSimContactObserver::ESave, NULL );
|
|
155 |
}
|
|
156 |
else
|
|
157 |
{
|
|
158 |
iObserver->ContactEventError( MVPbkSimContactObserver::ESave, NULL,
|
|
159 |
result );
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
// --------------------------------------------------------------------------
|
|
164 |
// CAsyncSave::DoCancel
|
|
165 |
// --------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
void CAsyncSave::DoCancel()
|
|
168 |
{
|
|
169 |
iStore.CancelAsyncRequest( EVPbkSimSrvSaveContact );
|
|
170 |
}
|
|
171 |
|
|
172 |
// --------------------------------------------------------------------------
|
|
173 |
// CAsyncDelete::CAsyncDelete
|
|
174 |
// C++ default constructor can NOT contain any code, that
|
|
175 |
// might leave.
|
|
176 |
// --------------------------------------------------------------------------
|
|
177 |
//
|
|
178 |
CAsyncDelete::CAsyncDelete( RVPbkSimStore& aStore )
|
|
179 |
: CActive( EPriorityStandard ),
|
|
180 |
iStore( aStore )
|
|
181 |
{
|
|
182 |
CActiveScheduler::Add( this );
|
|
183 |
}
|
|
184 |
|
|
185 |
// Destructor
|
|
186 |
CAsyncDelete::~CAsyncDelete()
|
|
187 |
{
|
|
188 |
Cancel();
|
|
189 |
}
|
|
190 |
|
|
191 |
// --------------------------------------------------------------------------
|
|
192 |
// CAsyncDelete::DoRequestL
|
|
193 |
// --------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CAsyncDelete::DoRequestL(
|
|
196 |
RVPbkStreamedIntArray& aSimIndexes,
|
|
197 |
MVPbkSimContactObserver& aObserver )
|
|
198 |
{
|
|
199 |
iObserver = &aObserver;
|
|
200 |
iStore.DeleteL( iStatus, aSimIndexes );
|
|
201 |
SetActive();
|
|
202 |
}
|
|
203 |
|
|
204 |
// --------------------------------------------------------------------------
|
|
205 |
// CAsyncDelete::RunL
|
|
206 |
// --------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
void CAsyncDelete::RunL()
|
|
209 |
{
|
|
210 |
TInt result = iStatus.Int();
|
|
211 |
if ( result == KErrNone )
|
|
212 |
{
|
|
213 |
iObserver->ContactEventComplete( MVPbkSimContactObserver::EDelete,
|
|
214 |
NULL );
|
|
215 |
}
|
|
216 |
else
|
|
217 |
{
|
|
218 |
iObserver->ContactEventError( MVPbkSimContactObserver::EDelete,
|
|
219 |
NULL, result );
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
// --------------------------------------------------------------------------
|
|
224 |
// CAsyncDelete::DoCancel
|
|
225 |
// --------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
void CAsyncDelete::DoCancel()
|
|
228 |
{
|
|
229 |
iStore.CancelAsyncRequest( EVPbkSimSrvDeleteContact );
|
|
230 |
}
|
|
231 |
|
|
232 |
// --------------------------------------------------------------------------
|
|
233 |
// CRemoteStore::CNumberMatchOperation::CNumberMatchOperation
|
|
234 |
// C++ default constructor can NOT contain any code, that
|
|
235 |
// might leave.
|
|
236 |
// --------------------------------------------------------------------------
|
|
237 |
//
|
|
238 |
CRemoteStore::CNumberMatchOperation::CNumberMatchOperation(
|
|
239 |
CRemoteStore& aStore, const TDesC& aPhoneNumber,
|
|
240 |
TInt aMaxMatchDigits, MVPbkSimFindObserver& aObserver )
|
|
241 |
: CActive( EPriorityStandard ),
|
|
242 |
iStore( aStore ),
|
|
243 |
iPhoneNumber( aPhoneNumber ),
|
|
244 |
iMaxMatchDigits( aMaxMatchDigits ),
|
|
245 |
iObserver( aObserver ),
|
|
246 |
iSimIndexBufPtr( NULL, 0 )
|
|
247 |
{
|
|
248 |
}
|
|
249 |
|
|
250 |
// --------------------------------------------------------------------------
|
|
251 |
// CRemoteStore::CNumberMatchOperation::ConstructL
|
|
252 |
// Symbian 2nd phase constructor can leave.
|
|
253 |
// --------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
void CRemoteStore::CNumberMatchOperation::ConstructL()
|
|
256 |
{
|
|
257 |
CActiveScheduler::Add( this );
|
|
258 |
iSimIndexBuf = HBufC8::NewL( KInitSimIndexBufSize );
|
|
259 |
iSimIndexBufPtr.Set( iSimIndexBuf->Des() );
|
|
260 |
}
|
|
261 |
|
|
262 |
// --------------------------------------------------------------------------
|
|
263 |
// CRemoteStore::CNumberMatchOperation::NewL
|
|
264 |
// Two-phased constructor.
|
|
265 |
// --------------------------------------------------------------------------
|
|
266 |
//
|
|
267 |
CRemoteStore::CNumberMatchOperation* CRemoteStore::CNumberMatchOperation::NewL(
|
|
268 |
CRemoteStore& aStore, const TDesC& aPhoneNumber,
|
|
269 |
TInt aMaxMatchDigits, MVPbkSimFindObserver& aObserver )
|
|
270 |
{
|
|
271 |
CNumberMatchOperation* self = new( ELeave ) CNumberMatchOperation( aStore,
|
|
272 |
aPhoneNumber, aMaxMatchDigits, aObserver );
|
|
273 |
CleanupStack::PushL( self );
|
|
274 |
self->ConstructL();
|
|
275 |
CleanupStack::Pop( self );
|
|
276 |
return self;
|
|
277 |
}
|
|
278 |
|
|
279 |
// Destructor
|
|
280 |
CRemoteStore::CNumberMatchOperation::~CNumberMatchOperation()
|
|
281 |
{
|
|
282 |
Cancel();
|
|
283 |
delete iSimIndexBuf;
|
|
284 |
}
|
|
285 |
|
|
286 |
// --------------------------------------------------------------------------
|
|
287 |
// CRemoteStore::CNumberMatchOperation::Activate
|
|
288 |
// --------------------------------------------------------------------------
|
|
289 |
//
|
|
290 |
void CRemoteStore::CNumberMatchOperation::Activate()
|
|
291 |
{
|
|
292 |
iStore.StoreSession().MatchPhoneNumber( iStatus, iPhoneNumber,
|
|
293 |
iMaxMatchDigits, iSimIndexBufPtr );
|
|
294 |
SetActive();
|
|
295 |
}
|
|
296 |
|
|
297 |
// --------------------------------------------------------------------------
|
|
298 |
// CRemoteStore::CNumberMatchOperation::RunL
|
|
299 |
// --------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
void CRemoteStore::CNumberMatchOperation::RunL()
|
|
302 |
{
|
|
303 |
RVPbkStreamedIntArray matchedIndexes;
|
|
304 |
CleanupClosePushL( matchedIndexes );
|
|
305 |
|
|
306 |
TInt result = iStatus.Int();
|
|
307 |
switch ( result )
|
|
308 |
{
|
|
309 |
case KErrNone:
|
|
310 |
{
|
|
311 |
RDesReadStream stream( iSimIndexBufPtr );
|
|
312 |
CleanupClosePushL( stream );
|
|
313 |
stream >> matchedIndexes;
|
|
314 |
CleanupStack::PopAndDestroy(); // stream
|
|
315 |
iObserver.FindCompleted( iStore, matchedIndexes );
|
|
316 |
break;
|
|
317 |
}
|
|
318 |
case KErrNotFound:
|
|
319 |
{
|
|
320 |
iObserver.FindCompleted( iStore, matchedIndexes );
|
|
321 |
break;
|
|
322 |
}
|
|
323 |
case KErrOverflow:
|
|
324 |
{
|
|
325 |
TInt newLength = 2 * iSimIndexBufPtr.MaxLength();
|
|
326 |
if ( newLength > KMaxSimIndexBufSize )
|
|
327 |
{
|
|
328 |
iObserver.FindError( iStore, result );
|
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
VPbkSimStoreImpl::CheckAndUpdateBufferSizeL( iSimIndexBuf,
|
|
333 |
iSimIndexBufPtr, newLength );
|
|
334 |
Activate();
|
|
335 |
}
|
|
336 |
break;
|
|
337 |
}
|
|
338 |
default:
|
|
339 |
{
|
|
340 |
iObserver.FindError( iStore, result );
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
}
|
|
344 |
CleanupStack::PopAndDestroy(); // matchedIndexes
|
|
345 |
}
|
|
346 |
|
|
347 |
// --------------------------------------------------------------------------
|
|
348 |
// CRemoteStore::CNumberMatchOperation::DoCancel
|
|
349 |
// --------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CRemoteStore::CNumberMatchOperation::DoCancel()
|
|
352 |
{
|
|
353 |
iStore.StoreSession().CancelAsyncRequest( EVPbkSimSrvMatchPhoneNumber );
|
|
354 |
}
|
|
355 |
|
|
356 |
// --------------------------------------------------------------------------
|
|
357 |
// CRemoteStore::CNumberMatchOperation::RunError
|
|
358 |
// --------------------------------------------------------------------------
|
|
359 |
//
|
|
360 |
TInt CRemoteStore::CNumberMatchOperation::RunError( TInt aError )
|
|
361 |
{
|
|
362 |
iObserver.FindError( iStore, aError );
|
|
363 |
return KErrNone;
|
|
364 |
}
|
|
365 |
|
|
366 |
// --------------------------------------------------------------------------
|
|
367 |
// CRemoteStore::CFindOperation::CFindOperation
|
|
368 |
// C++ default constructor can NOT contain any code, that
|
|
369 |
// might leave.
|
|
370 |
// --------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
CRemoteStore::CFindOperation::CFindOperation( CRemoteStore& aStore,
|
|
373 |
const TDesC& aStringToFind, MVPbkSimFindObserver& aObserver )
|
|
374 |
: CActive( EPriorityStandard ),
|
|
375 |
iStore( aStore ),
|
|
376 |
iStringToFind( aStringToFind ),
|
|
377 |
iObserver( aObserver ),
|
|
378 |
iSimIndexBufPtr( NULL, 0 )
|
|
379 |
{
|
|
380 |
}
|
|
381 |
|
|
382 |
// --------------------------------------------------------------------------
|
|
383 |
// CRemoteStore::CFindOperation::ConstructL
|
|
384 |
// Symbian 2nd phase constructor can leave.
|
|
385 |
// --------------------------------------------------------------------------
|
|
386 |
//
|
|
387 |
void CRemoteStore::CFindOperation::ConstructL(
|
|
388 |
RVPbkSimFieldTypeArray& aFieldTypes )
|
|
389 |
{
|
|
390 |
CActiveScheduler::Add( this );
|
|
391 |
|
|
392 |
iFieldTypes = ExternalizeArrayLC( aFieldTypes );
|
|
393 |
CleanupStack::Pop( iFieldTypes );
|
|
394 |
iSimIndexBuf = HBufC8::NewL( KInitSimIndexBufSize );
|
|
395 |
iSimIndexBufPtr.Set( iSimIndexBuf->Des() );
|
|
396 |
}
|
|
397 |
|
|
398 |
// --------------------------------------------------------------------------
|
|
399 |
// CRemoteStore::CFindOperation::NewL
|
|
400 |
// Two-phased constructor.
|
|
401 |
// --------------------------------------------------------------------------
|
|
402 |
//
|
|
403 |
CRemoteStore::CFindOperation* CRemoteStore::CFindOperation::NewL(
|
|
404 |
CRemoteStore& aStore, const TDesC& aStringToFind,
|
|
405 |
MVPbkSimFindObserver& aObserver, RVPbkSimFieldTypeArray& aFieldTypes )
|
|
406 |
{
|
|
407 |
CFindOperation* self =
|
|
408 |
new( ELeave ) CFindOperation( aStore, aStringToFind, aObserver );
|
|
409 |
CleanupStack::PushL( self );
|
|
410 |
self->ConstructL( aFieldTypes );
|
|
411 |
CleanupStack::Pop( self );
|
|
412 |
return self;
|
|
413 |
}
|
|
414 |
|
|
415 |
// Destructor
|
|
416 |
CRemoteStore::CFindOperation::~CFindOperation()
|
|
417 |
{
|
|
418 |
Cancel();
|
|
419 |
delete iSimIndexBuf;
|
|
420 |
delete iFieldTypes;
|
|
421 |
}
|
|
422 |
|
|
423 |
// --------------------------------------------------------------------------
|
|
424 |
// CRemoteStore::CFindOperation::Activate
|
|
425 |
// --------------------------------------------------------------------------
|
|
426 |
//
|
|
427 |
void CRemoteStore::CFindOperation::Activate()
|
|
428 |
{
|
|
429 |
iStore.StoreSession().Find( iStatus, iStringToFind,
|
|
430 |
*iFieldTypes, iSimIndexBufPtr );
|
|
431 |
SetActive();
|
|
432 |
}
|
|
433 |
|
|
434 |
// --------------------------------------------------------------------------
|
|
435 |
// CRemoteStore::CFindOperation::RunL
|
|
436 |
// --------------------------------------------------------------------------
|
|
437 |
//
|
|
438 |
void CRemoteStore::CFindOperation::RunL()
|
|
439 |
{
|
|
440 |
RVPbkStreamedIntArray matchedIndexes;
|
|
441 |
CleanupClosePushL( matchedIndexes );
|
|
442 |
|
|
443 |
TInt result = iStatus.Int();
|
|
444 |
switch ( result )
|
|
445 |
{
|
|
446 |
case KErrNone:
|
|
447 |
{
|
|
448 |
RDesReadStream stream( iSimIndexBufPtr );
|
|
449 |
CleanupClosePushL( stream );
|
|
450 |
stream >> matchedIndexes;
|
|
451 |
CleanupStack::PopAndDestroy(); // stream
|
|
452 |
iObserver.FindCompleted( iStore, matchedIndexes );
|
|
453 |
break;
|
|
454 |
}
|
|
455 |
case KErrNotFound:
|
|
456 |
{
|
|
457 |
iObserver.FindCompleted( iStore, matchedIndexes );
|
|
458 |
break;
|
|
459 |
}
|
|
460 |
case KErrOverflow:
|
|
461 |
{
|
|
462 |
TInt newLength = 2 * iSimIndexBufPtr.MaxLength();
|
|
463 |
if ( newLength > KMaxSimIndexBufSize )
|
|
464 |
{
|
|
465 |
iObserver.FindError( iStore, result );
|
|
466 |
}
|
|
467 |
else
|
|
468 |
{
|
|
469 |
VPbkSimStoreImpl::CheckAndUpdateBufferSizeL( iSimIndexBuf,
|
|
470 |
iSimIndexBufPtr, newLength );
|
|
471 |
Activate();
|
|
472 |
}
|
|
473 |
break;
|
|
474 |
}
|
|
475 |
default:
|
|
476 |
{
|
|
477 |
iObserver.FindError( iStore, result );
|
|
478 |
break;
|
|
479 |
}
|
|
480 |
}
|
|
481 |
CleanupStack::PopAndDestroy(); // matchedIndexes
|
|
482 |
}
|
|
483 |
|
|
484 |
// --------------------------------------------------------------------------
|
|
485 |
// CRemoteStore::CFindOperation::DoCancel
|
|
486 |
// --------------------------------------------------------------------------
|
|
487 |
//
|
|
488 |
void CRemoteStore::CFindOperation::DoCancel()
|
|
489 |
{
|
|
490 |
iStore.StoreSession().CancelAsyncRequest( EVPbkSimSrvFind );
|
|
491 |
}
|
|
492 |
|
|
493 |
// --------------------------------------------------------------------------
|
|
494 |
// CRemoteStore::CFindOperation::RunError
|
|
495 |
// --------------------------------------------------------------------------
|
|
496 |
//
|
|
497 |
TInt CRemoteStore::CFindOperation::RunError( TInt aError )
|
|
498 |
{
|
|
499 |
iObserver.FindError( iStore, aError );
|
|
500 |
return KErrNone;
|
|
501 |
}
|
|
502 |
|
|
503 |
// --------------------------------------------------------------------------
|
|
504 |
// CRemoteStore::CRemoteStore
|
|
505 |
// C++ default constructor can NOT contain any code, that
|
|
506 |
// might leave.
|
|
507 |
// --------------------------------------------------------------------------
|
|
508 |
//
|
|
509 |
CRemoteStore::CRemoteStore( TVPbkSimStoreIdentifier aIdentifier )
|
|
510 |
: CActive( EPriorityStandard ),
|
|
511 |
iIdentifier( aIdentifier ),
|
|
512 |
iCurrentState( EVPbkSimUnknown )
|
|
513 |
{
|
|
514 |
}
|
|
515 |
|
|
516 |
// --------------------------------------------------------------------------
|
|
517 |
// CRemoteStore::ConstructL
|
|
518 |
// Symbian 2nd phase constructor can leave.
|
|
519 |
// --------------------------------------------------------------------------
|
|
520 |
//
|
|
521 |
void CRemoteStore::ConstructL()
|
|
522 |
{
|
|
523 |
CActiveScheduler::Add( this );
|
|
524 |
iContactConverter = CVPbkETelCntConverter::NewL();
|
|
525 |
iCurrentETelContact = CVPbkSimContactBuf::NewL( *this );
|
|
526 |
iCurrentContact = CVPbkSimContactBuf::NewL( *this );
|
|
527 |
iSystemPhoneNumberMaxLength =
|
|
528 |
VPbkSimStoreCommonUtil::SystemMaxPhoneNumberLengthL();
|
|
529 |
iAsyncOpenOp =
|
|
530 |
CVPbkAsyncObjectOperation<MVPbkSimStoreObserver>::NewL();
|
|
531 |
}
|
|
532 |
|
|
533 |
// --------------------------------------------------------------------------
|
|
534 |
// CRemoteStore::NewL
|
|
535 |
// Two-phased constructor.
|
|
536 |
// --------------------------------------------------------------------------
|
|
537 |
//
|
|
538 |
CRemoteStore* CRemoteStore::NewL( TVPbkSimStoreIdentifier aIdentifier )
|
|
539 |
{
|
|
540 |
CRemoteStore* self = new( ELeave ) CRemoteStore( aIdentifier );
|
|
541 |
CleanupStack::PushL( self );
|
|
542 |
self->ConstructL();
|
|
543 |
CleanupStack::Pop( self );
|
|
544 |
return self;
|
|
545 |
}
|
|
546 |
|
|
547 |
|
|
548 |
// Destructor
|
|
549 |
CRemoteStore::~CRemoteStore()
|
|
550 |
{
|
|
551 |
delete iAsyncOpenOp;
|
|
552 |
iObservers.Close();
|
|
553 |
delete iCurrentContact;
|
|
554 |
delete iCurrentETelContact;
|
|
555 |
delete iContactConverter;
|
|
556 |
ResetAndCloseStore();
|
|
557 |
}
|
|
558 |
|
|
559 |
// --------------------------------------------------------------------------
|
|
560 |
// CRemoteStore::AddObserverL
|
|
561 |
// --------------------------------------------------------------------------
|
|
562 |
//
|
|
563 |
void CRemoteStore::AddObserverL( MVPbkSimStoreObserver& aObserver )
|
|
564 |
{
|
|
565 |
// adds aObserver to list of observers if it isn't there already, thus
|
|
566 |
// avoids clients registering multiple times
|
|
567 |
if ( iObservers.Find( &aObserver ) == KErrNotFound )
|
|
568 |
{
|
|
569 |
iObservers.AppendL( &aObserver );
|
|
570 |
}
|
|
571 |
}
|
|
572 |
|
|
573 |
// --------------------------------------------------------------------------
|
|
574 |
// CRemoteStore::RemoveObserver
|
|
575 |
// --------------------------------------------------------------------------
|
|
576 |
//
|
|
577 |
void CRemoteStore::RemoveObserver( MVPbkSimStoreObserver& aObserver )
|
|
578 |
{
|
|
579 |
TInt index = iObservers.Find( &aObserver );
|
|
580 |
if ( index != KErrNotFound )
|
|
581 |
{
|
|
582 |
iObservers.Remove( index );
|
|
583 |
}
|
|
584 |
}
|
|
585 |
|
|
586 |
// --------------------------------------------------------------------------
|
|
587 |
// CRemoteStore::IsOpen
|
|
588 |
// --------------------------------------------------------------------------
|
|
589 |
//
|
|
590 |
TBool CRemoteStore::IsOpen() const
|
|
591 |
{
|
|
592 |
return iCurrentState == EVPbkSimStoreOpen;
|
|
593 |
}
|
|
594 |
|
|
595 |
// --------------------------------------------------------------------------
|
|
596 |
// CRemoteStore::RunL
|
|
597 |
// --------------------------------------------------------------------------
|
|
598 |
//
|
|
599 |
void CRemoteStore::RunL()
|
|
600 |
{
|
|
601 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
|
|
602 |
"CRemoteStore::RunL: result %d, handle %d, id %d"),
|
|
603 |
iStatus.Int(), iSimStore.Handle(), iIdentifier );
|
|
604 |
VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
|
|
605 |
"CRemoteStore::RunL: event %d, eventData %d, eventOpData %d"),
|
|
606 |
iStoreEvent.iEvent, iStoreEvent.iData, iStoreEvent.iOpData);
|
|
607 |
|
|
608 |
if ( iStatus == KErrNone )
|
|
609 |
{
|
|
610 |
switch ( iStoreEvent.iEvent )
|
|
611 |
{
|
|
612 |
case EVPbkSimPhoneOpen:
|
|
613 |
{
|
|
614 |
// Open the store only first time. It's possible
|
|
615 |
// that phone and store can change unavailable<->open
|
|
616 |
// later.
|
|
617 |
if ( iCurrentState == EVPbkSimUnknown )
|
|
618 |
{
|
|
619 |
if( iSecurityInfo )
|
|
620 |
{
|
|
621 |
iSimStore.OpenL( *iSecurityInfo, iIdentifier );
|
|
622 |
}
|
|
623 |
else
|
|
624 |
{
|
|
625 |
// OpenL invoked with MVPbkSimCntStore::OpenL
|
|
626 |
// CRemoteStore::OpenL( secInfo, observer ) should be used instead.
|
|
627 |
User::Leave( KErrPermissionDenied );
|
|
628 |
}
|
|
629 |
}
|
|
630 |
break;
|
|
631 |
}
|
|
632 |
case EVPbkSimStoreOpen:
|
|
633 |
{
|
|
634 |
iCurrentState = iStoreEvent.iEvent;
|
|
635 |
iAsyncOpenOp->Purge();
|
|
636 |
SendStoreEventMessage( iObservers,
|
|
637 |
&MVPbkSimStoreObserver::StoreReady, *this );
|
|
638 |
break;
|
|
639 |
}
|
|
640 |
case EVPbkSimStoreNotAvailable:
|
|
641 |
{
|
|
642 |
iCurrentState = iStoreEvent.iEvent;
|
|
643 |
iAsyncOpenOp->Purge();
|
|
644 |
SendStoreEventMessage( iObservers,
|
|
645 |
&MVPbkSimStoreObserver::StoreNotAvailable, *this );
|
|
646 |
break;
|
|
647 |
}
|
|
648 |
case EVPbkSimContactAdded:
|
|
649 |
{
|
|
650 |
SendStoreEventMessage(iObservers, &MVPbkSimStoreObserver::StoreContactEvent,
|
|
651 |
MVPbkSimStoreObserver::EContactAdded,
|
|
652 |
iStoreEvent.iOpData );
|
|
653 |
break;
|
|
654 |
}
|
|
655 |
case EVPbkSimContactDeleted:
|
|
656 |
{
|
|
657 |
SendStoreEventMessage(iObservers, &MVPbkSimStoreObserver::StoreContactEvent,
|
|
658 |
MVPbkSimStoreObserver::EContactDeleted,
|
|
659 |
iStoreEvent.iOpData );
|
|
660 |
break;
|
|
661 |
}
|
|
662 |
case EVPbkSimContactChanged:
|
|
663 |
{
|
|
664 |
SendStoreEventMessage(iObservers, &MVPbkSimStoreObserver::StoreContactEvent,
|
|
665 |
MVPbkSimStoreObserver::EContactChanged,
|
|
666 |
iStoreEvent.iOpData );
|
|
667 |
break;
|
|
668 |
}
|
|
669 |
// Store is not interested in these events
|
|
670 |
case EVPbkSimPhoneServiceTableUpdated: // FALLTHROUGH
|
|
671 |
case EVPbkSimPhoneFdnStatusChanged:
|
|
672 |
{
|
|
673 |
break;
|
|
674 |
}
|
|
675 |
case EVPbkSimPhoneError:
|
|
676 |
{
|
|
677 |
iAsyncOpenOp->Purge();
|
|
678 |
TInt id = iStoreEvent.iData;
|
|
679 |
|
|
680 |
if ( IsOpen() && id == MVPbkSimPhoneObserver::ESimCardNotInserted )
|
|
681 |
{
|
|
682 |
iCurrentState = iStoreEvent.iEvent;
|
|
683 |
}
|
|
684 |
|
|
685 |
// If not SIM card or BT SAP is active then store is not available
|
|
686 |
if ( id == MVPbkSimPhoneObserver::ESimCardNotInserted ||
|
|
687 |
id == MVPbkSimPhoneObserver::EBtSapActive )
|
|
688 |
{
|
|
689 |
SendStoreEventMessage( iObservers,
|
|
690 |
&MVPbkSimStoreObserver::StoreNotAvailable, *this );
|
|
691 |
}
|
|
692 |
else
|
|
693 |
{
|
|
694 |
SendStoreErrorMessage( iObservers, *this, iStoreEvent.iOpData );
|
|
695 |
}
|
|
696 |
break;
|
|
697 |
}
|
|
698 |
case EVPbkSimStoreError: // FALLTHROUGH
|
|
699 |
{
|
|
700 |
iCurrentState = iStoreEvent.iEvent;
|
|
701 |
iAsyncOpenOp->Purge();
|
|
702 |
SendStoreErrorMessage( iObservers, *this, iStoreEvent.iOpData );
|
|
703 |
break;
|
|
704 |
}
|
|
705 |
default:
|
|
706 |
{
|
|
707 |
__ASSERT_DEBUG(EFalse, Panic(EUnknownSimStoreEvent));
|
|
708 |
iAsyncOpenOp->Purge();
|
|
709 |
SendStoreErrorMessage( iObservers, *this, iStoreEvent.iOpData );
|
|
710 |
break;
|
|
711 |
}
|
|
712 |
}
|
|
713 |
}
|
|
714 |
else
|
|
715 |
{
|
|
716 |
// Error case.
|
|
717 |
iCurrentState = EVPbkSimStoreNotAvailable;
|
|
718 |
iAsyncOpenOp->Purge();
|
|
719 |
SendStoreErrorMessage( iObservers, *this, iStatus.Int() );
|
|
720 |
}
|
|
721 |
|
|
722 |
// check session, it may have been closed during message send
|
|
723 |
if ( iSimStore.Handle() )
|
|
724 |
{
|
|
725 |
// Listen to store event always.
|
|
726 |
iSimStore.ListenToStoreEvents( iStatus, iStoreEvent );
|
|
727 |
SetActive();
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
// --------------------------------------------------------------------------
|
|
732 |
// CRemoteStore::DoCancel
|
|
733 |
// --------------------------------------------------------------------------
|
|
734 |
//
|
|
735 |
void CRemoteStore::DoCancel()
|
|
736 |
{
|
|
737 |
iSimStore.CancelAsyncRequest( EVPbkSimSrvStoreEventNotification );
|
|
738 |
}
|
|
739 |
|
|
740 |
// --------------------------------------------------------------------------
|
|
741 |
// CRemoteStore::RunError
|
|
742 |
// --------------------------------------------------------------------------
|
|
743 |
//
|
|
744 |
TInt CRemoteStore::RunError( TInt aError )
|
|
745 |
{
|
|
746 |
SendStoreErrorMessage( iObservers, *this, aError );
|
|
747 |
return KErrNone;
|
|
748 |
}
|
|
749 |
|
|
750 |
// --------------------------------------------------------------------------
|
|
751 |
// CRemoteStore::Identifier
|
|
752 |
// --------------------------------------------------------------------------
|
|
753 |
//
|
|
754 |
TVPbkSimStoreIdentifier CRemoteStore::Identifier() const
|
|
755 |
{
|
|
756 |
return iIdentifier;
|
|
757 |
}
|
|
758 |
|
|
759 |
// --------------------------------------------------------------------------
|
|
760 |
// CRemoteStore::OpenL
|
|
761 |
// --------------------------------------------------------------------------
|
|
762 |
//
|
|
763 |
void CRemoteStore::OpenL( MVPbkSimStoreObserver& aObserver )
|
|
764 |
{
|
|
765 |
if ( iSimStore.Handle() )
|
|
766 |
{
|
|
767 |
CVPbkAsyncObjectCallback<MVPbkSimStoreObserver>* callback =
|
|
768 |
VPbkEngUtils::CreateAsyncObjectCallbackLC(
|
|
769 |
*this,
|
|
770 |
&CRemoteStore::DoOpenL,
|
|
771 |
&CRemoteStore::DoOpenError,
|
|
772 |
aObserver);
|
|
773 |
iAsyncOpenOp->CallbackL( callback );
|
|
774 |
CleanupStack::Pop( callback );
|
|
775 |
}
|
|
776 |
else
|
|
777 |
{
|
|
778 |
// Connect to sim store server
|
|
779 |
iSimStore.ConnectToServerL();
|
|
780 |
// Start listening to store events
|
|
781 |
iSimStore.ListenToStoreEvents( iStatus, iStoreEvent );
|
|
782 |
SetActive();
|
|
783 |
// Open the phone, after phone is open we can open store
|
|
784 |
iSimStore.OpenPhoneL();
|
|
785 |
}
|
|
786 |
|
|
787 |
AddObserverL( aObserver );
|
|
788 |
}
|
|
789 |
|
|
790 |
// --------------------------------------------------------------------------
|
|
791 |
// CRemoteStore::OpenL
|
|
792 |
// --------------------------------------------------------------------------
|
|
793 |
//
|
|
794 |
void CRemoteStore::OpenL( const TSecurityInfo& aSecurityInfo,
|
|
795 |
MVPbkSimStoreObserver& aObserver )
|
|
796 |
{
|
|
797 |
OpenL( aObserver );
|
|
798 |
iSecurityInfo = &aSecurityInfo;
|
|
799 |
}
|
|
800 |
|
|
801 |
// --------------------------------------------------------------------------
|
|
802 |
// CRemoteStore::Close
|
|
803 |
// --------------------------------------------------------------------------
|
|
804 |
//
|
|
805 |
void CRemoteStore::Close( MVPbkSimStoreObserver& aObserver )
|
|
806 |
{
|
|
807 |
iAsyncOpenOp->CancelCallback( &aObserver );
|
|
808 |
RemoveObserver( aObserver );
|
|
809 |
ResetAndCloseStore();
|
|
810 |
}
|
|
811 |
|
|
812 |
// --------------------------------------------------------------------------
|
|
813 |
// CRemoteStore::CreateViewL
|
|
814 |
// --------------------------------------------------------------------------
|
|
815 |
//
|
|
816 |
MVPbkSimCntView* CRemoteStore::CreateViewL(
|
|
817 |
const RVPbkSimFieldTypeArray& aSortOrder,
|
|
818 |
TVPbkSimViewConstructionPolicy aConstructionPolicy,
|
|
819 |
const TDesC& aViewName,
|
|
820 |
CVPbkSimFieldTypeFilter* aFilter )
|
|
821 |
{
|
|
822 |
// Create always a remote view which is shared in the server
|
|
823 |
// side.
|
|
824 |
return CRemoteView::NewL( *this, aSortOrder, aConstructionPolicy,
|
|
825 |
aViewName, aFilter );
|
|
826 |
}
|
|
827 |
|
|
828 |
// --------------------------------------------------------------------------
|
|
829 |
// CRemoteStore::ReadLC
|
|
830 |
// --------------------------------------------------------------------------
|
|
831 |
//
|
|
832 |
const TDesC8* CRemoteStore::AtL( TInt aSimIndex )
|
|
833 |
{
|
|
834 |
HBufC8* cnt = iSimStore.ReadLC( aSimIndex );
|
|
835 |
if ( cnt )
|
|
836 |
{
|
|
837 |
iCurrentETelContact->SetL( *cnt );
|
|
838 |
CleanupStack::PopAndDestroy( cnt );
|
|
839 |
return &iCurrentETelContact->ETelContactL();
|
|
840 |
}
|
|
841 |
return NULL;
|
|
842 |
}
|
|
843 |
|
|
844 |
// --------------------------------------------------------------------------
|
|
845 |
// CRemoteStore::ContactAtL
|
|
846 |
// --------------------------------------------------------------------------
|
|
847 |
//
|
|
848 |
const MVPbkSimContact* CRemoteStore::ContactAtL( TInt aSimIndex )
|
|
849 |
{
|
|
850 |
HBufC8* cnt = iSimStore.ReadLC( aSimIndex );
|
|
851 |
if ( cnt )
|
|
852 |
{
|
|
853 |
iCurrentContact->SetL( *cnt );
|
|
854 |
CleanupStack::PopAndDestroy( cnt );
|
|
855 |
return iCurrentContact;
|
|
856 |
}
|
|
857 |
return NULL;
|
|
858 |
}
|
|
859 |
|
|
860 |
// --------------------------------------------------------------------------
|
|
861 |
// CRemoteStore::SaveL
|
|
862 |
// --------------------------------------------------------------------------
|
|
863 |
//
|
|
864 |
MVPbkSimStoreOperation* CRemoteStore::SaveL( const TDesC8& aData,
|
|
865 |
TInt& aSimIndex, MVPbkSimContactObserver& aObserver )
|
|
866 |
{
|
|
867 |
CAsyncSave* op = new( ELeave ) CAsyncSave( iSimStore );
|
|
868 |
CleanupStack::PushL( op );
|
|
869 |
op->DoRequestL( aData, aSimIndex, aObserver );
|
|
870 |
CleanupStack::Pop( op );
|
|
871 |
return op;
|
|
872 |
}
|
|
873 |
|
|
874 |
// --------------------------------------------------------------------------
|
|
875 |
// CRemoteStore::DeleteL
|
|
876 |
// --------------------------------------------------------------------------
|
|
877 |
//
|
|
878 |
MVPbkSimStoreOperation* CRemoteStore::DeleteL(
|
|
879 |
RVPbkStreamedIntArray& aSimIndexes,
|
|
880 |
MVPbkSimContactObserver& aObserver )
|
|
881 |
{
|
|
882 |
CAsyncDelete* op = new( ELeave ) CAsyncDelete( iSimStore );
|
|
883 |
CleanupStack::PushL( op );
|
|
884 |
op->DoRequestL( aSimIndexes, aObserver );
|
|
885 |
CleanupStack::Pop( op );
|
|
886 |
return op;
|
|
887 |
}
|
|
888 |
|
|
889 |
// --------------------------------------------------------------------------
|
|
890 |
// CRemoteStore::GetGsmStoreProperties
|
|
891 |
// --------------------------------------------------------------------------
|
|
892 |
//
|
|
893 |
TInt CRemoteStore::GetGsmStoreProperties(
|
|
894 |
TVPbkGsmStoreProperty& aGsmProperties ) const
|
|
895 |
{
|
|
896 |
return iSimStore.GetGsmStoreProperties( aGsmProperties );
|
|
897 |
}
|
|
898 |
|
|
899 |
// --------------------------------------------------------------------------
|
|
900 |
// CRemoteStore::GetUSimStoreProperties
|
|
901 |
// --------------------------------------------------------------------------
|
|
902 |
//
|
|
903 |
TInt CRemoteStore::GetUSimStoreProperties(
|
|
904 |
TVPbkUSimStoreProperty& aUSimProperties ) const
|
|
905 |
{
|
|
906 |
return iSimStore.GetUSimStoreProperties( aUSimProperties );
|
|
907 |
}
|
|
908 |
|
|
909 |
// --------------------------------------------------------------------------
|
|
910 |
// CRemoteStore::ContactConverter
|
|
911 |
// --------------------------------------------------------------------------
|
|
912 |
//
|
|
913 |
const CVPbkETelCntConverter& CRemoteStore::ContactConverter() const
|
|
914 |
{
|
|
915 |
return *iContactConverter;
|
|
916 |
}
|
|
917 |
|
|
918 |
// --------------------------------------------------------------------------
|
|
919 |
// CRemoteStore::CreateMatchPhoneNumberOperationL
|
|
920 |
// --------------------------------------------------------------------------
|
|
921 |
//
|
|
922 |
MVPbkSimStoreOperation* CRemoteStore::CreateMatchPhoneNumberOperationL(
|
|
923 |
const TDesC& aPhoneNumber, TInt aMaxMatchDigits,
|
|
924 |
MVPbkSimFindObserver& aObserver )
|
|
925 |
{
|
|
926 |
CNumberMatchOperation* op = CNumberMatchOperation::NewL( *this,
|
|
927 |
aPhoneNumber, aMaxMatchDigits, aObserver );
|
|
928 |
op->Activate();
|
|
929 |
return op;
|
|
930 |
}
|
|
931 |
|
|
932 |
// --------------------------------------------------------------------------
|
|
933 |
// CRemoteStore::CreateFindOperationL
|
|
934 |
// --------------------------------------------------------------------------
|
|
935 |
//
|
|
936 |
MVPbkSimStoreOperation* CRemoteStore::CreateFindOperationL(
|
|
937 |
const TDesC& aStringToFind, RVPbkSimFieldTypeArray& aFieldTypes,
|
|
938 |
MVPbkSimFindObserver& aObserver )
|
|
939 |
{
|
|
940 |
CFindOperation* op =
|
|
941 |
CFindOperation::NewL( *this, aStringToFind, aObserver, aFieldTypes );
|
|
942 |
op->Activate();
|
|
943 |
return op;
|
|
944 |
}
|
|
945 |
|
|
946 |
// --------------------------------------------------------------------------
|
|
947 |
// CRemoteStore::SystemPhoneNumberMaxLength
|
|
948 |
// --------------------------------------------------------------------------
|
|
949 |
//
|
|
950 |
TInt CRemoteStore::SystemPhoneNumberMaxLength() const
|
|
951 |
{
|
|
952 |
return iSystemPhoneNumberMaxLength;
|
|
953 |
}
|
|
954 |
|
|
955 |
// --------------------------------------------------------------------------
|
|
956 |
// CRemoteStore::ResetAndCloseStore
|
|
957 |
// --------------------------------------------------------------------------
|
|
958 |
//
|
|
959 |
void CRemoteStore::ResetAndCloseStore()
|
|
960 |
{
|
|
961 |
if ( iObservers.Count() == 0 )
|
|
962 |
{
|
|
963 |
// Close session if no observers
|
|
964 |
Cancel();
|
|
965 |
iSimStore.Close();
|
|
966 |
iCurrentState = EVPbkSimUnknown;
|
|
967 |
}
|
|
968 |
}
|
|
969 |
|
|
970 |
// --------------------------------------------------------------------------
|
|
971 |
// CRemoteStore::DoOpenL
|
|
972 |
// --------------------------------------------------------------------------
|
|
973 |
//
|
|
974 |
void CRemoteStore::DoOpenL( MVPbkSimStoreObserver& aObserver )
|
|
975 |
{
|
|
976 |
switch ( iCurrentState )
|
|
977 |
{
|
|
978 |
case EVPbkSimStoreOpen:
|
|
979 |
{
|
|
980 |
aObserver.StoreReady( *this );
|
|
981 |
break;
|
|
982 |
}
|
|
983 |
case EVPbkSimUnknown:
|
|
984 |
{
|
|
985 |
// Wait that store receives its state from server.
|
|
986 |
break;
|
|
987 |
}
|
|
988 |
default:
|
|
989 |
{
|
|
990 |
aObserver.StoreNotAvailable( *this );
|
|
991 |
break;
|
|
992 |
}
|
|
993 |
}
|
|
994 |
}
|
|
995 |
|
|
996 |
// --------------------------------------------------------------------------
|
|
997 |
// CRemoteStore::DoOpenError
|
|
998 |
// --------------------------------------------------------------------------
|
|
999 |
//
|
|
1000 |
void CRemoteStore::DoOpenError( MVPbkSimStoreObserver& aObserver,
|
|
1001 |
TInt aError )
|
|
1002 |
{
|
|
1003 |
aObserver.StoreError( *this, aError );
|
|
1004 |
}
|
|
1005 |
} // namespace VPbkSimStore
|
|
1006 |
// End of File
|