cbsref/telephonyrefplugins/atltsy/atcommand/phonebook/src/atphbkstoreread.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 // Copyright (c) 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 atphbkstoreread.cpp
       
    15 // This contains CAtPhbkStoreRead which is use to read a phonebook Entry
       
    16 // 
       
    17 
       
    18 //system include
       
    19 #include <etelmm.h>
       
    20 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    21 #include <mpbutil.h>
       
    22 #include <cmmgsmphonestorageutility.h>
       
    23 
       
    24 //user include 
       
    25 #include "atphbkstoreread.h"
       
    26 #include "mslogger.h"
       
    27 
       
    28 //constant defination
       
    29 _LIT8(KPhbkStoreRead,"AT+CPBR=%d,%d\r");
       
    30 _LIT8(KSelAdnPhonebook,"AT+CPBS=\"SM\"\r");
       
    31 _LIT8(KSelFdnPhonebook,"AT+CPBS=\"FD\"\r");
       
    32 _LIT8(KCPBRMatchString,"+CPBR:*");
       
    33 _LIT8(KCPBRSResponseString,"+CPBR:");
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CAtPhbkStoreRead::CAtPhbkStoreRead
       
    37 // other items were commented in a header
       
    38 // ---------------------------------------------------------------------------
       
    39 CAtPhbkStoreRead::CAtPhbkStoreRead(CGlobalPhonemanager& aGloblePhone, 
       
    40                                    CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    41                                    :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    42 	{
       
    43 	LOGTEXT(_L8("CAtPhbkStoreRead::CAtPhbkStoreRead called"));
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CAtPhbkStoreRead::~CAtPhbkStoreRead
       
    48 // other items were commented in a header
       
    49 // ---------------------------------------------------------------------------
       
    50 CAtPhbkStoreRead::~CAtPhbkStoreRead()
       
    51 	{
       
    52 	LOGTEXT(_L8("CAtPhbkStoreRead::~CAtPhbkStoreRead called"));
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CAtPhbkStoreRead::NewLC
       
    57 // other items were commented in a header
       
    58 // ---------------------------------------------------------------------------
       
    59 CAtPhbkStoreRead* CAtPhbkStoreRead::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    60                                           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    61 	{
       
    62 	CAtPhbkStoreRead* self = new (ELeave)CAtPhbkStoreRead(aGloblePhone, 
       
    63                                                           aCtsyDispatcherCallback);
       
    64 	CleanupStack::PushL(self);
       
    65 	self->ConstructL();
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CAtPhbkStoreRead::NewL
       
    71 // other items were commented in a header
       
    72 // ---------------------------------------------------------------------------
       
    73 CAtPhbkStoreRead* CAtPhbkStoreRead::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    74                                          CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    75 	{
       
    76 	CAtPhbkStoreRead* self=CAtPhbkStoreRead::NewLC(aGloblePhone, 
       
    77                                                    aCtsyDispatcherCallback);
       
    78 	CleanupStack::Pop(self);
       
    79 	return self;
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CAtPhbkStoreRead::ConstructL
       
    84 // other items were commented in a header
       
    85 // ---------------------------------------------------------------------------
       
    86 void CAtPhbkStoreRead::ConstructL()
       
    87 	{
       
    88 	CAtCommandBase::ConstructL();
       
    89 	AddExpectStringL(KLtsyOkString);
       
    90 	AddExpectStringL(KLtsyErrorString);
       
    91 	AddExpectStringL(KCPBRMatchString);
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CAtPhbkStoreRead::SetPhonebookType
       
    96 // other items were commented in a header
       
    97 // ---------------------------------------------------------------------------
       
    98 void CAtPhbkStoreRead::SetPhonebookType(DispatcherPhonebook::TPhonebook aPhonebookType)
       
    99 	{
       
   100 	iPhoneBookType = aPhonebookType;
       
   101 	}
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CAtPhbkStoreRead::SetReadParam
       
   105 // other items were commented in a header
       
   106 // ---------------------------------------------------------------------------
       
   107 void CAtPhbkStoreRead::SetReadParam(TInt aIndex,TInt aSlotNum)
       
   108 	{
       
   109 	iIndex = aIndex;
       
   110 	iSlotNum = aSlotNum;
       
   111 	}	
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CAtPhbkStoreRead::StartRequest
       
   115 // other items were commented in a header
       
   116 // ---------------------------------------------------------------------------
       
   117 void CAtPhbkStoreRead::StartRequest()
       
   118 	{
       
   119 	ExecuteCommand();
       
   120 	}
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CAtPhbkStoreRead::ExecuteCommand
       
   124 // other items were commented in a header
       
   125 // ---------------------------------------------------------------------------
       
   126 void CAtPhbkStoreRead::ExecuteCommand()
       
   127 	{
       
   128 	LOGTEXT(_L8("CAtPhbkStoreRead::ExecuteCommand called"));
       
   129 	iState = ESetStoreName;
       
   130 	iTxBuffer.Zero();	
       
   131 	if( iPhoneBookType == DispatcherPhonebook::EIccAdn )
       
   132 		{
       
   133 		iTxBuffer.Copy(KSelAdnPhonebook);
       
   134 		}
       
   135 	else if( iPhoneBookType == DispatcherPhonebook::EIccFdn )
       
   136 		{
       
   137 		iTxBuffer.Copy(KSelFdnPhonebook);
       
   138 		}
       
   139 	Write();
       
   140 	}
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CAtPhbkStoreRead::ReadEntry
       
   144 // other items were commented in a header
       
   145 // ---------------------------------------------------------------------------
       
   146 void CAtPhbkStoreRead::ReadEntry()
       
   147 	{
       
   148 	LOGTEXT(_L8("CAtPhbkStoreRead::ReadEntry callded"));
       
   149 	iPhoneGlobals.iEventSignalActive = ETrue;
       
   150 	iTxBuffer.Zero();
       
   151 	iTxBuffer.Format(KPhbkStoreRead,iIndex,iIndex+iSlotNum-1);
       
   152 	Write();
       
   153 	}
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CAtPhbkStoreRead::EventSignal
       
   157 // other items were commented in a header
       
   158 // ---------------------------------------------------------------------------
       
   159 void CAtPhbkStoreRead::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   160 	{
       
   161 	LOGTEXT3(_L8("CAtPhbkStoreRead::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   162 	if(aStatus != KErrNone)
       
   163 		{
       
   164 		Complete();
       
   165 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   166 		iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(aStatus,iPhoneBookType,iPhbkData);
       
   167 		}
       
   168 	else
       
   169 		{
       
   170 		if( aEventSource== EWriteCompletion )
       
   171 			{
       
   172 			if( iState==ESetStoreName )
       
   173 				{
       
   174 				iState = ESetStoreNameComplete;
       
   175 				}
       
   176 			else if( iState==EReadEntry )
       
   177 				{
       
   178 				iState = EReadEntryComplete;
       
   179 				}
       
   180 			}
       
   181 		else 
       
   182 			{
       
   183 			if( iState==ESetStoreNameComplete )
       
   184 				{
       
   185 				Complete();
       
   186 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   187 				if(iError == KErrNone)
       
   188 					{
       
   189 					ClearBuffer();
       
   190 					iState = EReadEntry;
       
   191 					ReadEntry();
       
   192 					}
       
   193 				else 
       
   194 					{
       
   195 					iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData);
       
   196 					}
       
   197 				}
       
   198 			else if( iState==EReadEntryComplete )
       
   199 				{
       
   200 				Complete();
       
   201 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   202 				//encounter OK or ERROR
       
   203 				if( iEndFlag )
       
   204 					{
       
   205 					ClearBuffer();
       
   206 					iPhbkData.Zero();
       
   207 					iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData);
       
   208 					}
       
   209 				else
       
   210 					{
       
   211 					if( iError==KErrNone )
       
   212 						{
       
   213 						TRAPD(err, GeneratePhbkDataL());
       
   214 						iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(err,iPhoneBookType,iPhbkData);
       
   215 						ClearCurrentLine();
       
   216 						}
       
   217 					else
       
   218 						{
       
   219 						iCtsyDispatcherCallback.CallbackPhonebookStoreReadEntryComp(iError,iPhoneBookType,iPhbkData);
       
   220 						}
       
   221 					}
       
   222 				}
       
   223 			}
       
   224 		}
       
   225 	}
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CAtPhbkStoreRead::ParseResponseL
       
   229 // other items were commented in a header
       
   230 // ---------------------------------------------------------------------------
       
   231 void CAtPhbkStoreRead::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   232 	{
       
   233 	if( iState == ESetStoreNameComplete )
       
   234 	    {
       
   235 		if (CurrentLine().Match(KLtsyOkString) == 0)
       
   236 			{
       
   237 			iError = KErrNone;
       
   238 			}
       
   239 		else
       
   240 			{
       
   241 			iError = KErrGeneral;
       
   242 			}
       
   243 	    }
       
   244 	else if( iState == EReadEntryComplete )
       
   245 		{
       
   246 		/**
       
   247 		* +CPBR = <index>,<number>,<129/145>,<text> 
       
   248 		* OK    
       
   249 		*/
       
   250 		RArray<TPtrC8> array;
       
   251 		CleanupClosePushL(array);
       
   252 		iParser->ParseRespondedBuffer(array,Buffer());
       
   253 		// remove the string of AT+CPBR=..
       
   254 		if(array[0].MatchF(KAnyATCommand) != KErrNotFound)
       
   255 			{
       
   256 			array.Remove(0);
       
   257 			}
       
   258 		TInt count = array.Count();
       
   259 #ifdef _DEBUG		
       
   260 		for( TInt i=0;i<count;i++ )
       
   261 			{
       
   262 			LOGTEXT3(_L8("CAtPhbkStoreRead::ParseResponseL\tarray[%d]=%S"),i,&array[i]); 
       
   263 			}
       
   264 #endif		
       
   265 		if((array[1].Match(KLtsyOkString) == KErrNone))
       
   266 			{
       
   267 			CleanupStack::PopAndDestroy();
       
   268 			iError = KErrNone;
       
   269 			iEndFlag = ETrue;
       
   270 			return; 
       
   271 			}
       
   272 		else if((array[1].Match(KLtsyErrorString) == KErrNone))
       
   273 			{
       
   274 			CleanupStack::PopAndDestroy();
       
   275 			iError = KErrGeneral;
       
   276 			iEndFlag = ETrue;
       
   277 			return; 
       
   278 			}
       
   279 	  
       
   280 		iError = KErrNone;
       
   281 		//remove number line if it has 
       
   282 		if( array[0].MatchF(KCPBRSResponseString) == KErrNotFound )
       
   283 			{
       
   284 			array.Remove(0);
       
   285 			}
       
   286 		if( array[0].MatchF(KCPBRSResponseString) == KErrNotFound )
       
   287 			{
       
   288 			CleanupStack::PopAndDestroy();
       
   289 			iError = KErrNotFound;
       
   290 			return;
       
   291 			}
       
   292 		//parse index
       
   293 		TLex8 lex(array[1]);
       
   294 		TUint16 val;
       
   295 		TInt ret = lex.Val(val,EDecimal);
       
   296 		if(ret != KErrNone)
       
   297 			{
       
   298 			CleanupStack::PopAndDestroy();
       
   299 			iError = ret;
       
   300 			return;
       
   301 			}
       
   302 		//Index  
       
   303 		iReadEntry.iIndex = val;             
       
   304 		iReadEntry.iNumber.Copy(array[2]);   
       
   305 		//Parse TON/NPI
       
   306 		TLex8 lex1(array[3]);
       
   307 		TUint16 val1;
       
   308 		ret = lex1.Val(val1,EDecimal);
       
   309 		if(ret != KErrNone)
       
   310 			{
       
   311 			CleanupStack::PopAndDestroy();
       
   312 			iError = ret;
       
   313 			return;
       
   314 			}
       
   315 		 //TON/NPI
       
   316 		iReadEntry.iTon = (TUint8)val1;  
       
   317 		iReadEntry.iText.Copy(array[4]);
       
   318 		CleanupStack::PopAndDestroy();
       
   319 		} 
       
   320   	}
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CAtPhbkStoreRead::GeneratePhbkData
       
   324 // other items were commented in a header
       
   325 // ---------------------------------------------------------------------------
       
   326 TInt CAtPhbkStoreRead::GeneratePhbkDataL()
       
   327 	{
       
   328 	CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer(); // used to write phonebook data
       
   329 	iPhbkData.Zero();
       
   330 	pbBuffer->Set(&iPhbkData); // Set it to point to the Client buffer
       
   331 	pbBuffer->AddNewEntryTag();
       
   332 	
       
   333 	TInt ret = pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBAdnIndex,iReadEntry.iIndex);
       
   334 	if( ret!=KErrNone )
       
   335 		{
       
   336 		delete pbBuffer;
       
   337 		return ret;
       
   338 		}
       
   339 	ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBNumber, iReadEntry.iNumber);
       
   340 	if( ret!=KErrNone )
       
   341 		{
       
   342 		delete pbBuffer;
       
   343 		return ret;
       
   344 		}
       
   345 	ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBTonNpi, iReadEntry.iTon);
       
   346 	if(ret!=KErrNone)
       
   347 		{
       
   348 		delete pbBuffer;
       
   349 		return ret;
       
   350 		}
       
   351 	ret=pbBuffer->PutTagAndValue(RMobilePhoneBookStore::ETagPBText, iReadEntry.iText);
       
   352 	if(ret != KErrNone)
       
   353 		{
       
   354 		delete pbBuffer;
       
   355 		return ret;
       
   356 		}
       
   357 	
       
   358 	delete pbBuffer;
       
   359 	return KErrNone;
       
   360 	}
       
   361 
       
   362 //End of file