cbsref/telephonyrefplugins/atltsy/atcommand/phonebook/src/atphbkstorewrite.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
child 21 4814c5a49428
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     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 atphbkstorewrite.cpp
       
    15 // This contains CAtPhbkStoreWrite which is use to write a phonebook Entry
       
    16 // 
       
    17 
       
    18 //system include 
       
    19 #include <etelmm.h>
       
    20 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    21 #include <mpbutil.h> 
       
    22 
       
    23 //user include 
       
    24 #include "atphbkstorewrite.h"
       
    25 #include "mslogger.h"
       
    26 
       
    27 //constant defination
       
    28 _LIT8(KPhbkStoreWrite,"AT+CPBW=%d,\"%S\",145,\"%S\"\r");
       
    29 _LIT8(KSelAdnPhonebook,"AT+CPBS=\"SM\"\r");
       
    30 _LIT8(KSelFdnPhonebook,"AT+CPBS=\"FD\"\r");
       
    31 const TInt KMaxNumberLen = 20;
       
    32 const TInt KMaxTextLen = 14;
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CAtPhbkStoreWrite::CAtPhbkStoreWrite
       
    36 // other items were commented in a header
       
    37 // ---------------------------------------------------------------------------
       
    38 CAtPhbkStoreWrite::CAtPhbkStoreWrite(CGlobalPhonemanager& aGloblePhone, 
       
    39                                      CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    40                                      :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    41 	{
       
    42 	LOGTEXT(_L8("CAtPhbkStoreWrite::CAtPhbkStoreWrite called"));
       
    43 	}
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CAtPhbkStoreWrite::~CAtPhbkStoreWrite
       
    47 // other items were commented in a header
       
    48 // ---------------------------------------------------------------------------
       
    49 CAtPhbkStoreWrite::~CAtPhbkStoreWrite()
       
    50 	{
       
    51 	LOGTEXT(_L8("CAtPhbkStoreWrite::~CAtPhbkStoreWrite called"));
       
    52 	}
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CAtPhbkStoreWrite::NewLC
       
    56 // other items were commented in a header
       
    57 // ---------------------------------------------------------------------------
       
    58 CAtPhbkStoreWrite* CAtPhbkStoreWrite::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    59                                             CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    60 	{
       
    61 	CAtPhbkStoreWrite* self = new (ELeave)CAtPhbkStoreWrite(aGloblePhone, 
       
    62                                                             aCtsyDispatcherCallback);
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL();
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CAtPhbkStoreWrite::NewL
       
    70 // other items were commented in a header
       
    71 // ---------------------------------------------------------------------------
       
    72 CAtPhbkStoreWrite* CAtPhbkStoreWrite::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    73                                            CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    74 	{
       
    75 	CAtPhbkStoreWrite* self=CAtPhbkStoreWrite::NewLC(aGloblePhone, 
       
    76                                                      aCtsyDispatcherCallback);
       
    77 	CleanupStack::Pop(self);
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CAtPhbkStoreWrite::ConstructL
       
    83 // other items were commented in a header
       
    84 // ---------------------------------------------------------------------------
       
    85 void CAtPhbkStoreWrite::ConstructL()
       
    86 	{
       
    87 	CAtCommandBase::ConstructL();
       
    88 	}
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CAtPhbkStoreWrite::SetPhonebookType
       
    92 // other items were commented in a header
       
    93 // ---------------------------------------------------------------------------
       
    94 void CAtPhbkStoreWrite::SetPhonebookType(DispatcherPhonebook::TPhonebook aPhonebookType)
       
    95 	{
       
    96 	iPhoneBookType = aPhonebookType;
       
    97 	}
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // CAtPhbkStoreWrite::SetPhonebookEntry
       
   101 // other items were commented in a header
       
   102 // ---------------------------------------------------------------------------
       
   103 void CAtPhbkStoreWrite::SetPhonebookEntryL(const TDesC8& aEntry)
       
   104 	{
       
   105 	TInt ret = KErrNone;
       
   106 	TInt retVal = KErrNone;
       
   107 	TUint8 tmpTagValue;
       
   108 	TPtrC16 textPtr;
       
   109     TUint8 tagValue;
       
   110     CPhoneBookBuffer::TPhBkTagType tagType;
       
   111     TUint8 newEntryTag;
       
   112     newEntryTag = RMobilePhoneBookStore::ETagPBNewEntry;
       
   113     TUint16 index;
       
   114     TPtrC16 numPtr;
       
   115     TPtrC16 type;
       
   116     // used to write phonebook data
       
   117 	CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer(); 
       
   118 	CleanupStack::PushL(pbBuffer);
       
   119 	
       
   120     //  Set pointer to constant descriptor
       
   121     TPtr8 dataToSeparate( NULL, 0, 0 );
       
   122     dataToSeparate.Set( (TUint8*)aEntry.Ptr(),
       
   123     		aEntry.Length(), aEntry.Length() );
       
   124     
       
   125     //  Init and get entry info
       
   126     pbBuffer->Set( &dataToSeparate );
       
   127     pbBuffer->StartRead();
       
   128     ret = pbBuffer->GetTagAndType( tmpTagValue, tagType );
       
   129     // Ensure, that there is new entry containing data
       
   130     if ( KErrNone == ret && tmpTagValue == newEntryTag )
       
   131         {
       
   132         // Get the first value from TLV data
       
   133         ret = pbBuffer->GetTagAndType( tagValue, tagType );
       
   134         while(ret == KErrNone)
       
   135 			{	
       
   136 			switch ( tagValue )
       
   137 		        {
       
   138 		        // Get name
       
   139 		        case RMobilePhoneBookStore::ETagPBText:
       
   140 		        	retVal = pbBuffer->GetValue( textPtr );
       
   141 		            if(retVal == KErrNone)
       
   142 		                {
       
   143 		                iPhbkEntry.iText = textPtr;
       
   144 		            	}
       
   145 		            break;
       
   146 		         // Get number
       
   147 		        case RMobilePhoneBookStore::ETagPBNumber:
       
   148 		            ret = pbBuffer->GetValue( numPtr );
       
   149 		            if(retVal == KErrNone)
       
   150 		            	{
       
   151 		            	iPhbkEntry.iNumber = numPtr;
       
   152 		            	}
       
   153 		            break;
       
   154 		         // get the index
       
   155 		        case RMobilePhoneBookStore::ETagPBAdnIndex:
       
   156 		        	retVal = pbBuffer->GetValue(index);
       
   157 		            if( retVal == KErrNone )
       
   158 		            	{
       
   159 		            	iPhbkEntry.iIndex = index;
       
   160 		            	}
       
   161 		            break;
       
   162 		         // get ETagPBTonNpi , not needed
       
   163 		        case RMobilePhoneBookStore::ETagPBTonNpi:
       
   164 		        	retVal = pbBuffer->GetValue(type);
       
   165 		            break;      
       
   166 		        default:
       
   167 		        	break;
       
   168 		        }//switch 
       
   169 			ret = pbBuffer->GetTagAndType( tagValue, tagType );
       
   170 		    }//while
       
   171  		}
       
   172 	CleanupStack::PopAndDestroy(pbBuffer);
       
   173 	}	
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CAtPhbkStoreWrite::StartRequest
       
   177 // other items were commented in a header
       
   178 // ---------------------------------------------------------------------------
       
   179 void CAtPhbkStoreWrite::StartRequest()
       
   180 	{
       
   181 	GetMaxNumberLen();
       
   182 	ExecuteCommand();
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CAtPhbkStoreWrite::ExecuteCommand
       
   187 // other items were commented in a header
       
   188 // ---------------------------------------------------------------------------
       
   189 void CAtPhbkStoreWrite::ExecuteCommand()
       
   190 	{
       
   191 	LOGTEXT(_L8("CAtPhbkStoreWrite::ExecuteCommand called"));
       
   192 	iState = ESetStoreName;
       
   193 	iTxBuffer.Zero();	
       
   194 	if( iPhoneBookType == DispatcherPhonebook::EIccAdn )
       
   195 		{
       
   196 		iTxBuffer.Copy(KSelAdnPhonebook);
       
   197 		}
       
   198 	else if( iPhoneBookType == DispatcherPhonebook::EIccFdn )
       
   199 		{
       
   200 		iTxBuffer.Copy(KSelFdnPhonebook);
       
   201 		}
       
   202 	Write();
       
   203 	}
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CAtPhbkStoreWrite::WriteEntry
       
   207 // other items were commented in a header
       
   208 // ---------------------------------------------------------------------------
       
   209 void CAtPhbkStoreWrite::WriteEntry()
       
   210 	{
       
   211 	LOGTEXT(_L8("CAtPhbkStoreWrite::WriteEntry callded"));
       
   212 	iPhoneGlobals.iEventSignalActive = ETrue;
       
   213 	iTxBuffer.Zero();
       
   214 	TBuf8<KMaxNumberLen> tempNumber;
       
   215 	TBuf8<KMaxTextLen>   tempText;
       
   216 	//covert 16 bit to 8 bit
       
   217 	tempNumber.Copy(iPhbkEntry.iNumber);
       
   218 	tempText.Copy(iPhbkEntry.iText);
       
   219 	iTxBuffer.Format(KPhbkStoreWrite,iPhbkEntry.iIndex,
       
   220 			         &tempNumber,&tempText);
       
   221 	Write();
       
   222 	}
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CAtPhbkStoreWrite::EventSignal
       
   226 // other items were commented in a header
       
   227 // ---------------------------------------------------------------------------
       
   228 void CAtPhbkStoreWrite::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   229 	{
       
   230 	LOGTEXT3(_L8("CAtPhbkStoreWrite::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   231 	
       
   232 	if(aStatus != KErrNone)
       
   233 		{
       
   234 		Complete();
       
   235 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   236 		iCtsyDispatcherCallback.CallbackPhonebookStoreWriteEntryComp(aStatus,iPhoneBookType,iPhbkEntry.iIndex,iMaxLen);
       
   237 		}
       
   238 	else
       
   239 		{
       
   240 		if( aEventSource== EWriteCompletion )
       
   241 			{
       
   242 			if( iState==ESetStoreName )
       
   243 				{
       
   244 				iState = ESetStoreNameComplete;
       
   245 				}
       
   246 			else if( iState==EWriteEntry )
       
   247 				{
       
   248 				iState = EWriteEntryComplete;
       
   249 				}
       
   250 			}
       
   251 		else 
       
   252 			{
       
   253 			if( iState==ESetStoreNameComplete )
       
   254 				{
       
   255 				Complete();
       
   256 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   257 				if( iError==KErrNone )
       
   258 					{
       
   259 					iState = EWriteEntry;
       
   260 					WriteEntry();
       
   261 					}
       
   262 				else
       
   263 					{
       
   264 					iCtsyDispatcherCallback.CallbackPhonebookStoreWriteEntryComp(iError,iPhoneBookType,
       
   265 																				 iPhbkEntry.iIndex,iMaxLen);
       
   266 					}
       
   267 				}
       
   268 			else if( iState== EWriteEntryComplete)
       
   269 				{
       
   270 				Complete();
       
   271 				iPhoneGlobals.iEventSignalActive = EFalse;
       
   272 				iCtsyDispatcherCallback.CallbackPhonebookStoreWriteEntryComp(iError,iPhoneBookType,
       
   273 															                 iPhbkEntry.iIndex,iMaxLen);
       
   274 				}
       
   275 			}
       
   276 		}
       
   277 	}
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CAtPhbkStoreWrite::ParseResponseL
       
   281 // other items were commented in a header
       
   282 // ---------------------------------------------------------------------------
       
   283 void CAtPhbkStoreWrite::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   284 	{
       
   285 	if (CurrentLine().Match(KLtsyOkString) == 0)
       
   286 		{
       
   287 		iError = KErrNone;
       
   288 		}
       
   289 	else
       
   290 		{
       
   291 		iError = KErrGeneral;
       
   292 		}
       
   293 	}
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CAtPhbkStoreWrite::GetMaxNumberLen
       
   297 // other items were commented in a header
       
   298 // ---------------------------------------------------------------------------
       
   299 void CAtPhbkStoreWrite::GetMaxNumberLen()
       
   300 	{
       
   301 	if( iPhoneBookType == DispatcherPhonebook::EIccAdn )
       
   302 		{
       
   303 		iMaxLen = iPhoneGlobals.iPhonebookStoreInfo.iAdnMaximumNumberLength;
       
   304 		}
       
   305 	else if( iPhoneBookType == DispatcherPhonebook::EIccFdn )
       
   306 		{
       
   307 		iMaxLen = iPhoneGlobals.iPhonebookStoreInfo.iFdnMaximumNumberLength;
       
   308 		}
       
   309 	}
       
   310 
       
   311 //End of file