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