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