telephonyserverplugins/multimodetsy/Multimode/Mphbkinf.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // \file MPHBKINF.CPP
       
    15 // Multimode TSY Phone book Implementation file.
       
    16 // This file contains the implementation of the CATPhoneBookInfo class, which is used
       
    17 // to obtain Phone book information. 
       
    18 // This class does all three AT+CPBS commands and an AT+CPBR:
       
    19 // AT+CPBS=? to get the supported storage types;
       
    20 // AT+CPBS=<storage> to set the storage type;
       
    21 // AT+CPBS? to get the 'used' and 'total' slots;
       
    22 // AT+CPBR=? to get the maximum length of the number and text fields;
       
    23 // A TPhoneBookInfo struct containing all the relevant information about the 
       
    24 // specified phone book is returned.
       
    25 // 
       
    26 //
       
    27 
       
    28 
       
    29 #include "Mphbkcom.h"
       
    30 #include "mSLOGGER.H"
       
    31 #include "mPHBOOK.H"
       
    32 #include "ATIO.H"
       
    33 #include "Matstd.h"
       
    34 #include "mphbkinf.h"
       
    35 
       
    36 
       
    37 // AT command
       
    38 _LIT8(KPhoneBookReadTest,"AT+CPBR=?");
       
    39 
       
    40 //
       
    41 const TUint KHyphenChar='-';
       
    42 
       
    43 //
       
    44 GLDEF_C void ConvertStorageTypeToName(const TStorageType& aStorageType,TDes& aName)
       
    45 /**
       
    46  * This function converts a storage type (phone book memory) to its name equivalent.
       
    47  */
       
    48 	{
       
    49 	if (aStorageType==KFDStorage)
       
    50 		aName.Copy(KETelIccFdnPhoneBook);
       
    51 	else if (aStorageType==KMEStorage)
       
    52 		aName.Copy(KETelMeAdnPhoneBook);
       
    53 	else if (aStorageType==KMTStorage)
       
    54 		aName.Copy(KETelCombinedAdnPhoneBook);
       
    55 	else if (aStorageType==KSMStorage)
       
    56 		aName.Copy(KETelIccAdnPhoneBook);
       
    57 	else if (aStorageType==KTAStorage)
       
    58 		aName.Copy(KETelTaAdnPhoneBook);
       
    59 	else if (aStorageType==KBMStorage)
       
    60 		aName.Copy(KETelIccBdnPhoneBook);
       
    61 	else if (aStorageType==KDCStorage)
       
    62 		aName.Copy(KETelMeDialledPhoneBook);
       
    63 	else if (aStorageType==KENStorage)
       
    64 		aName.Copy(KETelEmergencyNumberStore);
       
    65 	else if (aStorageType==KMCStorage)
       
    66 		aName.Copy(KETelMeMissedPhoneBook);
       
    67 	else if (aStorageType==KRCStorage)
       
    68 		aName.Copy(KETelMeReceivedPhoneBook);
       
    69 	else if (aStorageType==KLDStorage)
       
    70 		aName.Copy(KETelIccLndPhoneBook);
       
    71 	else if (aStorageType==KONStorage)
       
    72 		aName.Copy(KETelOwnNumberStore);
       
    73 	else if (aStorageType==KSNStorage)
       
    74 		aName.Copy(KETelIccSdnPhoneBook);
       
    75 	else
       
    76 		// we don't know any other storage type
       
    77 		aName.SetLength(0);
       
    78 	}
       
    79 
       
    80 //
       
    81 // CATPhoneBookInfo Implementation
       
    82 //
       
    83 
       
    84 CATPhoneBookInfo* CATPhoneBookInfo::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
    85 /**
       
    86  * Standard 2 phase constructor. 
       
    87  */
       
    88 	{
       
    89 	CATPhoneBookInfo* r=new(ELeave) CATPhoneBookInfo(aIo,aTelObject,aInit,aPhoneGlobals);
       
    90 	CleanupStack::PushL(r);
       
    91 	r->ConstructL();
       
    92 	CleanupStack::Pop();
       
    93 	return r;
       
    94 	}
       
    95 
       
    96 CATPhoneBookInfo::CATPhoneBookInfo(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aPhoneGlobals)
       
    97 	: CATCommands(aIo,aTelObject,aInit,aPhoneGlobals), iCompleted(EFalse)
       
    98 	{
       
    99 	}
       
   100 
       
   101 CATPhoneBookInfo::~CATPhoneBookInfo()
       
   102 /**
       
   103  * Destructor.
       
   104  */
       
   105 	{
       
   106 	delete iStorageTypeArray;
       
   107 	}
       
   108 
       
   109 void CATPhoneBookInfo::ConstructL()
       
   110 /**
       
   111  * This function calls the ConstructL() function of the CATCommands class. 
       
   112  * It also allocates memory for an array of supported phonebook types.
       
   113  */
       
   114 	{
       
   115 	CATCommands::ConstructL();
       
   116 	iStorageTypeArray=new(ELeave) CArrayFixFlat<TStorageType>(5);
       
   117 	}	
       
   118 
       
   119 void CATPhoneBookInfo::Start(TTsyReqHandle aTsyReqHandle,TAny* aParams)
       
   120 /** 
       
   121  * Start function; initializes TPhoneBookInfo struct members to Unknown
       
   122  * and starts the AT+CPBS? query command.
       
   123  */
       
   124 	{
       
   125 	LOGTEXT(_L8("Starting AT+CPBS? Command"));
       
   126 	
       
   127 	iReqHandle=aTsyReqHandle;
       
   128 
       
   129 	if (aParams)
       
   130 		iInfoPckg=static_cast<RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg*>(aParams);
       
   131 
       
   132 // if this is the first time then get a list of the supported types, otherwise, just
       
   133 // get info for the required index
       
   134 
       
   135 	if (iStorageTypeArray->Count()>0)
       
   136 		{
       
   137 		SetIndexByStorageType();
       
   138 		StartSelect();
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		WriteExpectingResults(KPhoneBookStorageTest(),3);
       
   143 		__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   144 		iState=EListWaitForWriteComplete;
       
   145 		}
       
   146 	}
       
   147 
       
   148 void CATPhoneBookInfo::EventSignal(TEventSource aEventSource)
       
   149 /** 
       
   150  * This function contains the State machine for retrieving phone book information.
       
   151  *
       
   152  * Waits for the AT+CPBS=? command to be written to the comm port, parses the phone's
       
   153  * response and initializes an array containing the supported phone book memories. It
       
   154  * then sets a phonebook type, and retrieves information pertaining to the phone book:
       
   155  * total no. of slots, no. of used slots, the maximum length of the text and number fields.
       
   156  */
       
   157 	{
       
   158 	LOGTEXT2(_L8("CATPhoneBookInfo::EventSignal, aEventSource=%d"),aEventSource);
       
   159 
       
   160 	if (aEventSource==ETimeOutCompletion)
       
   161 		{
       
   162 		LOGTEXT(_L8("Timeout Error during getting phone book info"));
       
   163 		RemoveStdExpectStrings();
       
   164 		Complete(KErrTimedOut,aEventSource);
       
   165 		return;
       
   166 		}
       
   167 	
       
   168 	switch (iState)
       
   169 		{
       
   170 	case EListWaitForWriteComplete:
       
   171 		WriteComplete(aEventSource,EListWaitForReadComplete);
       
   172 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EListWaitForWriteComplete"));
       
   173 		break;
       
   174 
       
   175 	case EListWaitForReadComplete:
       
   176 		__ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   177 			{
       
   178 			TInt ret(ValidateExpectString());
       
   179 			RemoveStdExpectStrings();
       
   180 			if (ret!=KErrNone)
       
   181 				{
       
   182 				Complete(ret,aEventSource);
       
   183 				return;
       
   184 				}
       
   185 			TRAP(ret,ParseListResponseL()); // parse the list of supported phone book types.
       
   186 			if (ret!=KErrNone)
       
   187 				{
       
   188 				Complete(ret,aEventSource);
       
   189 				return;
       
   190 				}
       
   191 			}
       
   192 		SetIndexByStorageType();		
       
   193 		StartSelect();	// Set a phone book memory.
       
   194 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EListWaitForReadComplete"));
       
   195 		break; 
       
   196 		
       
   197 	case ESelectWaitForWriteComplete:
       
   198 		WriteComplete(aEventSource,ESelectWaitForReadComplete);
       
   199 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed ESelectWaitForWriteComplete"));
       
   200 		break;
       
   201 
       
   202 	case ESelectWaitForReadComplete:
       
   203 		__ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   204 			{
       
   205 			TInt ret(ValidateExpectString());
       
   206 			RemoveStdExpectStrings();
       
   207 			if (ret!=KErrNone)
       
   208 				{
       
   209 				Complete(ret,aEventSource);
       
   210 				return;
       
   211 				}
       
   212 			// no parsing this time
       
   213 			} 
       
   214 		iPhoneGlobals->iPhoneStatus.iLastAccessedPhoneBook=iStorageType;
       
   215 		StartGetInfo();	// Transmit AT+CPBS? cmd; get the phone book's total and used slots
       
   216 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed ESelectWaitForReadComplete"));
       
   217 		break;
       
   218 
       
   219 	case EGetInfoWaitForWriteComplete:
       
   220 		WriteComplete(aEventSource,EGetInfoWaitForReadComplete);
       
   221 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EGetInfoWaitForWriteComplete"));
       
   222 		break;
       
   223 
       
   224 	case EGetInfoWaitForReadComplete:
       
   225 		__ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   226 			{
       
   227 			TInt ret(ValidateExpectString());
       
   228 			RemoveStdExpectStrings();
       
   229 			if (ret!=KErrNone)
       
   230 				{
       
   231 				Complete(ret,aEventSource);
       
   232 				return;
       
   233 				}
       
   234 			TRAP(ret,ParseGetInfoResponseL());	// Parse the phone's response to the AT+CPBS? command
       
   235 			if (ret!=KErrNone)
       
   236 				{
       
   237 				Complete(ret,aEventSource);
       
   238 				return;
       
   239 				}
       
   240 			}
       
   241 		StartGetMaxLength();  // Transmit AT+CPBR=? cmd; get the maximum text and number length.
       
   242 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EGetInfoWaitForReadComplete"));
       
   243 		break;
       
   244 
       
   245 	case EGetMaxLengthWaitForWriteComplete:
       
   246 		WriteComplete(aEventSource,EGetMaxLengthWaitForReadComplete);
       
   247 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EGetMaxLengthWaitForWriteComplete"));
       
   248 		break;
       
   249 
       
   250 	case EGetMaxLengthWaitForReadComplete:
       
   251 		__ASSERT_ALWAYS(aEventSource==EReadCompletion,Panic(EATCommand_IllegalCompletionReadExpected));
       
   252 			{
       
   253 			TInt ret(ValidateExpectString());
       
   254 			RemoveStdExpectStrings();
       
   255 			if (ret!=KErrNone)
       
   256 				{
       
   257 				Complete(ret,aEventSource);
       
   258 				return;
       
   259 				}
       
   260 			TRAP(ret,ParseGetMaxLengthResponseL()); // Parse the phone's response to the AT+CPBR=? command.
       
   261 			Complete(ret,aEventSource);
       
   262 			}
       
   263 		LOGTEXT(_L8("CATPhoneBookInfo::EventSignal processed EGetMaxLengthWaitForReadComplete"));
       
   264 		break;
       
   265 			
       
   266 	case EIdle:
       
   267 	default:
       
   268 		break;
       
   269 		}
       
   270 	}
       
   271 	
       
   272 void CATPhoneBookInfo::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
   273 /**
       
   274  * This function is called if an error occurs. It cancels the relevant timer and 
       
   275  * completes the request before setting the state to Idle.
       
   276  */
       
   277 	{
       
   278 	if (iState!=EIdle)
       
   279 		{
       
   280 		iIo->WriteAndTimerCancel(this);
       
   281 		if (iReqHandle) 
       
   282 			{
       
   283 			iTelObject->ReqCompleted(iReqHandle,aStatus);
       
   284 			}
       
   285 		iState=EIdle;
       
   286 		}
       
   287 	}
       
   288 
       
   289 void CATPhoneBookInfo::SetStorageType(TStorageType aStorageType)
       
   290 /**
       
   291  * Sets the client's desired phonebook type. 
       
   292  */
       
   293 	{
       
   294 	iStorageType=aStorageType;
       
   295 	}
       
   296 
       
   297 void CATPhoneBookInfo::SetIndexByStorageType()
       
   298 /**
       
   299  * Sets the client index using the storage type supplied by the client 
       
   300  */
       
   301 	{
       
   302 	iIndex=KErrUnknown;
       
   303 	for (TInt i=0; i<iStorageTypeArray->Count(); i++)
       
   304 		{
       
   305 		if ((*iStorageTypeArray)[i] == iStorageType)
       
   306 			{
       
   307 			iIndex=i;
       
   308 			return;
       
   309 			}
       
   310 		}
       
   311 	}
       
   312 
       
   313 void CATPhoneBookInfo::Stop(TTsyReqHandle aTsyReqHandle)
       
   314 /**
       
   315  * This function is used to prematurely stop the state machine.  This would usually 
       
   316  * occur following a client cancel request.
       
   317  */
       
   318 	{
       
   319 	__ASSERT_ALWAYS(aTsyReqHandle == iReqHandle,Panic(EIllegalTsyReqHandle));
       
   320 	LOGTEXT(_L8("Cancelling phone book get info command"));
       
   321 
       
   322 	switch (iState)
       
   323 		{
       
   324 	case EListWaitForWriteComplete:
       
   325 	case ESelectWaitForWriteComplete:
       
   326 	case EGetInfoWaitForWriteComplete:
       
   327 	case EGetMaxLengthWaitForWriteComplete:
       
   328 		Complete(KErrCancel,EWriteCompletion);
       
   329 		return;
       
   330 	
       
   331 	case EListWaitForReadComplete:
       
   332 	case ESelectWaitForReadComplete:
       
   333 	case EGetInfoWaitForReadComplete:
       
   334 	case EGetMaxLengthWaitForReadComplete:
       
   335 		Complete(KErrCancel,EReadCompletion);
       
   336 		return;
       
   337 
       
   338 	case EIdle:
       
   339 	default:
       
   340 		return;
       
   341 		}
       
   342 	}
       
   343 
       
   344 
       
   345 void CATPhoneBookInfo::StartSelect()
       
   346 /** 
       
   347  * This function selects a phonebook memory.
       
   348  */
       
   349 	{
       
   350 	TBuf8<KGenericBufferSize> buf;
       
   351 	
       
   352 	if (iPhoneGlobals->iPhoneStatus.iLastAccessedPhoneBook!=iStorageType)
       
   353 		{
       
   354 		// We need to select the phonebook using AT+CPBS=<storage>
       
   355 		if (iIndex>=0)
       
   356 			buf.Format(KPhoneBookStorageSet,&(*iStorageTypeArray)[iIndex]);
       
   357 		else
       
   358 			Panic(EUnknownPhoneBookStorageTypeIndex);
       
   359 
       
   360 		WriteExpectingResults(buf,3);
       
   361 		__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   362 		iState=ESelectWaitForWriteComplete;
       
   363 		}
       
   364 	else
       
   365 		// We already have correct phonebook selected
       
   366 		StartGetInfo();
       
   367 	}
       
   368 
       
   369 void CATPhoneBookInfo::StartGetInfo()
       
   370 /**
       
   371  * This function transmits an AT+CPBS? command. 
       
   372  */
       
   373 	{
       
   374 	WriteExpectingResults(KPhoneBookStorageRead(),3);
       
   375 	
       
   376 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   377 	iState=EGetInfoWaitForWriteComplete;
       
   378 	}
       
   379 
       
   380 void CATPhoneBookInfo::StartGetMaxLength()
       
   381 /** 
       
   382  * This function transmits an AT+CPBR=? command.
       
   383  */
       
   384 	{	
       
   385 	WriteExpectingResults(KPhoneBookReadTest(),3);
       
   386 	__ASSERT_ALWAYS(iIo->AddExpectString(this,KNotifyMeIfErrorString) != NULL, Panic(EGeneral));
       
   387 	iState=EGetMaxLengthWaitForWriteComplete;
       
   388 	}
       
   389 
       
   390 void CATPhoneBookInfo::ParseListResponseL()
       
   391 /**
       
   392  * This function parses the phone's response to the AT+CPBS=? command.
       
   393  * It initializes an array with the supported phone book types.
       
   394  */
       
   395 	{
       
   396 	TInt count=iStorageTypeArray->Count();
       
   397 	if (count>0)
       
   398 		iStorageTypeArray->Delete(0,count);
       
   399 
       
   400 	ParseBufferLC(EFalse, ':');
       
   401 	if (iRxResults.IsEmpty())
       
   402 		User::Leave(KErrNotFound);
       
   403 	else
       
   404 		{
       
   405 		TDblQueIter<CATParamListEntry> iter(iRxResults);
       
   406 		CATParamListEntry* entry=iter++;
       
   407 		if (entry!=NULL)
       
   408 			{
       
   409 			entry->Deque();			// skip the +CPBS
       
   410 			delete entry;
       
   411 			}
       
   412 		else
       
   413 			User::Leave(KErrNotFound);
       
   414 		
       
   415 		entry=iter++;
       
   416 		TStorageType storageType;
       
   417 		while (entry!=NULL)
       
   418 			{
       
   419 			if (entry->iResultPtr.Length()>2)
       
   420 				User::Leave(KErrArgument);
       
   421 			storageType=entry->iResultPtr;
       
   422 			iStorageTypeArray->AppendL(storageType);
       
   423 			entry->Deque();
       
   424 			delete entry;
       
   425 			entry=iter++;
       
   426 			}
       
   427 		}
       
   428 	CleanupStack::PopAndDestroy();		// parsed buffer
       
   429 	}
       
   430 
       
   431 void CATPhoneBookInfo::ParseGetInfoResponseL()
       
   432 /** 
       
   433  * This function parses the phone's response to the AT+CPBS? command.
       
   434  * The variables containing the used and total slots are assigned the
       
   435  * corresponding values returned by the phone.
       
   436  */
       
   437 	{
       
   438 	ParseBufferLC(EFalse, ':');
       
   439 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
   440 	CATParamListEntry* entry=iter++;	
       
   441 	if (entry!=NULL)
       
   442 		{
       
   443 		entry->Deque();			// skip the +CPBS
       
   444 		delete entry;
       
   445 		}
       
   446 	else
       
   447 		User::Leave(KErrNotFound);
       
   448 
       
   449 	entry=iter++;
       
   450 	if (entry!=NULL)
       
   451 		{
       
   452 		entry->Deque();			// skip the storage name
       
   453 		delete entry;
       
   454 		}
       
   455 	else
       
   456 		User::Leave(KErrNotFound);
       
   457 	
       
   458 	entry=iter++;
       
   459 	if (entry!=NULL)
       
   460 		{
       
   461 		CATParamListEntry::EntryValL(entry,iPhbkInfo.iUsedEntries);
       
   462 		entry=iter++;
       
   463 		}
       
   464 
       
   465 	if (entry!=NULL)
       
   466 		{
       
   467 		CATParamListEntry::EntryValL(entry,iPhbkInfo.iTotalEntries);
       
   468 		}
       
   469 
       
   470 	CleanupStack::PopAndDestroy();		// parsed buffer
       
   471 	}
       
   472 
       
   473 void CATPhoneBookInfo::ParseGetMaxLengthResponseL()
       
   474 /** 
       
   475  * This function parses the phone's response to the AT+CPBR=? command -> e.g. 
       
   476  * +CPBR: (101-200),020,014 or +CPBR: (1-10),32,14.
       
   477  * The variables containing the maximum text and number lengths are assigned 
       
   478  * the corresponding values returned by the phone.
       
   479  */
       
   480 	{
       
   481 	ParseBufferLC(EFalse, ':');
       
   482 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
   483 	CATParamListEntry* entry=iter++;	
       
   484 	if (entry==NULL)
       
   485 		User::Leave(KErrNotFound);
       
   486 	
       
   487 	// skip the +CPBR
       
   488 	entry=iter++;
       
   489 
       
   490 	// T28 returns CPBR:(),20,8. () should be tackled correctly.
       
   491 	if (entry->iResultPtr.Locate(KHyphenChar)==KErrNotFound)
       
   492 		entry=iter++;
       
   493 	else
       
   494 		{
       
   495 		while (entry!=NULL && entry->iResultPtr.Locate(KHyphenChar)>KErrNone)
       
   496 			{
       
   497 			const TInt hyphenPos=entry->iResultPtr.Locate(KHyphenChar);
       
   498 			TPtrC8 beforeHyphen=entry->iResultPtr.Left(hyphenPos);
       
   499 			TPtrC8 afterHyphen=entry->iResultPtr.Mid(hyphenPos+1);
       
   500 
       
   501 			// Get the index offset that'll need to be used for
       
   502 			// read, write and delete phone book store operations
       
   503 			{		// curly brackets used to scope TLex8 object
       
   504 			TLex8 lex(beforeHyphen);
       
   505 			(void)User::LeaveIfError(lex.Val(iIndexOffset));
       
   506 			}
       
   507 			iIndexOffset--;		// decrement offset by one as it is an offset and not a starting index value
       
   508 
       
   509 			LOGTEXT2(_L8("CATPhoneBookInfo::ParseGetMaxLengthResponseL iIndexOffset=%d"),iIndexOffset);
       
   510 
       
   511 			if (iPhbkInfo.iTotalEntries<=0)
       
   512 				{	
       
   513 				// The optional <used> and <total> parameters were not present in AT+CPBS=?
       
   514 				// Try to get this info from AT+CPBR? instead
       
   515 				TLex8 lex(afterHyphen);
       
   516 				(void)User::LeaveIfError(lex.Val(iPhbkInfo.iTotalEntries));
       
   517 				}
       
   518 			entry=iter++;
       
   519 			}
       
   520 		}
       
   521 	
       
   522 	if (entry!=NULL)
       
   523 		{
       
   524 		CATParamListEntry::EntryValL(entry,iPhbkInfo.iMaxNumLength);
       
   525 		entry=iter++;
       
   526 		}
       
   527 	else
       
   528 		// not supported by this ME
       
   529 		iPhbkInfo.iMaxNumLength=KErrNotFound;
       
   530 
       
   531 	if (entry!=NULL)
       
   532 		CATParamListEntry::EntryValL(entry,iPhbkInfo.iMaxTextLength);
       
   533 	else
       
   534 		// not supported by this ME
       
   535 		iPhbkInfo.iMaxTextLength=KErrNotFound;
       
   536 
       
   537 	CleanupStack::PopAndDestroy();		// parsed buffer
       
   538 	}
       
   539 
       
   540 void CATPhoneBookInfo::WriteComplete(TEventSource aSource,TPhoneBookInfoState aState)
       
   541 /**
       
   542  * This function is used by the Write states in the State machine. Performs common
       
   543  * write routines and sets the new state.
       
   544  */
       
   545 	{
       
   546 	__ASSERT_ALWAYS(aSource==EWriteCompletion,Panic(EATCommand_IllegalCompletionWriteExpected));
       
   547 	AddStdExpectStrings();
       
   548 	iIo->SetTimeOut(this);
       
   549 	iState=aState;	
       
   550 	}
       
   551 
       
   552 void CATPhoneBookInfo::Complete(TInt aError, TEventSource aSource)
       
   553 /** 
       
   554  * This function completes the Client request.
       
   555  * It sets the Write Access for the phone book and sets the state to Idle.
       
   556  */
       
   557 	{
       
   558 	LOGTEXT2(_L8("CATPhoneBookInfo::Complete aError=%d"),aError);
       
   559 	
       
   560 	if (aError==KErrNone)
       
   561 		{
       
   562 		iPhbkInfo.iCaps = RMobilePhoneStore::KCapsReadAccess; 
       
   563 		if (CPhoneGlobals::IsWriteAccess(iStorageType))
       
   564 			iPhbkInfo.iCaps |= RMobilePhoneStore::KCapsWriteAccess;
       
   565 
       
   566 		ConvertStorageTypeToName(iStorageType, iPhbkInfo.iName);
       
   567 
       
   568 		iIo->WriteAndTimerCancel(this);
       
   569 		iIo->RemoveExpectStrings(this);
       
   570 
       
   571 		iState=EIdle;
       
   572 		// Mark the information retrieval as completed - so it is not repeated
       
   573 		iCompleted=ETrue;
       
   574 
       
   575 		// Write back data if started by a client request
       
   576 		if (iReqHandle)
       
   577 			{
       
   578 			// Check if client was actually asking for RMobilePhoneStore::TMobilePhoneStoreInfoV1
       
   579 			// rather than larger RMobilePhonebookStore::TMobilePhoneBookInfoV1
       
   580 
       
   581 			RMobilePhoneStore::TMobilePhoneStoreInfoV1& storeInfo = (*iInfoPckg)();
       
   582 
       
   583 			storeInfo.iType=RMobilePhoneStore::EPhoneBookStore;
       
   584 			storeInfo.iUsedEntries=iPhbkInfo.iUsedEntries;
       
   585 			storeInfo.iTotalEntries=iPhbkInfo.iTotalEntries;
       
   586 			storeInfo.iName=iPhbkInfo.iName;
       
   587 			storeInfo.iCaps=iPhbkInfo.iCaps;
       
   588 
       
   589 			if (storeInfo.ExtensionId()==RMobilePhoneStore::KETelMobilePhonebookStoreV1)
       
   590 				{
       
   591 				RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg* phbkPckg 
       
   592 					= reinterpret_cast<RMobilePhoneBookStore::TMobilePhoneBookInfoV1Pckg*>(iInfoPckg);
       
   593 				RMobilePhoneBookStore::TMobilePhoneBookInfoV1& phbkInfo = (*phbkPckg)();
       
   594 				phbkInfo.iMaxNumLength=iPhbkInfo.iMaxNumLength;
       
   595 				phbkInfo.iMaxTextLength=iPhbkInfo.iMaxTextLength;
       
   596 				phbkInfo.iLocation=RMobilePhoneBookStore::ELocationUnknown; // could change this later!
       
   597 				}
       
   598 		
       
   599 			CATCommands::Complete(aError,aSource);
       
   600 			iTelObject->ReqCompleted(iReqHandle,aError);
       
   601 			}
       
   602 		}
       
   603 	else
       
   604 		{
       
   605 		// There was an error or the request was cancelled
       
   606 		iIo->WriteAndTimerCancel(this);
       
   607 		iIo->RemoveExpectStrings(this);
       
   608 		iState=EIdle;
       
   609 
       
   610 		CATCommands::Complete(aError,aSource);
       
   611 		if (iReqHandle)
       
   612 			iTelObject->ReqCompleted(iReqHandle,aError);
       
   613 		}
       
   614 	}