cbsref/telephonyrefplugins/atltsy/atcommand/phonebooken/src/atphbkenreadall.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 atphbkenreadall.cpp
       
    15 // This contains CAtPhbkEnReadAll which is used to read all PhonebookEn 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 "atphbkenreadall.h"
       
    26 #include "mslogger.h"
       
    27 
       
    28 //constant defination
       
    29 _LIT8(KPhbkStoreRead,"AT+CPBR=%d,%d\r");
       
    30 _LIT8(KSelPhonebookEn,"AT+CPBS=\"EN\"\r");
       
    31 _LIT8(KCPBRMatchString,"+CPBR:*");
       
    32 _LIT8(KCPBRSResponseString,"+CPBR:");
       
    33 const TInt KEnStartIndex = 1;
       
    34 const TInt KEnEndIndex = 16;
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CAtPhbkEnReadAll::CAtPhbkEnReadAll
       
    38 // other items were commented in a header
       
    39 // ---------------------------------------------------------------------------
       
    40 CAtPhbkEnReadAll::CAtPhbkEnReadAll(CGlobalPhonemanager& aGloblePhone, 
       
    41                                    CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    42                                    :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    43 	{
       
    44 	LOGTEXT(_L8("CAtPhbkEnReadAll::CAtPhbkEnReadAll called"));
       
    45 	iEndFlag = EFalse;
       
    46 	}
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CAtPhbkEnReadAll::~CAtPhbkEnReadAll
       
    50 // other items were commented in a header
       
    51 // ---------------------------------------------------------------------------
       
    52 CAtPhbkEnReadAll::~CAtPhbkEnReadAll()
       
    53 	{
       
    54 	LOGTEXT(_L8("CAtPhbkEnReadAll::~CAtPhbkEnReadAll called"));
       
    55 	}
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CAtPhbkEnReadAll::NewLC
       
    59 // other items were commented in a header
       
    60 // ---------------------------------------------------------------------------
       
    61 CAtPhbkEnReadAll* CAtPhbkEnReadAll::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    62                                           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    63 	{
       
    64 	CAtPhbkEnReadAll* self = new (ELeave)CAtPhbkEnReadAll(aGloblePhone, 
       
    65                                                           aCtsyDispatcherCallback);
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL();
       
    68 	return self;
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CAtPhbkEnReadAll::NewL
       
    73 // other items were commented in a header
       
    74 // ---------------------------------------------------------------------------
       
    75 CAtPhbkEnReadAll* CAtPhbkEnReadAll::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    76                                          CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    77 	{
       
    78 	CAtPhbkEnReadAll* self=CAtPhbkEnReadAll::NewLC(aGloblePhone, 
       
    79                                                    aCtsyDispatcherCallback);
       
    80 	CleanupStack::Pop(self);
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAtPhbkEnReadAll::ConstructL
       
    86 // other items were commented in a header
       
    87 // ---------------------------------------------------------------------------
       
    88 void CAtPhbkEnReadAll::ConstructL()
       
    89 	{
       
    90 	CAtCommandBase::ConstructL();
       
    91 	AddExpectStringL(KLtsyOkString);
       
    92 	AddExpectStringL(KLtsyErrorString);
       
    93 	AddExpectStringL(KCPBRMatchString);
       
    94 	}
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CAtPhbkEnReadAll::StartRequest
       
    98 // other items were commented in a header
       
    99 // ---------------------------------------------------------------------------
       
   100 void CAtPhbkEnReadAll::StartRequest()
       
   101 	{
       
   102 	ExecuteCommand();
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CAtPhbkEnReadAll::ExecuteCommand
       
   107 // other items were commented in a header
       
   108 // ---------------------------------------------------------------------------
       
   109 void CAtPhbkEnReadAll::ExecuteCommand()
       
   110 	{
       
   111 	LOGTEXT(_L8("CAtPhbkEnReadAll::ExecuteCommand called"));
       
   112 	iState = ESetEnName;
       
   113 	iTxBuffer.Zero();	
       
   114 	iTxBuffer.Copy(KSelPhonebookEn);
       
   115 	Write();
       
   116 	}
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CAtPhbkEnReadAll::ReadEntry
       
   120 // other items were commented in a header
       
   121 // ---------------------------------------------------------------------------
       
   122 void CAtPhbkEnReadAll::ReadEntry()
       
   123 	{
       
   124 	LOGTEXT(_L8("CAtPhbkEnReadAll::ReadEntry callded"));
       
   125 	iPhoneGlobals.iEventSignalActive = ETrue;
       
   126 	iTxBuffer.Zero();
       
   127 	iTxBuffer.Format(KPhbkStoreRead,KEnStartIndex,KEnEndIndex);
       
   128 	Write();
       
   129 	}
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CAtPhbkEnReadAll::EventSignal
       
   133 // other items were commented in a header
       
   134 // ---------------------------------------------------------------------------
       
   135 void CAtPhbkEnReadAll::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   136 	{
       
   137 	LOGTEXT3(_L8("CAtPhbkEnReadAll::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   138 	if(aStatus != KErrNone)
       
   139 		{
       
   140 		Complete();
       
   141 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   142 		iCtsyDispatcherCallback.CallbackPhonebookEnStoreReadAllComp(aStatus,iIndex,iNumber,EFalse);
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		if( aEventSource== EWriteCompletion )
       
   147 			{
       
   148 			if( iState==ESetEnName )
       
   149 				{
       
   150 				iState = ESetEnNameComplete;
       
   151 				}
       
   152 			else if( iState==EReadEntry )
       
   153 				{
       
   154 				iState = EReadEntryComplete;
       
   155 				}
       
   156 			}
       
   157 		else 
       
   158 			{
       
   159 			if( iState==ESetEnNameComplete )
       
   160 				{
       
   161 				Complete();
       
   162 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   163 				if(iError == KErrNone)
       
   164 					{
       
   165 					ClearBuffer();
       
   166 					iState = EReadEntry;
       
   167 					ReadEntry();
       
   168 					}
       
   169 				else 
       
   170 					{
       
   171 					iCtsyDispatcherCallback.CallbackPhonebookEnStoreReadAllComp(iError,iIndex,iNumber,EFalse);
       
   172 					}
       
   173 				}
       
   174 			else if( iState==EReadEntryComplete )
       
   175 				{
       
   176 				//encounter OK or ERROR
       
   177 				if( iEndFlag )
       
   178 					{
       
   179 					ClearBuffer();
       
   180 					iIndex++;
       
   181 					iNumber.Zero();
       
   182 					Complete();
       
   183 					iPhoneGlobals.iEventSignalActive = EFalse;
       
   184 		    		iCtsyDispatcherCallback.CallbackPhonebookEnStoreReadAllComp(iError,iIndex,iNumber,EFalse);
       
   185 					}
       
   186 				else 
       
   187 					{
       
   188 					iCtsyDispatcherCallback.CallbackPhonebookEnStoreReadAllComp(iError,iIndex,iNumber,ETrue);
       
   189 					ClearCurrentLine();
       
   190 					}
       
   191 				}
       
   192 			}
       
   193 		}
       
   194 	}
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CAtPhbkEnReadAll::ParseResponseL
       
   198 // other items were commented in a header
       
   199 // ---------------------------------------------------------------------------
       
   200 void CAtPhbkEnReadAll::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   201 	{
       
   202 	if( iState == ESetEnNameComplete )
       
   203 	    {
       
   204 		if (CurrentLine().Match(KLtsyOkString) == 0)
       
   205 			{
       
   206 			iError = KErrNone;
       
   207 			}
       
   208 		else
       
   209 			{
       
   210 			iError = KErrGeneral;
       
   211 			}
       
   212 	    }
       
   213 	else if( iState == EReadEntryComplete )
       
   214 		{
       
   215 		/**
       
   216 		* Here is an Example 
       
   217 		* at+CPBR=1,16  
       
   218 		*+CPBR: 1,"112",129
       
   219 		*+CPBR: 2,"911",129
       
   220 		*OK
       
   221 		*/
       
   222 		RArray<TPtrC8> array;
       
   223 		CleanupClosePushL(array);
       
   224 		iParser->ParseRespondedBuffer(array,Buffer());
       
   225 		// remove the string of AT+CPBR=..
       
   226 		if(array[0].MatchF(KAnyATCommand)!=KErrNotFound)
       
   227 			{
       
   228 			array.Remove(0);
       
   229 			}
       
   230 		TInt count = array.Count();
       
   231 #ifdef _DEBUG		
       
   232 		for( TInt i = 0;i<count;i++ )
       
   233 			{
       
   234 			LOGTEXT3(_L8("CAtPhbkEnReadAll::ParseResponseL\tarray[%d]=%S"),i,&array[i]);  
       
   235 			}
       
   236 #endif		
       
   237 		if((array[1].Match(KLtsyOkString) == KErrNone))
       
   238 			{
       
   239 			CleanupStack::PopAndDestroy();
       
   240 			iError = KErrNone;
       
   241 			iEndFlag = ETrue;
       
   242 			return; 
       
   243 			}
       
   244 		else if((array[1].Match(KLtsyErrorString) == KErrNone))
       
   245 			{
       
   246 			CleanupStack::PopAndDestroy();
       
   247 			iError = KErrGeneral;
       
   248 			iEndFlag = ETrue;
       
   249 			return; 
       
   250 			}
       
   251 	  
       
   252 		iError = KErrNone;
       
   253 		//remove number line if it has 
       
   254 		if( array[0].MatchF(KCPBRSResponseString) == KErrNotFound )
       
   255 			{
       
   256 			array.Remove(0);
       
   257 			}
       
   258 		if( array[0].MatchF(KCPBRSResponseString) == KErrNotFound )
       
   259 			{
       
   260 			CleanupStack::PopAndDestroy();
       
   261 			iError = KErrNotFound;
       
   262 			return;
       
   263 			}
       
   264 		//parse index
       
   265 		TLex8 lex(array[1]);
       
   266 		TUint16 val;
       
   267 		TInt ret = lex.Val(val,EDecimal);
       
   268 		if(ret != KErrNone)
       
   269 			{
       
   270 			CleanupStack::PopAndDestroy();
       
   271 			iError = ret;
       
   272 			return;
       
   273 			}
       
   274 		//Index  
       
   275 		iIndex = val;     
       
   276 		iNumber.Zero();
       
   277 		iNumber.Copy(array[2]);   
       
   278 		//Parse TON/NPI
       
   279 		TLex8 lex1(array[3]);
       
   280 		TUint16 val1;
       
   281 		ret = lex1.Val(val1,EDecimal);
       
   282 		if(ret != KErrNone)
       
   283 			{
       
   284 			CleanupStack::PopAndDestroy();
       
   285 			iError = ret;
       
   286 			return;
       
   287 			}
       
   288 		CleanupStack::PopAndDestroy();
       
   289 		} 
       
   290   	}
       
   291 
       
   292 //End of file