cbsref/telephonyrefplugins/atltsy/atcommand/phonebooken/src/atphbkengetinfo.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 atphbkengetinfo.cpp
       
    15 // This contains CAtPhbkEnGetInfo which is used to get emergency call info
       
    16 // 
       
    17 
       
    18 //system include 
       
    19 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    20 #include <etelmm.h>
       
    21 
       
    22 //user include
       
    23 #include "atphbkengetinfo.h"
       
    24 #include "mslogger.h"
       
    25 #include "ltsycommondefine.h"
       
    26 
       
    27 //constant defination
       
    28 _LIT8(KSetEnStore,"AT+CPBS=\"%S\"\r");
       
    29 _LIT8(KGetEnStoreInfo,"AT+CPBS?\r");
       
    30 _LIT8(KCPBSResponseString,"+CPBS:");
       
    31 _LIT8(KPhonebookEn,"EN");
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CAtPhbkEnGetInfo::CAtPhbkEnGetInfo
       
    35 // other items were commented in a header
       
    36 // ---------------------------------------------------------------------------
       
    37 CAtPhbkEnGetInfo::CAtPhbkEnGetInfo(CGlobalPhonemanager& aGloblePhone, 
       
    38                                                    CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    39                                                    :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    40 	{
       
    41 	LOGTEXT(_L8("CAtPhbkEnGetInfo::CAtPhbkEnGetInfo called"));
       
    42 	}
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CAtPhbkEnGetInfo::~CAtPhbkEnGetInfo
       
    46 // other items were commented in a header
       
    47 // ---------------------------------------------------------------------------
       
    48 CAtPhbkEnGetInfo::~CAtPhbkEnGetInfo()
       
    49 	{
       
    50 	LOGTEXT(_L8("CAtPhbkEnGetInfo::~CAtPhbkEnGetInfo called"));
       
    51 	}
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CAtPhbkEnGetInfo::NewLC
       
    55 // other items were commented in a header
       
    56 // ---------------------------------------------------------------------------
       
    57 CAtPhbkEnGetInfo* CAtPhbkEnGetInfo::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    58                                                           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    59     {
       
    60 	CAtPhbkEnGetInfo* self = new (ELeave)CAtPhbkEnGetInfo(aGloblePhone, 
       
    61 			                                                              aCtsyDispatcherCallback);
       
    62 	CleanupStack::PushL(self);
       
    63 	self->ConstructL();
       
    64 	return self;
       
    65 	}
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CAtPhbkEnGetInfo::NewL
       
    69 // other items were commented in a header
       
    70 // ---------------------------------------------------------------------------
       
    71 CAtPhbkEnGetInfo* CAtPhbkEnGetInfo::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    72                                                          CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    73     {
       
    74 	CAtPhbkEnGetInfo* self=CAtPhbkEnGetInfo::NewLC(aGloblePhone, 
       
    75                                                                    aCtsyDispatcherCallback);
       
    76 	CleanupStack::Pop(self);
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CAtPhbkEnGetInfo::ConstructL
       
    82 // other items were commented in a header
       
    83 // ---------------------------------------------------------------------------
       
    84 void CAtPhbkEnGetInfo::ConstructL()
       
    85 	{
       
    86 	CAtCommandBase::ConstructL();
       
    87 	}
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CAtPhbkEnGetInfo::StartRequest
       
    92 // other items were commented in a header
       
    93 // ---------------------------------------------------------------------------
       
    94 void CAtPhbkEnGetInfo::StartRequest()
       
    95 	{
       
    96 	ExecuteCommand();
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CAtPhbkEnGetInfo::ExecuteCommand
       
   101 // other items were commented in a header
       
   102 // ---------------------------------------------------------------------------
       
   103 void CAtPhbkEnGetInfo::ExecuteCommand()
       
   104 	{
       
   105 	LOGTEXT(_L8("CAtPhbkEnGetInfo::ExecuteCommand called"));
       
   106 	iState = ESetEnStore;
       
   107 	TPtrC8  storeName;
       
   108 	iTxBuffer.Zero();
       
   109 	storeName.Set(KPhonebookEn);
       
   110 	iTxBuffer.Format(KSetEnStore,&storeName);
       
   111 	Write();
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CAtPhbkEnGetInfo::EventSignal
       
   116 // other items were commented in a header
       
   117 // ---------------------------------------------------------------------------
       
   118 void CAtPhbkEnGetInfo::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   119 	{
       
   120 	LOGTEXT3(_L8("CAtPhbkEnGetInfo::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   121 	
       
   122 	if(aStatus != KErrNone)
       
   123 		{
       
   124 		Complete();
       
   125 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   126 		iCtsyDispatcherCallback.CallbackPhonebookEnStoreGetInfoComp(aStatus,iUsed);
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 		if( aEventSource == EWriteCompletion )
       
   131 			{
       
   132 			LOGTEXT(_L8("CAtPhbkEnGetInfo::EventSignal,EWriteCompletion!"));
       
   133 			if( iState==ESetEnStore )
       
   134 				{
       
   135 				iState = ESetEnStoreComplete;
       
   136 				}
       
   137 			else if( iState==EGetEnStoreInfo )
       
   138 				{
       
   139 				iState = EGetEnStoreInfoComplete;
       
   140 				}
       
   141 			 }
       
   142 		else 
       
   143 			{
       
   144 			LOGTEXT(_L8("CAtPhbkEnGetInfo::EventSignal,EReadCompletion!"));
       
   145 			if( iState == ESetEnStoreComplete )
       
   146 				{
       
   147 				Complete();
       
   148 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   149 				if(iError == KErrNone)
       
   150 					{
       
   151 					iState = EGetEnStoreInfo;
       
   152 					GetEnStoreInfo();
       
   153 					}
       
   154 				else
       
   155 					{
       
   156 					iCtsyDispatcherCallback.CallbackPhonebookEnStoreGetInfoComp(iError,iUsed);
       
   157 					}
       
   158 				}
       
   159 			else if( iState == EGetEnStoreInfoComplete )
       
   160 				{
       
   161 				Complete();
       
   162 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   163 				iCtsyDispatcherCallback.CallbackPhonebookEnStoreGetInfoComp(iError,iUsed);
       
   164 				}
       
   165 			}
       
   166 		}
       
   167 	}	
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CAtPhbkEnGetInfo::GetEnStoreInfo
       
   171 // other items were commented in a header
       
   172 // ---------------------------------------------------------------------------
       
   173 void CAtPhbkEnGetInfo::GetEnStoreInfo()
       
   174 	{
       
   175 	LOGTEXT(_L8("CAtPhbkEnGetInfo::GetEnStoreInfo callded"));
       
   176 	iPhoneGlobals.iEventSignalActive = ETrue;
       
   177 	iTxBuffer.Zero();
       
   178 	iTxBuffer.Copy(KGetEnStoreInfo);
       
   179 	Write();   
       
   180 	}
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CAtPhbkEnGetInfo::ParseResponseL
       
   184 // other items were commented in a header
       
   185 // ---------------------------------------------------------------------------
       
   186 void CAtPhbkEnGetInfo::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   187 	{
       
   188 	if( iState==ESetEnStoreComplete )
       
   189 		{
       
   190 		if (CurrentLine().Match(KLtsyOkString) == 0)
       
   191 			{
       
   192 			iError = KErrNone;
       
   193 			}
       
   194 		else
       
   195 			{
       
   196 			iError = KErrGeneral;
       
   197 			}
       
   198 		}
       
   199 	else if( iState==EGetEnStoreInfoComplete )
       
   200 		{
       
   201 		/**
       
   202 		* Here is an Example 
       
   203 		* +CPBS: "EN",2,16 
       
   204         * phonebooken is selected,2 locations are used and 
       
   205         * total 16 locations are available
       
   206 		*/
       
   207 		iError = KErrNone;
       
   208 		RArray<TPtrC8> array;
       
   209 		CleanupClosePushL(array);
       
   210 		iParser->ParseRespondedBuffer(array,Buffer());
       
   211 		//remove AT+CPBS
       
   212 		if(array[0].MatchF(KAnyATCommand)!=KErrNotFound)
       
   213 			{
       
   214 			array.Remove(0);
       
   215 			}
       
   216 		TInt count = array.Count();
       
   217 #ifdef _DEBUG			
       
   218 		for( TInt i=0;i<count;i++ )
       
   219 			{
       
   220 		    LOGTEXT3(_L8("CAtPhbkEnGetInfo::ParseResponseL\tarray[%d]=%S"),
       
   221 		    		      i,&array[i]);     
       
   222 			}
       
   223 #endif			
       
   224 		if (count <= 1)
       
   225 			{
       
   226 			CleanupStack::PopAndDestroy();
       
   227 			iError = KErrNotFound;
       
   228 			return;
       
   229 			}
       
   230 		if(array[0].MatchF(KCPBSResponseString)==KErrNotFound)
       
   231 			{
       
   232 			CleanupStack::PopAndDestroy();
       
   233 			iError = KErrNotFound;
       
   234 			return;
       
   235 			}
       
   236 				
       
   237 		//parse used
       
   238 		TLex8 lex(array[2]);
       
   239 		TUint16 val;
       
   240 		TInt ret=lex.Val(val,EDecimal);
       
   241 		if(ret!=KErrNone)
       
   242 			{
       
   243 			CleanupStack::PopAndDestroy();
       
   244 			iError = ret;
       
   245 			return;
       
   246 			}
       
   247 		iUsed = val;
       
   248 		
       
   249 		//parse total
       
   250 		TLex8 lex1(array[3]);
       
   251 		ret=lex1.Val(val,EDecimal);
       
   252 		if(ret!=KErrNone)
       
   253 			{
       
   254 			CleanupStack::PopAndDestroy();
       
   255 			iError = ret;
       
   256 			return;
       
   257 			}
       
   258 		iTotal = val;
       
   259 	    LOGTEXT3(_L8("CAtPhbkEnGetInfo::ParseResponseL\tPreferred store used=%d, total=%d"), 
       
   260 	    		                                iUsed,iTotal);
       
   261 		CleanupStack::PopAndDestroy(&array);
       
   262 		}
       
   263 	}
       
   264 
       
   265 //End of file