cbsref/telephonyrefplugins/atltsy/atcommand/phonebook/src/atphbkstoreinitialise.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 atphbkstoreinitialise.cpp
       
    15 // This contains CAtPhbkStoreInitialise which initialises all kinds of phonebook 
       
    16 // 
       
    17 
       
    18 //system include 
       
    19 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    20 #include <etelmm.h>
       
    21 
       
    22 //user  include 
       
    23 #include "atphbkstoreinitialise.h"
       
    24 #include "mslogger.h"
       
    25 #include "ltsycommondefine.h"
       
    26 
       
    27 //constant defination
       
    28 _LIT8(KAdnStore,"AT+CPBS=\"SM\"\r");
       
    29 _LIT8(KFdnStore,"AT+CPBS=\"FD\"\r");
       
    30 _LIT8(KGetSotreInfo,"AT+CPBR=?\r");
       
    31 _LIT8(KCPBRResponseString,"+CPBR:");
       
    32 _LIT8(KSeparator,"-");
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CAtPhbkStoreInitialise::CAtPhbkStoreInitialise
       
    36 // other items were commented in a header
       
    37 // ---------------------------------------------------------------------------
       
    38 CAtPhbkStoreInitialise::CAtPhbkStoreInitialise(CGlobalPhonemanager& aGloblePhone, 
       
    39                                                CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    40                                                :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    41 	{
       
    42 	LOGTEXT(_L8("CAtPhbkStoreInitialise::CAtPhbkStoreInitialise called"));
       
    43 	}
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAtPhbkStoreInitialise::~CAtPhbkStoreInitialise
       
    47 // other items were commented in a header
       
    48 // ---------------------------------------------------------------------------
       
    49 CAtPhbkStoreInitialise::~CAtPhbkStoreInitialise()
       
    50 	{
       
    51 	LOGTEXT(_L8("CAtPhbkStoreInitialise::~CAtPhbkStoreInitialise called"));
       
    52 	
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CAtPhbkStoreInitialise::NewLC
       
    57 // other items were commented in a header
       
    58 // ---------------------------------------------------------------------------
       
    59 CAtPhbkStoreInitialise* CAtPhbkStoreInitialise::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    60                                                       CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    61     {
       
    62 	CAtPhbkStoreInitialise* self = new (ELeave)CAtPhbkStoreInitialise(aGloblePhone, 
       
    63 			                                                          aCtsyDispatcherCallback);
       
    64 	CleanupStack::PushL(self);
       
    65 	self->ConstructL();
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CAtPhbkStoreInitialise::NewL
       
    71 // other items were commented in a header
       
    72 // ---------------------------------------------------------------------------
       
    73 CAtPhbkStoreInitialise* CAtPhbkStoreInitialise::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    74                                                      CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    75     {
       
    76 	CAtPhbkStoreInitialise* self=CAtPhbkStoreInitialise::NewLC(aGloblePhone, 
       
    77                                                                aCtsyDispatcherCallback);
       
    78 	CleanupStack::Pop(self);
       
    79 	return self;
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CAtPhbkStoreInitialise::ConstructL
       
    84 // other items were commented in a header
       
    85 // ---------------------------------------------------------------------------
       
    86 void CAtPhbkStoreInitialise::ConstructL()
       
    87 	{
       
    88 	CAtCommandBase::ConstructL();
       
    89 	//first is ADN 
       
    90 	iStoreArr.Reset();
       
    91 	iStoreArr.Append(KAdnStore());
       
    92 //	//second is FDN
       
    93 	iStoreArr.Append(KFdnStore());
       
    94 	}
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CAtPhbkStoreInitialise::StartRequest
       
    98 // other items were commented in a header
       
    99 // ---------------------------------------------------------------------------
       
   100 void CAtPhbkStoreInitialise::StartRequest()
       
   101 	{
       
   102 	ExecuteCommand();
       
   103 	}
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CAtPhbkStoreInitialise::ExecuteCommand
       
   107 // other items were commented in a header
       
   108 // ---------------------------------------------------------------------------
       
   109 void CAtPhbkStoreInitialise::ExecuteCommand()
       
   110 	{
       
   111 	LOGTEXT(_L8("CAtPhbkStoreInitialise::ExecuteCommand called"));
       
   112 	iState = ESetStoreName;
       
   113 	iStoreIndex = 0;
       
   114 	iTxBuffer.Zero();	
       
   115 	iTxBuffer.Copy(iStoreArr[iStoreIndex]);
       
   116 	Write();
       
   117 	}
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CAtPhbkStoreInitialise::EventSignal
       
   121 // other items were commented in a header
       
   122 // ---------------------------------------------------------------------------
       
   123 void CAtPhbkStoreInitialise::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   124 	{
       
   125 	LOGTEXT3(_L8("CAtPhbkStoreInitialise::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   126 	
       
   127 	if(aStatus != KErrNone)
       
   128 		{
       
   129 		Complete();
       
   130 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   131 		iCtsyDispatcherCallback.CallbackPhonebookStoreInitialiseComp(aStatus,iStoreInfo);
       
   132 		}
       
   133 	else
       
   134 		{
       
   135 		if( aEventSource == EWriteCompletion )
       
   136 			{
       
   137 			LOGTEXT(_L8("CAtPhbkStoreInitialise::EventSignal,EWriteCompletion!"));
       
   138 			if( iState==ESetStoreName )
       
   139 				{
       
   140 				iState = ESetStoreNameComplete;
       
   141 				}
       
   142 			else if( iState==EGetStoreInfo )
       
   143 				{
       
   144 				iState = EGetStoreInfoComplete;
       
   145 				}
       
   146 			 }
       
   147 		else 
       
   148 			{
       
   149 			LOGTEXT(_L8("CAtPhbkStoreInitialise::EventSignal,EReadCompletion!"));
       
   150 			if( iState==ESetStoreNameComplete )
       
   151 				{
       
   152 				Complete();
       
   153 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   154 				if(iError == KErrNone )
       
   155 					{
       
   156 					iState = EGetStoreInfo;
       
   157 					GetStoreInfo();
       
   158 					}
       
   159 				else
       
   160 					{
       
   161 					iCtsyDispatcherCallback.CallbackPhonebookStoreInitialiseComp(iError,iStoreInfo);
       
   162 					}
       
   163 				}
       
   164 			else if( iState==EGetStoreInfoComplete )
       
   165 				{
       
   166 				Complete();
       
   167 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   168 				iStoreIndex++;
       
   169 				//stands for complete all phonebook store type's at+CPBR=?
       
   170 				if ( iStoreIndex > 1 )
       
   171 					{
       
   172 					iCtsyDispatcherCallback.CallbackPhonebookStoreInitialiseComp(iError,iStoreInfo);
       
   173 					}
       
   174 				else 
       
   175 					{
       
   176 					iState = ESetStoreName;
       
   177 					iTxBuffer.Zero();
       
   178 					//For this case,only two store type
       
   179 					iTxBuffer.Copy(iStoreArr[iStoreIndex]);   
       
   180 					Write();
       
   181 					}
       
   182 				}
       
   183 			}  
       
   184 		}
       
   185 	}	
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CAtPhbkStoreInitialise::GetStoreInfo
       
   189 // other items were commented in a header
       
   190 // ---------------------------------------------------------------------------
       
   191 void CAtPhbkStoreInitialise::GetStoreInfo()
       
   192 	{
       
   193 	LOGTEXT(_L8("CAtPhbkStoreInitialise::GetPhoneStoreInfo callded"));
       
   194 	iPhoneGlobals.iEventSignalActive = ETrue;
       
   195 	iTxBuffer.Zero();
       
   196 	iTxBuffer.Copy(KGetSotreInfo);
       
   197 	Write();   
       
   198 	}
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CAtPhbkStoreInitialise::ParseResponseL
       
   202 // other items were commented in a header
       
   203 // ---------------------------------------------------------------------------
       
   204 void CAtPhbkStoreInitialise::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   205 	{
       
   206 	if( iState == ESetStoreNameComplete )
       
   207 		{
       
   208 		if (CurrentLine().Match(KLtsyOkString) == 0)
       
   209 			{
       
   210 			iError = KErrNone;
       
   211 			}
       
   212 		else
       
   213 			{
       
   214 			iError = KErrGeneral;
       
   215 			}
       
   216 		}
       
   217 	else if( iState == EGetStoreInfoComplete )
       
   218 		{
       
   219 		/**
       
   220 		* Parse result of AT+CPBR=? 
       
   221 		* Response:+CPMS:<(startIndex-endIndex>,<len1>,<len2>
       
   222 		* len1 is maximum length for phone number
       
   223 		* len2 is maximum length for text 
       
   224 		*/
       
   225 		iError = KErrNone;
       
   226 		RArray<TPtrC8> array;
       
   227 		CleanupClosePushL(array);
       
   228 		iParser->ParseRespondedBuffer(array,Buffer());
       
   229 		// remove the string of AT+CPBR=?
       
   230 		if(array[0].MatchF(KAnyATCommand) != KErrNotFound)
       
   231 			{
       
   232 			array.Remove(0);
       
   233 			}
       
   234 		TInt count = array.Count();
       
   235 #ifdef _DEBUG	
       
   236 		for( TInt i=0;i<count;i++ )
       
   237 			{
       
   238 		    LOGTEXT3(_L8("CAtPhbkStoreInitialise::ParseResponseL\tarray[%d]=%S"),
       
   239 		    		      i,&array[i]);     
       
   240 			}
       
   241 #endif		
       
   242 		if (count <= 1)
       
   243 			{
       
   244 			CleanupStack::PopAndDestroy();
       
   245 			iError = KErrNotFound;
       
   246 			return;
       
   247 			}
       
   248 		if(array[0].MatchF(KCPBRResponseString) == KErrNotFound)
       
   249 			{
       
   250 			CleanupStack::PopAndDestroy();
       
   251 			iError = KErrNotFound;
       
   252 			return;
       
   253 			}
       
   254 		//parse iTotalEntries
       
   255 		TInt len = array[1].Length();
       
   256 		TInt pos = array[1].FindF(KSeparator);
       
   257 		TPtrC8 tempStr;
       
   258 		tempStr.Set(array[1].Left(pos));
       
   259 		TLex8 lex(tempStr);
       
   260 		TUint16 val;
       
   261 		TInt ret = lex.Val(val,EDecimal);
       
   262 		if(ret != KErrNone)
       
   263 			{
       
   264 			CleanupStack::PopAndDestroy();
       
   265 			iError = ret;
       
   266 			return;
       
   267 			}
       
   268 		tempStr.Set(array[1].Right(len-pos-1));
       
   269 		TLex8 lex1(tempStr);
       
   270 		TUint16 val1;
       
   271 		ret = lex1.Val(val1,EDecimal);
       
   272 		if(ret!=KErrNone)
       
   273 			{
       
   274 			CleanupStack::PopAndDestroy();
       
   275 			iError = ret;
       
   276 			return;
       
   277 			}
       
   278 	    iTotalEntries = val1-val+1;
       
   279 
       
   280 		
       
   281 	  	//parse MaximumNumberLength
       
   282 		TLex8 lexNumberLen(array[2]);
       
   283 		ret = lexNumberLen.Val(iValNumberLen,EDecimal);
       
   284 		if(ret != KErrNone)
       
   285 			{
       
   286 			CleanupStack::PopAndDestroy();
       
   287 			iError = ret;
       
   288 			return;
       
   289 			}
       
   290 				
       
   291 		//parse MaximumTextLength
       
   292 		TLex8 lexTextLen(array[3]);
       
   293 		ret = lexTextLen.Val(iValTextLen,EDecimal);
       
   294 		if(ret != KErrNone)
       
   295 			{
       
   296 			CleanupStack::PopAndDestroy();
       
   297 			iError = ret;
       
   298 			return;
       
   299 			}
       
   300 		AssignPhbkType();
       
   301 		LOGTEXT2(_L8("CAtPhbkStoreInitialise::ParseResponseL\tiTotalEntries=%d"),iTotalEntries);
       
   302 	    LOGTEXT3(_L8("CAtPhbkStoreInitialise::ParseResponseL\tPreferred MaxNumbereLen=%d, MaxTextLen=%d"), 
       
   303 	    		                                              iValNumberLen,iValTextLen);
       
   304 		CleanupStack::PopAndDestroy(&array);
       
   305 
       
   306 		}
       
   307 	}
       
   308 
       
   309 // ---------------------------------------------------------------------------
       
   310 // CAtPhbkStoreInitialise::AssignPhbkType
       
   311 // other items were commented in a header
       
   312 // ---------------------------------------------------------------------------
       
   313 void CAtPhbkStoreInitialise::AssignPhbkType()
       
   314 	{
       
   315 	if( iStoreIndex == 0 )
       
   316 		{
       
   317 		iStoreInfo.iAdnTotalEntries = iTotalEntries;
       
   318 		iPhoneGlobals.iPhonebookStoreInfo.iAdnTotalEntries = iTotalEntries;
       
   319 		iStoreInfo.iAdnMaximumNumberLength = iValNumberLen;
       
   320 		iStoreInfo.iAdnMaximumTextLength = iValTextLen;
       
   321 		iPhoneGlobals.iPhonebookStoreInfo.iAdnMaximumNumberLength =
       
   322 		                                    iValNumberLen;
       
   323 		iPhoneGlobals.iPhonebookStoreInfo.iAdnMaximumTextLength =
       
   324 		                                     iValTextLen;
       
   325 		}
       
   326 	else if( iStoreIndex == 1 )
       
   327 		{
       
   328 		iStoreInfo.iFdnTotalEntries = iTotalEntries;
       
   329 		iPhoneGlobals.iPhonebookStoreInfo.iFdnTotalEntries = iTotalEntries;
       
   330 		iStoreInfo.iFdnMaximumNumberLength = iValNumberLen;
       
   331 		iStoreInfo.iFdnMaximumTextLength = iValTextLen;
       
   332 		iPhoneGlobals.iPhonebookStoreInfo.iFdnMaximumNumberLength = 
       
   333 											iValNumberLen;
       
   334 		iPhoneGlobals.iPhonebookStoreInfo.iFdnMaximumTextLength =
       
   335 											iValTextLen;    
       
   336 		}
       
   337 	}
       
   338 
       
   339 //End of file