|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Multimode TSY Phone book Implementation file. |
|
15 // This file contains the implementation of the CATPhoneBookCommands, CATPhoneBookInit, |
|
16 // CATPhoneBookWrite and CATPhoneBookDelete classes. |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "Mphbkcom.h" |
|
25 #include "mSLOGGER.H" |
|
26 #include "mPHBOOK.H" |
|
27 #include "NOTIFY.H" |
|
28 #include "ATIO.H" |
|
29 #include "Matstd.h" |
|
30 |
|
31 // AT commands |
|
32 |
|
33 _LIT8(KPhoneBookReadAll,"AT+CPBR="); // Modified from "AT+CPBR=1,n; 1 is not always the starting index |
|
34 _LIT8(KPhoneBookReadResponse,"+CPBR:*"); |
|
35 |
|
36 _LIT8(KPhoneBookWriteWithIndex,"AT+CPBW=%d,\"%S\",%d,\"%S\""); |
|
37 _LIT8(KPhoneBookWriteWithIndexPrependedPlus,"AT+CPBW=%d,\"+%S\",%d,\"%S\""); |
|
38 _LIT8(KPhoneBookDelete,"AT+CPBW=%d"); |
|
39 _LIT8(KPhoneBookAlternativeDelete,"AT+CPBW=%d,\"\",,\"\""); |
|
40 |
|
41 |
|
42 const TInt KPhoneBookTimeForExtraRxData=100; |
|
43 |
|
44 // Time-outs |
|
45 |
|
46 const TInt KPhoneBookReadTimeout=30; //< Time-out used when reading the phone books (in seconds). For sizeable phonebooks, this can be large. |
|
47 //< The Siemens S25 is the slowest phone observed. The Nokia 8210 can take 14s to read an empty 200 entry phonebook. |
|
48 |
|
49 // |
|
50 // CATPhoneBookCommands definitions |
|
51 // |
|
52 |
|
53 CATPhoneBookCommands::CATPhoneBookCommands(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
54 : CATCommands(aIo,aTelObject,aInit,aPhoneGlobals), iState(EATPhoneBookCommandIdle) |
|
55 {} |
|
56 |
|
57 CATPhoneBookCommands::~CATPhoneBookCommands() |
|
58 /** |
|
59 * Destructor. |
|
60 */ |
|
61 { |
|
62 iIo->RemoveExpectStrings(this); |
|
63 } |
|
64 |
|
65 void CATPhoneBookCommands::EventSignal(TEventSource aEventSource) |
|
66 /** |
|
67 * This function contains the State machine for the phonebook commands whose classes |
|
68 * inherit from the CATPhoneBookCommands class. |
|
69 * |
|
70 * Note: The cases EATPhoneBookCommandWaitForReadComplete & EATPhoneBookCommandWait- |
|
71 * ForAlternativeReadComplete are overriden by similar cases in CATPhoneBookInit:: |
|
72 * EventSignal and CATPhoneBookRead::EventSignal. |
|
73 */ |
|
74 { |
|
75 if (aEventSource==ETimeOutCompletion && iState!=EATPhoneBookCommandExtendedRead) |
|
76 { |
|
77 LOGTEXT(_L8("Timeout Error during phone book command")); |
|
78 RemoveStdExpectStrings(); |
|
79 Complete(KErrTimedOut,aEventSource); |
|
80 return; |
|
81 } |
|
82 |
|
83 TInt ret=KErrNone; |
|
84 switch (iState) |
|
85 { |
|
86 case EATPhoneBookStorageSelectWaitForWriteComplete: |
|
87 __ASSERT_ALWAYS(aEventSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected)); |
|
88 AddStdExpectStrings(); |
|
89 iIo->SetTimeOut(this); |
|
90 iState=EATPhoneBookStorageSelectWaitForReadComplete; |
|
91 return; |
|
92 |
|
93 case EATPhoneBookStorageSelectWaitForReadComplete: |
|
94 __ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
95 { |
|
96 ret=ValidateExpectString(); |
|
97 RemoveStdExpectStrings(); |
|
98 if (ret!=KErrNone) |
|
99 { |
|
100 Complete(ret,aEventSource); |
|
101 return; |
|
102 } |
|
103 CMobilePhonebookStore* phoneBook=REINTERPRET_CAST(CMobilePhonebookStore*,iTelObject); |
|
104 iPhoneGlobals->iPhoneStatus.iLastAccessedPhoneBook=phoneBook->StorageType(); |
|
105 } |
|
106 StartThisCommand(); |
|
107 return; |
|
108 |
|
109 case EATPhoneBookCommandWaitForWriteComplete: |
|
110 __ASSERT_ALWAYS(aEventSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected)); |
|
111 iIo->SetTimeOut(this); |
|
112 AddStdExpectStrings(); |
|
113 iState=EATPhoneBookCommandWaitForReadComplete; |
|
114 return; |
|
115 |
|
116 case EATPhoneBookCommandWaitForReadComplete: |
|
117 case EATPhoneBookCommandWaitForAlternativeReadComplete: |
|
118 __ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
119 ret=ValidateExpectString(); |
|
120 RemoveStdExpectStrings(); |
|
121 if (ret!=KErrNone) |
|
122 { |
|
123 Complete(ret,aEventSource); |
|
124 return; |
|
125 } |
|
126 iIo->SetTimeOut(this,KPhoneBookTimeForExtraRxData); |
|
127 iState=EATPhoneBookCommandExtendedRead; |
|
128 return; |
|
129 |
|
130 case EATPhoneBookCommandWaitForAlternativeWriteComplete: |
|
131 __ASSERT_ALWAYS(aEventSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected)); |
|
132 iIo->SetTimeOut(this,KPhoneBookReadTimeout*KOneSecondPause); |
|
133 AddStdExpectStrings(); |
|
134 iState=EATPhoneBookCommandWaitForAlternativeReadComplete; |
|
135 return; |
|
136 |
|
137 case EATPhoneBookCommandExtendedRead: |
|
138 __ASSERT_ALWAYS(aEventSource==ETimeOutCompletion,Panic(EATCommand_IllegalCompletionWaitExpected)); |
|
139 Complete(ret,aEventSource); |
|
140 return; |
|
141 |
|
142 case EATPhoneBookCommandIdle: |
|
143 default: |
|
144 return; |
|
145 } |
|
146 } |
|
147 |
|
148 void CATPhoneBookCommands::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus) |
|
149 /** |
|
150 * This function is called if an error occurs. It cancels the relevant timer and |
|
151 * completes the request before setting the state to Idle. |
|
152 */ |
|
153 { |
|
154 if (iState!=EATPhoneBookCommandIdle) |
|
155 { |
|
156 iIo->WriteAndTimerCancel(this); |
|
157 iTelObject->ReqCompleted(iReqHandle,aStatus); |
|
158 iState=EATPhoneBookCommandIdle; |
|
159 } |
|
160 } |
|
161 |
|
162 void CATPhoneBookCommands::StartStorageSelect() |
|
163 /** |
|
164 * This function finds out which phone book memory to set and then transmits the |
|
165 * set command ("AT+CPBS=xx") to the relevant phone book. |
|
166 */ |
|
167 { |
|
168 LOGTEXT(_L8("Starting AT+CPBS= Command")); |
|
169 |
|
170 CMobilePhonebookStore* phoneBook=REINTERPRET_CAST(CMobilePhonebookStore*,iTelObject); |
|
171 if (iPhoneGlobals->iPhoneStatus.iLastAccessedPhoneBook==phoneBook->StorageType()) |
|
172 { |
|
173 StartThisCommand(); |
|
174 } |
|
175 else |
|
176 { |
|
177 TBuf8<KGenericBufferSize> buf; |
|
178 TStorageType storageType(phoneBook->StorageType()); |
|
179 buf.Format(KPhoneBookStorageSet,&storageType); |
|
180 WriteExpectingResults(buf,3); |
|
181 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral)); |
|
182 iState=EATPhoneBookStorageSelectWaitForWriteComplete; |
|
183 } |
|
184 } |
|
185 |
|
186 void CATPhoneBookCommands::Stop(TTsyReqHandle aTsyReqHandle) |
|
187 /** |
|
188 * This function is used to prematurely stop the state machine. This would usually |
|
189 * occur following a client cancel request. |
|
190 */ |
|
191 { |
|
192 __ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle)); |
|
193 LOGTEXT(_L8("Cancelling phone book command")); |
|
194 |
|
195 switch (iState) |
|
196 { |
|
197 case EATPhoneBookStorageSelectWaitForWriteComplete: |
|
198 case EATPhoneBookCommandWaitForWriteComplete: |
|
199 case EATPhoneBookCommandWaitForAlternativeWriteComplete: |
|
200 Complete(KErrCancel,EWriteCompletion); |
|
201 return; |
|
202 |
|
203 case EATPhoneBookStorageSelectWaitForReadComplete: |
|
204 case EATPhoneBookCommandWaitForReadComplete: |
|
205 case EATPhoneBookCommandWaitForAlternativeReadComplete: |
|
206 Complete(KErrCancel,EReadCompletion); |
|
207 return; |
|
208 |
|
209 case EATPhoneBookCommandExtendedRead: |
|
210 Complete(KErrCancel,ETimeOutCompletion); |
|
211 return; |
|
212 |
|
213 case EATPhoneBookCommandIdle: |
|
214 default: |
|
215 return; |
|
216 } |
|
217 } |
|
218 |
|
219 void CATPhoneBookCommands::Complete(TInt aError,TEventSource aSource) |
|
220 /** |
|
221 * This function completes a client request. Sets the state machine to Idle. |
|
222 */ |
|
223 { |
|
224 iIo->WriteAndTimerCancel(this); |
|
225 iIo->RemoveExpectStrings(this); |
|
226 if (aSource==EWriteCompletion) |
|
227 iIo->Read(); |
|
228 iState=EATPhoneBookCommandIdle; |
|
229 CATCommands::Complete(aError,aSource); |
|
230 iTelObject->ReqCompleted(iReqHandle,aError); |
|
231 } |
|
232 |
|
233 // |
|
234 // CATPhoneBookRead definitions |
|
235 // |
|
236 |
|
237 CATPhoneBookRead::CATPhoneBookRead(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals,CATPhoneBookInfo *aInfo) |
|
238 : CATPhoneBookCommands(aIo,aTelObject,aInit,aPhoneGlobals), |
|
239 iInfo(aInfo) |
|
240 /** |
|
241 * C++ constructor |
|
242 */ |
|
243 {} |
|
244 |
|
245 CATPhoneBookRead::~CATPhoneBookRead() |
|
246 /** |
|
247 * Destructor. |
|
248 */ |
|
249 { |
|
250 delete iPbBuffer; |
|
251 } |
|
252 |
|
253 CATPhoneBookRead* CATPhoneBookRead::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals,CATPhoneBookInfo *aInfo) |
|
254 /** |
|
255 * Standard 2 phase constructor. |
|
256 * This method creats an instance of the CATPhoneBookRead class. |
|
257 */ |
|
258 { |
|
259 CATPhoneBookRead* r=new(ELeave) CATPhoneBookRead(aIo,aTelObject,aInit,aPhoneGlobals,aInfo); |
|
260 CleanupStack::PushL(r); |
|
261 r->ConstructL(); |
|
262 CleanupStack::Pop(); |
|
263 return r; |
|
264 } |
|
265 |
|
266 void CATPhoneBookRead::ConstructL() |
|
267 /** |
|
268 * Standard 2nd phase constructor. |
|
269 * Creates phonebook buffer object used to populate client buffer |
|
270 */ |
|
271 { |
|
272 CATCommands::ConstructL(); |
|
273 iPbBuffer = new(ELeave) CPhoneBookBuffer(); |
|
274 } |
|
275 |
|
276 void CATPhoneBookRead::Start(TTsyReqHandle aTsyReqHandle,TAny* aParams) |
|
277 /** |
|
278 * Start function. Its calls the StartStorageSelect() function to select |
|
279 * the phone book memory. |
|
280 */ |
|
281 { |
|
282 iReqHandle=aTsyReqHandle; |
|
283 iRead = static_cast<RMobilePhoneBookStore::TPBIndexAndNumEntries*>(aParams); |
|
284 StartStorageSelect(); |
|
285 } |
|
286 |
|
287 void CATPhoneBookRead::StartThisCommand() |
|
288 /** |
|
289 * This function starts the "AT+CPBR=minimum index, maximum index" command, i.e, |
|
290 * Read one or a number of entries in the selected phone book. It constructs the command |
|
291 * using the starting index and the number of entries that are to be read. It |
|
292 * then sets the state machine going. |
|
293 */ |
|
294 { |
|
295 LOGTEXT(_L8("Starting AT+CPBR=minIndex,maxIndex Command (Read one or more entries)")); |
|
296 |
|
297 // Construct the AT+CPBR=a,z command. The starting index is not necessarily 1 |
|
298 TBuf8<KGenericBufferSize> buf(KPhoneBookReadAll); |
|
299 buf.AppendNum(iRead->iIndex); // starting location in the phonebook from which to read |
|
300 |
|
301 if (iRead->iNumSlots>1) |
|
302 { |
|
303 // If more than one entry to be read also put finishing index |
|
304 buf.Append(KCommaChar); |
|
305 buf.AppendNum(iRead->iIndex + iRead->iNumSlots -1); // last location from which to read |
|
306 } |
|
307 |
|
308 iNumReadEntries=0; |
|
309 WriteExpectingResults(buf,3); |
|
310 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral)); |
|
311 iCPBRResponse=iIo->AddExpectString(this,KPhoneBookReadResponse); |
|
312 iState=EATPhoneBookCommandWaitForAlternativeWriteComplete; |
|
313 } |
|
314 |
|
315 void CATPhoneBookRead::ParseResponseL() |
|
316 /** |
|
317 * This function parses a line of response to the "AT+CBPR=minimum index, maximum index" |
|
318 * command and converts the phonebook data into the TLV format. Note that the minimum |
|
319 * index of the phone book memory need not necessarily |
|
320 * start at 1 (e.g the phonebook could use range [100 to 150]. |
|
321 */ |
|
322 { |
|
323 ParseBufferLC(EFalse, ':'); |
|
324 |
|
325 TDblQueIter<CATParamListEntry> iter(iRxResults); |
|
326 CATParamListEntry* entry=iter++; //Assume discarded CPBR string |
|
327 if (entry==NULL) |
|
328 User::Leave(KErrGeneral); |
|
329 TInt ret(KErrNone); |
|
330 TBuf16<KGenericBufferSize> buffer; |
|
331 |
|
332 // new entry so append the new entry tag first |
|
333 if(iPbBuffer->AddNewEntryTag() == KErrNone) |
|
334 { |
|
335 // convert index into TLV format and append it to the supplied buffer |
|
336 entry=iter++; |
|
337 if(!entry) |
|
338 User::Leave(KErrGeneral); |
|
339 TInt index=CATParamListEntry::EntryValL(entry); |
|
340 |
|
341 if (iInfo->Completed()) |
|
342 { |
|
343 LOGTEXT(_L8("CATPhoneBookRead::ParseResponseL Mapping phone index to client index")); |
|
344 iInfo->MapPhoneIndexToClientIndex(index); |
|
345 } |
|
346 |
|
347 ret = iPbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex, static_cast<TUint16>(index)); |
|
348 |
|
349 if(ret == KErrNone) // only continue if the previous field successfully appended |
|
350 { |
|
351 // convert number into TLV format and append it to the supplied buffer |
|
352 entry=iter++; |
|
353 if (!entry) |
|
354 User::Leave(KErrGeneral); |
|
355 buffer.Copy(entry->iResultPtr); |
|
356 // If the number has a leading "+" then remove it. Note: in this case, we assume that the TON will be international. |
|
357 if((buffer.Length()>0)&&(buffer[0]=='+')) |
|
358 buffer.Delete(0,1); |
|
359 |
|
360 TPtrC16 numberPtr(buffer); |
|
361 ret=iPbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, numberPtr); |
|
362 |
|
363 if(ret == KErrNone) // only continue if the previous field successfully appended |
|
364 { |
|
365 // convert type into TLV format and append it to the supplied buffer |
|
366 entry=iter++; |
|
367 TInt type=CATParamListEntry::EntryValL(entry); |
|
368 ret=iPbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi, static_cast<TUint8>(type)); |
|
369 |
|
370 if(ret == KErrNone) // only continue if the previous field successfully appended |
|
371 { |
|
372 // convert text into TLV format and append it to the supplied buffer |
|
373 entry=iter++; |
|
374 if (!entry) |
|
375 User::Leave(KErrGeneral); |
|
376 buffer.Copy(entry->iResultPtr); |
|
377 TPtrC16 textPtr(buffer); |
|
378 ret=iPbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, textPtr); |
|
379 if(ret==KErrNone) |
|
380 iNumReadEntries++; |
|
381 } |
|
382 } |
|
383 } |
|
384 } // end if AddNewEntryTag |
|
385 |
|
386 // one of the fields could not be appended so remove previous fields from the buffer |
|
387 if(ret != KErrNone) |
|
388 { |
|
389 (void)iPbBuffer->RemovePartialEntry(); |
|
390 } |
|
391 CleanupStack::PopAndDestroy(); // parsed buffer |
|
392 } |
|
393 |
|
394 void CATPhoneBookRead::EventSignal(TEventSource aEventSource) |
|
395 /** |
|
396 * State machine. Replaces CATPhoneBookCommands implementation to use second command |
|
397 * state. |
|
398 */ |
|
399 { |
|
400 if ((aEventSource!=ETimeOutCompletion) && (iState==EATPhoneBookCommandWaitForAlternativeReadComplete)) |
|
401 { |
|
402 __ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
403 // may be a entry, OK, or ERROR |
|
404 if (iIo->FoundChatString()==iCPBRResponse) |
|
405 { |
|
406 TRAPD(ret,ParseResponseL()); |
|
407 if (ret!=KErrNone) |
|
408 { |
|
409 Complete(ret,EReadCompletion); |
|
410 return; |
|
411 } |
|
412 // wait for another one |
|
413 iIo->SetTimeOut(this,KPhoneBookReadTimeout*KOneSecondPause); |
|
414 } |
|
415 else |
|
416 { |
|
417 TInt ret(ValidateExpectString()); |
|
418 RemoveStdExpectStrings(); |
|
419 if((ret==KErrNone)&&(iNumReadEntries==0)) |
|
420 { |
|
421 // No entries read, so buffer will be empty and KErrNotFound must be returned. |
|
422 ret=KErrNotFound; |
|
423 } |
|
424 Complete(ret,EReadCompletion); |
|
425 } |
|
426 } |
|
427 else |
|
428 CATPhoneBookCommands::EventSignal(aEventSource); |
|
429 } |
|
430 |
|
431 |
|
432 void CATPhoneBookRead::CompleteWithIOError(TEventSource,TInt aError) |
|
433 /** |
|
434 * This function is called if an error occurs. It cancels the relevant timer and |
|
435 * completes the request. |
|
436 */ |
|
437 { |
|
438 if (iState!=EATPhoneBookCommandIdle) |
|
439 { |
|
440 iIo->WriteAndTimerCancel(this); |
|
441 iCPBRResponse=0; |
|
442 iState=EATPhoneBookCommandIdle; |
|
443 iTelObject->ReqCompleted(iReqHandle,aError); |
|
444 } |
|
445 } |
|
446 |
|
447 |
|
448 // |
|
449 // CATPhoneBookWrite definitions |
|
450 // |
|
451 |
|
452 CATPhoneBookWrite* CATPhoneBookWrite::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
453 /** |
|
454 * Standard 2 phase constructor. |
|
455 * This method creats an instance of the CATPhoneBookWrite class. |
|
456 */ |
|
457 { |
|
458 CATPhoneBookWrite* r=new(ELeave) CATPhoneBookWrite(aIo,aTelObject,aInit,aPhoneGlobals); |
|
459 CleanupStack::PushL(r); |
|
460 r->ConstructL(); |
|
461 CleanupStack::Pop(); |
|
462 return r; |
|
463 } |
|
464 |
|
465 CATPhoneBookWrite::CATPhoneBookWrite(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
466 : CATPhoneBookCommands(aIo,aTelObject,aInit,aPhoneGlobals) |
|
467 /** |
|
468 * C++ constructor |
|
469 */ |
|
470 {} |
|
471 |
|
472 void CATPhoneBookWrite::ConstructL() |
|
473 /** |
|
474 * Standard 2nd phase constructor. |
|
475 * Creates phonebook buffer object used to extract data from client buffer |
|
476 */ |
|
477 { |
|
478 CATCommands::ConstructL(); |
|
479 iPbBuffer = new(ELeave) CPhoneBookBuffer(); |
|
480 } |
|
481 |
|
482 CATPhoneBookWrite::~CATPhoneBookWrite() |
|
483 /** |
|
484 * Destructor. |
|
485 */ |
|
486 { |
|
487 delete iPbBuffer; |
|
488 } |
|
489 |
|
490 void CATPhoneBookWrite::Start(TTsyReqHandle aTsyReqHandle,TAny* aParams) |
|
491 /** |
|
492 * Start function. Its calls the StartStorageSelect() function to select |
|
493 * the phone book memory. |
|
494 */ |
|
495 { |
|
496 iReqHandle=aTsyReqHandle; |
|
497 iIndex = *(static_cast<TInt*>(aParams)); // aParams will contain an index |
|
498 StartStorageSelect(); |
|
499 } |
|
500 |
|
501 void CATPhoneBookWrite::StartThisCommand() |
|
502 /** |
|
503 * This function starts the Write command. It decodes the phonebook data supplied by the |
|
504 * client from the TLV format into the AT+CPBW= format, builds the command and |
|
505 * starts the state machine to write the entry to the phone. It can only write |
|
506 * one entry at a time. |
|
507 */ |
|
508 { |
|
509 LOGTEXT(_L8("Starting AT+CPBW= Command")); |
|
510 |
|
511 TBuf8<KGenericBufferSize> atbuf; // used for 8-bit AT command characters |
|
512 TBuf8<KGenericBufferSize> name; |
|
513 TBuf8<KGenericBufferSize> number; |
|
514 |
|
515 TBuf16<KGenericBufferSize> des16Buf; // used for 16-bit name field |
|
516 TPtrC16 des16Ptr(des16Buf); |
|
517 |
|
518 TUint8 tonNpi(0); |
|
519 |
|
520 TUint8 aTagValue(0); |
|
521 CPhoneBookBuffer::TPhBkTagType aDataType; |
|
522 |
|
523 TInt ret=KErrNone; |
|
524 iPbBuffer->StartRead(); |
|
525 while ((ret=iPbBuffer->GetTagAndType(aTagValue, aDataType))==KErrNone) |
|
526 { |
|
527 if (aTagValue==RMobilePhoneBookStore::ETagPBTonNpi) |
|
528 { |
|
529 (void)iPbBuffer->GetValue(tonNpi); |
|
530 } |
|
531 else if (aTagValue==RMobilePhoneBookStore::ETagPBText) |
|
532 { |
|
533 (void)iPbBuffer->GetValue(des16Ptr); |
|
534 |
|
535 if (des16Ptr.Length() > KGenericBufferSize) |
|
536 { |
|
537 Complete(KErrOverflow, EWriteCompletion); |
|
538 return; |
|
539 } |
|
540 |
|
541 name.Copy(des16Ptr); |
|
542 } |
|
543 else if (aTagValue==RMobilePhoneBookStore::ETagPBNumber) |
|
544 { |
|
545 (void)iPbBuffer->GetValue(des16Ptr); |
|
546 |
|
547 if (des16Ptr.Length() > KGenericBufferSize) |
|
548 { |
|
549 Complete(KErrOverflow, EWriteCompletion); |
|
550 return; |
|
551 } |
|
552 |
|
553 number.Copy(des16Ptr); |
|
554 } |
|
555 else |
|
556 { |
|
557 // An unsupported field type - just skip this value |
|
558 iPbBuffer->SkipValue(aDataType); |
|
559 } |
|
560 } |
|
561 |
|
562 if(ret==KErrNotFound) // This is to ensure the TLV conversion worked |
|
563 { |
|
564 // If the ton is international, but the number doesn't start with a '+' then prepend one. |
|
565 if((tonNpi==145)&&(number.Length()>0)&&(number[0]!='+')) |
|
566 atbuf.Format(KPhoneBookWriteWithIndexPrependedPlus,iIndex,&number,tonNpi,&name); |
|
567 else |
|
568 atbuf.Format(KPhoneBookWriteWithIndex,iIndex,&number,tonNpi,&name); |
|
569 } |
|
570 |
|
571 WriteExpectingResults(atbuf,3); |
|
572 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral)); |
|
573 iState=EATPhoneBookCommandWaitForWriteComplete; |
|
574 } |
|
575 |
|
576 |
|
577 TUint CATPhoneBookWrite::NumberTypefromMMToGSM(TUint aTypeOfNumberMM) |
|
578 /** Maping from MM Number Type To GSM Number Type |
|
579 * This method maps the MM way of representing a type of telefon number |
|
580 * to the GSM standard. |
|
581 */ |
|
582 { |
|
583 switch (aTypeOfNumberMM) |
|
584 { |
|
585 case 0: // EUnknownNumber (MM) |
|
586 return 129; // Nationality unknown (GSM) |
|
587 case 1: // EInternationalNumber (MM) |
|
588 return 145; // International Number (GSM) |
|
589 case 2: // ENationalNumber (MM) |
|
590 return 161; // National Number (GSM) |
|
591 default: |
|
592 return 129; // Nationality unknown (GSM) |
|
593 } |
|
594 } |
|
595 |
|
596 |
|
597 void CATPhoneBookWrite::ParseResponseL() |
|
598 { |
|
599 } |
|
600 |
|
601 |
|
602 // |
|
603 // CATPhoneBookDelete definitions |
|
604 // |
|
605 CATPhoneBookDelete* CATPhoneBookDelete::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
606 /** |
|
607 * Standard 2 phase constructor. |
|
608 * This method creats an instance of the CATPhoneBookDelete class. |
|
609 */ |
|
610 { |
|
611 CATPhoneBookDelete* r=new(ELeave) CATPhoneBookDelete(aIo,aTelObject,aInit,aPhoneGlobals); |
|
612 CleanupStack::PushL(r); |
|
613 r->ConstructL(); |
|
614 CleanupStack::Pop(); |
|
615 return r; |
|
616 } |
|
617 |
|
618 CATPhoneBookDelete::CATPhoneBookDelete(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals) |
|
619 : CATPhoneBookCommands(aIo,aTelObject,aInit,aPhoneGlobals) |
|
620 /** |
|
621 * C++ constructor |
|
622 */ |
|
623 {} |
|
624 |
|
625 CATPhoneBookDelete::~CATPhoneBookDelete() |
|
626 {} |
|
627 |
|
628 void CATPhoneBookDelete::Start(TTsyReqHandle aTsyReqHandle,TAny* aParams) |
|
629 /** |
|
630 * Start function. Its calls the StartStorageSelect() function to select |
|
631 * the phone book memory. |
|
632 */ |
|
633 { |
|
634 iReqHandle=aTsyReqHandle; |
|
635 iIndex=*(TInt*)aParams; |
|
636 |
|
637 StartStorageSelect(); |
|
638 } |
|
639 |
|
640 void CATPhoneBookDelete::StartThisCommand() |
|
641 /** |
|
642 * Start of the Delete command. This function constructs and then sends the Delete |
|
643 * command (the Delete command is the same as the write command with just the index to |
|
644 * delete specified e.g "AT+CPBW=2" command will delete the entry in index location 2). |
|
645 */ |
|
646 { |
|
647 LOGTEXT(_L8("Starting AT+CPBW= Command")); |
|
648 |
|
649 TBuf8<KGenericBufferSize> buf; |
|
650 |
|
651 buf.Format(KPhoneBookDelete,iIndex); |
|
652 WriteExpectingResults(buf,3); |
|
653 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral)); |
|
654 iState=EATPhoneBookCommandWaitForWriteComplete; |
|
655 } |
|
656 |
|
657 void CATPhoneBookDelete::StartAlternativeDelete() |
|
658 /** |
|
659 * Alternative Delete command. The same principles as the normal delete apply. |
|
660 */ |
|
661 { |
|
662 LOGTEXT(_L8("Starting alternative AT+CPBW= Command")); |
|
663 |
|
664 TBuf8<KGenericBufferSize> buf; |
|
665 |
|
666 buf.Format(KPhoneBookAlternativeDelete,iIndex); |
|
667 WriteExpectingResults(buf,3); |
|
668 __ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral)); |
|
669 iState=EATPhoneBookCommandWaitForAlternativeWriteComplete; |
|
670 } |
|
671 |
|
672 |
|
673 void CATPhoneBookDelete::EventSignal(TEventSource aEventSource) |
|
674 /** |
|
675 * State machine for the Delete command. |
|
676 */ |
|
677 { |
|
678 if (iState==EATPhoneBookCommandWaitForReadComplete && |
|
679 aEventSource!=ETimeOutCompletion) |
|
680 { |
|
681 __ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected)); |
|
682 TInt ret(ValidateExpectString()); |
|
683 RemoveStdExpectStrings(); |
|
684 if (ret==KErrGeneral) |
|
685 { |
|
686 StartAlternativeDelete(); |
|
687 return; |
|
688 } |
|
689 if (ret!=KErrNone) |
|
690 { |
|
691 Complete(ret,aEventSource); |
|
692 return; |
|
693 } |
|
694 iIo->SetTimeOut(this,KTimeForExtraRxData); |
|
695 iState=EATPhoneBookCommandExtendedRead; |
|
696 } |
|
697 else |
|
698 CATPhoneBookCommands::EventSignal(aEventSource); |
|
699 } |
|
700 |
|
701 void CATPhoneBookDelete::ParseResponseL() |
|
702 /** |
|
703 * |
|
704 */ |
|
705 { |
|
706 } |
|
707 |
|
708 |