telephonyserverplugins/simtsy/src/CSimSmsStore.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2003-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 // Implements the SMS Store manipulation code.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <mmlist.h>
       
    23 #include <mmretrieve.h>
       
    24 #include <testconfigfileparser.h>
       
    25 #include "CSimSmsStore.h"
       
    26 #include "csimsmsmess.h"
       
    27 #include "Simlog.h"
       
    28 #include "CSimTsyMode.h"
       
    29 
       
    30 const TInt KSmsStoreGranularity=2;
       
    31 const TInt KCorruptPDU=9999;
       
    32 _LIT(KNullTelephoneNumber,"0");
       
    33 
       
    34 
       
    35 CListReadAllAttempt* CListReadAllAttempt::NewL(RMobilePhone::TClientId& aId, TTsyReqHandle aReqHandle)
       
    36 /**
       
    37  * Standard two phase constructor.
       
    38  * @param aId The client ID (session and sub-session handles) that uniquely identifies a client performing a two phase read.
       
    39  * @param aReqHandle The TSY request handle of the client request associated with a two phase read.
       
    40  * @return CListReadAllAttempt* The newly created object.
       
    41  */
       
    42 	{
       
    43 	CListReadAllAttempt* read=new(ELeave) CListReadAllAttempt(aId, aReqHandle);
       
    44 	CleanupStack::PushL(read);
       
    45 	read->ConstructL();
       
    46 	CleanupStack::Pop();
       
    47 	return read;
       
    48 	}
       
    49 
       
    50 CListReadAllAttempt::CListReadAllAttempt(RMobilePhone::TClientId& aId, TTsyReqHandle aReqHandle)
       
    51 		: iListBuf(NULL),iReqHandle(aReqHandle)
       
    52 /**
       
    53  * Trivial first phase constructor.
       
    54  * @param aId The client ID (session and sub-session handles) that uniquely identifies a client performing a two phase read.
       
    55  * @param aReqHandle The TSY request handle of the client request associated with a two phase read.
       
    56  */
       
    57 	{
       
    58 	iClient.iSessionHandle=aId.iSessionHandle;
       
    59 	iClient.iSubSessionHandle=aId.iSubSessionHandle;
       
    60 	iReqHandle=aReqHandle;
       
    61 	iListBuf = NULL;
       
    62 	}
       
    63 
       
    64 void CListReadAllAttempt::ConstructL()
       
    65 /**
       
    66  * Trivial second phase constructor.
       
    67  */
       
    68 	{
       
    69 	}
       
    70 
       
    71 CListReadAllAttempt::~CListReadAllAttempt()
       
    72 /**
       
    73  * Trivial destructor.
       
    74  */
       
    75 	{
       
    76 	delete iListBuf;
       
    77 	}
       
    78 
       
    79 //
       
    80 // CSimSmsStore
       
    81 //
       
    82 void CSimSmsStore::ClosePhone(TAny* aObj)
       
    83 /**
       
    84  * A utility function for cleaning up the stack.
       
    85  */
       
    86 	{
       
    87 	((CObject*)aObj)->Close();
       
    88 	}
       
    89 
       
    90 CSimSmsStore* CSimSmsStore::NewL(CSimSmsMessaging* aSimSmsMess, const TDesC8& aName, TInt aMaxNumSlots, CSimPhone* aPhone)
       
    91 /**
       
    92  * Standard two phase constructor.
       
    93  * @param aSimSmsMess	The SMS Messaging object from which this SMS Store was opened.
       
    94  * @param aName			The name of the created SMS Store.
       
    95  * @param aMaxNumSlots	The maximum number of slots in the SMS Store.
       
    96  * @return CSimSmsStore* The newly created object.
       
    97  */
       
    98 	{
       
    99 	CSimSmsStore* store=new(ELeave) CSimSmsStore(aSimSmsMess, aPhone);
       
   100 	TCleanupItem newObjClose(ClosePhone,store);
       
   101 	CleanupStack::PushL(newObjClose);
       
   102 	store->ConstructL(aName,aMaxNumSlots);
       
   103 	CleanupStack::Pop();
       
   104 	return store;
       
   105 	}
       
   106 
       
   107 CSimSmsStore::CSimSmsStore(CSimSmsMessaging* aSmsMess, CSimPhone* aPhone)
       
   108 		: iSmsMessaging(aSmsMess), iEvOutstandingReq(EFalse), iPhone(aPhone)
       
   109 /**
       
   110  * Trivial first phase constructor.
       
   111  * @param aSimSmsMess	The SMS Messaging object from which this SMS Store was opened.
       
   112  */
       
   113 	{}
       
   114 
       
   115 void CSimSmsStore::ConstructL(const TDesC8& aName, TInt aMaxNumSlots)
       
   116 /**
       
   117  * Second phase constructor that allocates memory for the SMS store, batch read buffer and
       
   118  * a delayed completion timer.  The constructor also reads the individual and batch read
       
   119  * delays from the configuration file.
       
   120  * 
       
   121  * @param aName			The name of the created SMS Store.
       
   122  * @param aMaxNumSlots	The maximum number of slots in the SMS Store.
       
   123  */
       
   124 	{
       
   125 	iGsmSmsStoreEntries=new(ELeave) RMobileSmsStore::TMobileGsmSmsEntryV1[aMaxNumSlots+1];//index 0 is not used
       
   126 	iSmsMaxNumSlots=aMaxNumSlots;
       
   127 	iSmsStoreName.Copy(aName);
       
   128 	iSmsReadAll=new(ELeave) CArrayPtrFlat<CListReadAllAttempt>(KSmsStoreGranularity);
       
   129 	LOGSMS1("Starting to parse SMS Store config parameters...");
       
   130 	iSmsIndividualPause=CfgFileSection()->ItemValue(KSmsStoreIndividualReqPause,KDefaultSmsStoreIndividualReqPause);
       
   131 	iSmsBatchPause=CfgFileSection()->ItemValue(KSmsStoreBatchReqPause,KDefaultSmsStoreBatchReqPause);
       
   132 	
       
   133 	const CTestConfigItem* item0=NULL;
       
   134 	item0=CfgFileSection()->Item(KSmsPhoneStoreCaps,0);
       
   135 	if (item0)
       
   136 		{
       
   137 		TPtrC8 value0;
       
   138 		TInt ret0=CTestConfig::GetElement(item0->Value(),KStdDelimiter,0,value0);
       
   139 		if(ret0!=KErrNone)
       
   140 			{
       
   141 			LOGPARSERR("value0",ret0,0,&KSmsPhoneStoreCaps);
       
   142 			iSmsStoreCaps=KDefaultSmsPhoneStoreCaps+KDefaultSmsOnlySmsCaps;
       
   143 			}
       
   144 		else
       
   145 			{
       
   146 			TUint32 intValue;
       
   147 			TInt ret = AsciiToNum(value0, intValue);
       
   148 			if(ret!=KErrNone)
       
   149 				iSmsStoreCaps=KDefaultSmsPhoneStoreCaps+KDefaultSmsOnlySmsCaps;
       
   150 			else
       
   151 				iSmsStoreCaps = intValue+KDefaultSmsOnlySmsCaps;
       
   152 			}
       
   153 		}
       
   154 	else
       
   155 		iSmsStoreCaps=KDefaultSmsPhoneStoreCaps+KDefaultSmsOnlySmsCaps;
       
   156 
       
   157 
       
   158 	LOGSMS1("...Finished parsing SMS Store config parameters");
       
   159 	iTimer=CSimTimer::NewL(iSmsMessaging->iPhone);
       
   160 	iIncomingTimer=CSimTimer::NewL(iSmsMessaging->iPhone);
       
   161 	}
       
   162 
       
   163 void CSimSmsStore::PopulateStoreFromConfigFile()
       
   164 /**
       
   165  * Populate the SMS Store from information in the configuration file.  This is performed
       
   166  * after the standard SMS Store construction in order to prevent reseting the configuation
       
   167  * file accessor class' pointers while possibly multiple SMS Stores are created.
       
   168  *
       
   169  * The store entries comply to the following format:
       
   170  * "SmsStoreEntry = <store name>, <slot number>, <entry status>, <pdu>"
       
   171  */
       
   172 	{
       
   173 	LOGSMS1("Starting reading SMS Store entries...");
       
   174 	TInt count=CfgFileSection()->ItemCount(KSmsStoreEntry);
       
   175 	const CTestConfigItem* item=NULL;
       
   176 	TInt ret=KErrNone;
       
   177 
       
   178 	for(TInt i=0;i<count;i++)
       
   179 		{
       
   180 		item=CfgFileSection()->Item(KSmsStoreEntry,i);
       
   181 		if(!item)
       
   182 			break;
       
   183 
       
   184 		TPtrC8 storeName;
       
   185 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,0,storeName);
       
   186 		if(ret!=KErrNone)
       
   187 			{
       
   188 			LOGPARSERR("storeName",ret,0,&KSmsStoreEntry);
       
   189 			continue;
       
   190 			}
       
   191 		if(storeName.MatchF(iSmsStoreName)!=0)
       
   192 			continue;						// Not this store
       
   193 
       
   194 		TInt index,stat;
       
   195 		TPtrC8 pdu;
       
   196 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,1,index);
       
   197 		if((ret!=KErrNone)||(index>=iSmsMaxNumSlots))
       
   198 			{
       
   199 			LOGPARSERR("index",ret,1,&KSmsStoreEntry);
       
   200 			continue;
       
   201 			}
       
   202 	
       
   203 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,2,stat);
       
   204 		if(ret!=KErrNone)
       
   205 			{
       
   206 			LOGPARSERR("stat",ret,2,&KSmsStoreEntry);
       
   207 			continue;
       
   208 			}
       
   209 
       
   210 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,3,pdu);
       
   211 		if(ret!=KErrNone)
       
   212 			{
       
   213 			LOGPARSERR("pdu",ret,3,&KSmsStoreEntry);
       
   214 			continue;
       
   215 			}
       
   216 
       
   217 		TPtrC8 sca;
       
   218 		ret=CTestConfig::GetElement(item->Value(),KStdDelimiter,4,sca);
       
   219 		if(ret!=KErrNone)
       
   220 			{
       
   221 			LOGPARSERR("sca",ret,4,&KSmsStoreEntry);
       
   222 			continue;
       
   223 			}
       
   224 		iGsmSmsStoreEntries[index].iIndex=index;
       
   225 		iGsmSmsStoreEntries[index].iMsgStatus=(RMobileSmsStore::TMobileSmsStoreStatus)stat;
       
   226 		ConvertAsciiSms(pdu,iGsmSmsStoreEntries[index].iMsgData);
       
   227 		RecordSca(sca, index);
       
   228 		}
       
   229 
       
   230 	LOGSMS1("...Finished reading SMS Store entries");
       
   231 	}
       
   232 
       
   233 
       
   234 
       
   235 void CSimSmsStore::RecordSca(const TDesC8& aAsciiAddr, TInt aIndex)
       
   236 /**
       
   237  * Used to set the sca number
       
   238  * 
       
   239  *
       
   240  * @param aAsciiSca Ascii representation of a telephone number such as the one found in the configuration file
       
   241  * @param aType specifies whether aAsciiAddres should be used to fill in the sca or destination field of the smsp entry
       
   242  * @param aIndex specifies at which index in the smsp list the number should be filled in
       
   243  */
       
   244 	{
       
   245 	if(aAsciiAddr.Length()>0)//only support for international numbers
       
   246 		{
       
   247 		iGsmSmsStoreEntries[aIndex].iServiceCentre.iNumberPlan=RMobilePhone::EIsdnNumberPlan;
       
   248 		iGsmSmsStoreEntries[aIndex].iServiceCentre.iTypeOfNumber=RMobilePhone::EInternationalNumber;
       
   249 		iGsmSmsStoreEntries[aIndex].iServiceCentre.iTelNumber.Copy(aAsciiAddr);
       
   250 		}
       
   251 	}
       
   252 
       
   253 CSimSmsStore::~CSimSmsStore()
       
   254 /**
       
   255  * Standard destructor.  Any objects created by the ::ConstructL() function
       
   256  * will be destroyed here.
       
   257  */
       
   258 	{
       
   259 	delete[] iGsmSmsStoreEntries;
       
   260 	
       
   261 	if (iSmsReadAll)
       
   262 		{
       
   263 		iSmsReadAll->ResetAndDestroy();
       
   264 		delete iSmsReadAll;
       
   265 		}
       
   266 
       
   267 	delete iTimer;
       
   268 	delete iIncomingTimer;
       
   269 	}
       
   270 
       
   271 #ifdef _DEBUG
       
   272 void CSimSmsStore::LogRequest(TBool aEntering, TInt aIpc, TInt aError)
       
   273 #else
       
   274 void CSimSmsStore::LogRequest(TBool aEntering, TInt aIpc, TInt /*aError*/)
       
   275 #endif
       
   276 /**
       
   277  * This method logs client requests to the t_reg.txt
       
   278  * @param aEntering Tells if the request is entering into simtsy tsy or completing
       
   279  * @param aIpc IPC number of request
       
   280  * @param aError Error code that the request has
       
   281  */
       
   282  	{
       
   283 	TBuf8<64> ipcBuf;
       
   284 
       
   285 	switch (aIpc)
       
   286 		{
       
   287 		case EMobilePhoneStoreGetInfo:
       
   288 			ipcBuf = _L8("GetInfo");
       
   289 			break;
       
   290 
       
   291 		case EMobilePhoneStoreNotifyStoreEvent:
       
   292 			ipcBuf = _L8("NotifyStoreEvent");
       
   293 			break;
       
   294 
       
   295 		case EMobilePhoneStoreRead:
       
   296 			ipcBuf = _L8("Read");
       
   297 			break;
       
   298 
       
   299 		case EMobilePhoneStoreWrite:
       
   300 			ipcBuf = _L8("Write");
       
   301 			break;
       
   302 
       
   303 		case EMobilePhoneStoreDelete:
       
   304 			ipcBuf = _L8("Delete");
       
   305 			break;
       
   306 
       
   307 		case EMobilePhoneStoreReadAllPhase1:
       
   308 			ipcBuf = _L8("ReadAllPhase1");
       
   309 			break;
       
   310 
       
   311 
       
   312 		case EMobilePhoneStoreReadAllPhase2:
       
   313 			ipcBuf = _L8("ReadAllPhase2");
       
   314 			break;
       
   315 
       
   316 		case EMobilePhoneStoreDeleteAll:
       
   317 			ipcBuf = _L8("DeleteAll");
       
   318 			break;		
       
   319 		
       
   320 		default:
       
   321 			ipcBuf = _L8("OTHER");
       
   322 			break;
       
   323 		}
       
   324 
       
   325 	if (aEntering!=EFalse)
       
   326 		{
       
   327 		LOGSMS3(">>%d,CSimSmsStore::%S",aIpc, &ipcBuf );
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		LOGSMS4("<<%d,CSimSmsStore::%S with error %d",aIpc, &ipcBuf, aError);
       
   332 		}
       
   333 	}
       
   334 
       
   335 
       
   336 
       
   337 
       
   338 TInt CSimSmsStore::ExtFunc(const TTsyReqHandle aReqHandle,const TInt aIpc, const TDataPackage& aPckg)
       
   339 /**
       
   340  * Dispatch function for all SMS Store requests.
       
   341  * @param aReqHandle	The TSY request handle for this request.
       
   342  * @param aIpc			The IPC number of this request.
       
   343  * @param aPckg			The parameter package related to this request.
       
   344  * @return TInt			The return error condition.
       
   345  */
       
   346 	{
       
   347 // The following requests can be completed even if the completion of another request is pending.
       
   348 	TInt ret=KErrNone;//error is only used with LogRequest when at the end of ExtFunc
       
   349 	LogRequest(ETrue, aIpc, ret);
       
   350 	switch(aIpc)
       
   351 		{
       
   352 	case EMobilePhoneStoreGetInfo:
       
   353 		ret = GetInfo(aReqHandle,aPckg.Des1n());
       
   354 		LogRequest(EFalse, aIpc, ret);
       
   355 		return ret;
       
   356 
       
   357 	case EMobilePhoneStoreNotifyStoreEvent:
       
   358 		ret =  NotifyStoreEvent(aReqHandle,aPckg.Des1n(),aPckg.Des2n());
       
   359 		LogRequest(EFalse, aIpc, ret);
       
   360 		return ret;
       
   361 
       
   362 	default:
       
   363 		break;
       
   364 		}
       
   365 	
       
   366 
       
   367 // The TSY can only process one of the following requests at a time.  If a second is received
       
   368 // while processing the first, then it will be errored with KErrInUse.  This restriction will
       
   369 // be removed later, by inserting a request queuing mechanism.  Note that the standard TSY
       
   370 // "flow control" mechanism works phone-wide and so is not suitable.
       
   371 
       
   372 	if(iTimer->IsActive())
       
   373 		{
       
   374 		ReqCompleted(aReqHandle,KErrInUse);
       
   375 		return KErrNone;
       
   376 		}
       
   377 
       
   378 	switch(aIpc)
       
   379 		{
       
   380 	case EMobilePhoneStoreRead:
       
   381 		ret = Read(aReqHandle,aPckg.Des1n());
       
   382 		break;
       
   383 
       
   384 	case EMobilePhoneStoreWrite:
       
   385 		ret = Write(aReqHandle,aPckg.Des1n());
       
   386 		break;
       
   387 
       
   388 	case EMobilePhoneStoreDelete:
       
   389 		ret = Delete(aReqHandle,aPckg.Des1n());
       
   390 		break;
       
   391 
       
   392 	case EMobilePhoneStoreReadAllPhase1:
       
   393 		ret = ReadAllPhase1(aReqHandle,aPckg.Des1n(),aPckg.Des2n());
       
   394 		break;
       
   395 
       
   396 	case EMobilePhoneStoreReadAllPhase2:
       
   397 		ret = ReadAllPhase2(aReqHandle,aPckg.Des1n(),aPckg.Des2n());
       
   398 		break;
       
   399 
       
   400 	case EMobilePhoneStoreDeleteAll:
       
   401 		ret = DeleteAll(aReqHandle);
       
   402 		break;
       
   403 
       
   404 	default:
       
   405 		return KErrNotSupported;
       
   406 		}
       
   407 	LogRequest(EFalse, aIpc, ret);
       
   408 	return ret;
       
   409 
       
   410 	}
       
   411 
       
   412 CTelObject* CSimSmsStore::OpenNewObjectByNameL(const TDesC& /*aName*/)
       
   413 /**
       
   414  * The API does not support any objects that could be opened from this one.
       
   415  */
       
   416 	{
       
   417 	User::Leave(KErrNotSupported);
       
   418 	return NULL;
       
   419 	}
       
   420 
       
   421 CTelObject* CSimSmsStore::OpenNewObjectL(TDes&)
       
   422 /**
       
   423  * The API does not support any objects that could be opened from this one.
       
   424  */
       
   425 	{
       
   426 	User::Leave(KErrNotSupported);
       
   427 	return NULL;
       
   428 	}
       
   429 
       
   430 CTelObject::TReqMode CSimSmsStore::ReqModeL(const TInt aIpc)
       
   431 /**
       
   432  * This function returns the Request Mode for the request with the passed IPC value.
       
   433  * @param aIpc		The IPC number of the request.
       
   434  * @return TReqMode	The request mode.
       
   435  */
       
   436 	{
       
   437 	CTelObject::TReqMode ret=0;	
       
   438 
       
   439 	switch(aIpc)
       
   440 		{
       
   441 	case EMobilePhoneStoreGetInfo:
       
   442 	case EMobilePhoneStoreRead:
       
   443 	case EMobilePhoneStoreWrite:
       
   444 	case EMobilePhoneStoreDelete:
       
   445 	case EMobilePhoneStoreReadAllPhase1:
       
   446 	case EMobilePhoneStoreReadAllPhase2:
       
   447 	case EMobilePhoneStoreDeleteAll:
       
   448 		break;
       
   449 
       
   450 	case EMobilePhoneStoreNotifyStoreEvent:
       
   451 		ret=KReqModeMultipleCompletionEnabled | KReqModeRePostImmediately;
       
   452 		break;
       
   453 
       
   454 	default:
       
   455 		User::Leave(KErrNotSupported);
       
   456 		break;
       
   457 		}
       
   458 
       
   459 	return ret;
       
   460 	}
       
   461 
       
   462 TInt CSimSmsStore::RegisterNotification(const TInt /*aIpc*/)
       
   463 /**
       
   464  * The ETel Server calls this function when the first client makes a notification
       
   465  * request.  If supported by the underlying protocol controlling the
       
   466  * signalling stack, this can be used to start requesting updates for the relevant
       
   467  * service.
       
   468  */
       
   469 	{
       
   470 	return KErrNone;
       
   471 	}
       
   472 
       
   473 TInt CSimSmsStore::DeregisterNotification(const TInt /*aIpc*/)
       
   474 /**
       
   475  * The ETel Server calls this function when the last client that had previously
       
   476  * made a notification request closes its ETel Server handle.  If supported by
       
   477  * the underlying protocol controlling the	signalling stack, this can be used
       
   478  * to stop requesting updates for the relevant service.
       
   479  */
       
   480 	{
       
   481 	return KErrNone;
       
   482 	}
       
   483 
       
   484 TInt CSimSmsStore::NumberOfSlotsL(const TInt /*aIpc*/)
       
   485 /**
       
   486  * Return the number of slots that the ETel Server should allocate for buffering requests
       
   487  * of the given IPC number.
       
   488  */
       
   489 	{
       
   490 	return KDefaultNumberOfSlots;
       
   491 	}
       
   492 
       
   493 TInt CSimSmsStore::CancelService(const TInt aIpc,const TTsyReqHandle /*aTsyReqHandle*/)
       
   494 /**
       
   495  * Cancel an outstanding request.
       
   496  * @param aIpc			The IPC number of the request that is to be cancelled.
       
   497  * @param aTsyReqHandle	The TSY request handle of the request that is to be cancelled.
       
   498  * @param TInt			Standard return value.
       
   499  */
       
   500 	{
       
   501 	switch(aIpc)
       
   502 		{
       
   503 	case EMobilePhoneStoreGetInfo:
       
   504 	case EMobilePhoneStoreRead:
       
   505 	case EMobilePhoneStoreWrite:
       
   506 	case EMobilePhoneStoreDelete:
       
   507 		if(iTimer->Running())
       
   508 			{
       
   509 			iTimer->Cancel();
       
   510 			ReqCompleted(iPendingReqCompletion,KErrCancel);
       
   511 			}
       
   512 		break;
       
   513 	case EMobilePhoneStoreReadAllPhase1:
       
   514 		ReadAllCancel();
       
   515 		break;
       
   516 	case EMobilePhoneStoreDeleteAll:
       
   517 		DeleteAllCancel();
       
   518 		break;
       
   519 	case EMobilePhoneStoreNotifyStoreEvent:
       
   520 		NotifyStoreEventCancel();
       
   521 		break;
       
   522 	default:
       
   523 		break;
       
   524 		}
       
   525 	return KErrNone;
       
   526 	}
       
   527 
       
   528 void CSimSmsStore::Init()
       
   529 /**
       
   530  *	This function can be used to perform any necessary synchronous initialisation.
       
   531  */
       
   532 	{
       
   533 	}
       
   534 
       
   535 TInt CSimSmsStore::GetInfo(TTsyReqHandle aReqHandle, TDes8* aPckg)
       
   536 /**
       
   537  * Retrieve SMS Store information. This request is completed immediately, as it is assumed
       
   538  * that in a real TSY, all this data will be cached in the TSY.
       
   539  *
       
   540  * @param aReqHandle	The TSY request handle associated with this request.
       
   541  * @param aPckg			The parameter package associated with this request.
       
   542  */
       
   543 	{
       
   544 	RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg* getInfoPckg=(RMobilePhoneStore::TMobilePhoneStoreInfoV1Pckg*)aPckg;
       
   545 	RMobilePhoneStore::TMobilePhoneStoreInfoV1& getInfo=(*getInfoPckg)();
       
   546 
       
   547 	// Check that the data structure is supported by the simulated TSY version
       
   548 	TInt err = iPhone->CheckSimTsyVersion(getInfo);
       
   549 	if(err != KErrNone)
       
   550 		{
       
   551 		ReqCompleted(aReqHandle, err);
       
   552 		return KErrNone;
       
   553 		}
       
   554 
       
   555 	getInfo.iType=RMobilePhoneStore::EShortMessageStore;
       
   556 	getInfo.iTotalEntries=MaxSlots();
       
   557 	getInfo.iCaps=iSmsStoreCaps;
       
   558 	getInfo.iName.Copy(iSmsStoreName);
       
   559 	getInfo.iUsedEntries=UsedEntries();
       
   560 
       
   561 	ReqCompleted(aReqHandle,KErrNone);
       
   562 	return KErrNone;
       
   563 	}
       
   564 
       
   565 TInt CSimSmsStore::Read(TTsyReqHandle aReqHandle, TDes8* aPckg)
       
   566 /**
       
   567  * Read a single SMS store entry.  The completion of this request is delayed in order to
       
   568  * simulate a real TSY that would have to go and get the information from a SIM card.
       
   569  *
       
   570  * @param aReqHandle	The TSY request handle associated with this request.
       
   571  * @param aPckg			The parameter package associated with this request.
       
   572  */
       
   573 	{
       
   574 	if (!(iSmsStoreCaps & RMobilePhoneStore::KCapsIndividualEntry && iSmsStoreCaps & RMobilePhoneStore::KCapsReadAccess))
       
   575 		{
       
   576 		ReqCompleted(aReqHandle, KErrAccessDenied);
       
   577 		return KErrNone;
       
   578 		}
       
   579 
       
   580 	RMobileSmsStore::TMobileSmsEntryV1Pckg* smsPckg=(RMobileSmsStore::TMobileSmsEntryV1Pckg*)aPckg;	
       
   581 	RMobileSmsStore::TMobileSmsEntryV1& sms=(*smsPckg)();
       
   582 		
       
   583 	// Check that the data structure is supported by the simulated TSY version
       
   584 	TInt err = iPhone->CheckSimTsyVersion(sms);
       
   585 	if(err != KErrNone)
       
   586 		{
       
   587 		ReqCompleted(aReqHandle, err);
       
   588 		return KErrNone;
       
   589 		}
       
   590 
       
   591 	switch (sms.ExtensionId())
       
   592 		{
       
   593 		case RMobileSmsStore::KETelMobileGsmSmsEntryV1:
       
   594 			{
       
   595 			RMobileSmsStore::TMobileGsmSmsEntryV1Pckg* gsmSmsPckg=(RMobileSmsStore::TMobileGsmSmsEntryV1Pckg*)aPckg;
       
   596 			RMobileSmsStore::TMobileGsmSmsEntryV1& gsmSms=(*gsmSmsPckg)();
       
   597 
       
   598 			// Check that the data structure is supported by the simulated TSY version
       
   599 			TInt err = iPhone->CheckSimTsyVersion(gsmSms);
       
   600 			if(err != KErrNone)
       
   601 				{
       
   602 				ReqCompleted(aReqHandle, err);
       
   603 				return KErrNone;
       
   604 				}
       
   605 
       
   606 			TInt& index=gsmSms.iIndex;
       
   607 			if((index<1)||(index>iSmsMaxNumSlots))
       
   608 				{
       
   609 				ReqCompleted(aReqHandle,KErrArgument);
       
   610 				return KErrNone;
       
   611 				}
       
   612 				
       
   613 			if (iGsmSmsStoreEntries[index].iMsgStatus == KCorruptPDU)
       
   614 				{
       
   615 				ReqCompleted(aReqHandle,KErrCorrupt);
       
   616 				return KErrNone;			    
       
   617 				}
       
   618 
       
   619 			if(iGsmSmsStoreEntries[index].iMsgData.Length()==0)
       
   620 				{
       
   621 				ReqCompleted(aReqHandle, KErrNotFound);
       
   622 				return KErrNone;
       
   623 				}
       
   624 
       
   625 			gsmSms.iMsgData.Copy(iGsmSmsStoreEntries[index].iMsgData);
       
   626 			gsmSms.iMsgStatus=iGsmSmsStoreEntries[index].iMsgStatus;
       
   627 			gsmSms.iServiceCentre=iGsmSmsStoreEntries[index].iServiceCentre;
       
   628 			break;
       
   629 			}
       
   630 		case RMobileSmsStore::KETelMobileCdmaSmsEntryV1:
       
   631 			 ReqCompleted(aReqHandle,KErrNotSupported);
       
   632 			 return KErrNone;	
       
   633 
       
   634 		default:
       
   635 			ReqCompleted(aReqHandle,KErrArgument);
       
   636 			return KErrNone;
       
   637 		}
       
   638 	
       
   639 	DelayCompletion(iSmsIndividualPause,aReqHandle);
       
   640 	return KErrNone;
       
   641 	}
       
   642 
       
   643 TInt CSimSmsStore::Write(TTsyReqHandle aReqHandle,TDes8* aPckg)
       
   644 /**
       
   645  * Write a single SMS store entry.  The completion of this request is delayed in order to
       
   646  * simulate a real TSY that would have to write the information to a SIM card. A store
       
   647  * event may be triggered by this request.
       
   648  *
       
   649  * @param aReqHandle	The TSY request handle associated with this request.
       
   650  * @param aPckg			The parameter package associated with this request.
       
   651  */
       
   652 	{
       
   653 	if (!(iSmsStoreCaps & RMobilePhoneStore::KCapsIndividualEntry && iSmsStoreCaps & RMobilePhoneStore::KCapsWriteAccess))
       
   654 		{
       
   655 		ReqCompleted(aReqHandle, KErrAccessDenied);
       
   656 		return KErrNone;
       
   657 		}
       
   658 
       
   659 	TStoreEvent event=EStoreEventNoEvent;
       
   660 	TInt index;
       
   661 
       
   662 	RMobileSmsStore::TMobileSmsEntryV1Pckg* smsPckg=(RMobileSmsStore::TMobileSmsEntryV1Pckg*)aPckg;	
       
   663 	RMobileSmsStore::TMobileSmsEntryV1& sms=(*smsPckg)();
       
   664 		
       
   665 	// Check that the data structure is supported by the simulated TSY version
       
   666 	TInt err = iPhone->CheckSimTsyVersion(sms);
       
   667 	if(err != KErrNone)
       
   668 		{
       
   669 		ReqCompleted(aReqHandle, err);
       
   670 		return KErrNone;
       
   671 		}
       
   672 
       
   673 	switch (sms.ExtensionId())
       
   674 		{
       
   675 		case RMobileSmsStore::KETelMobileGsmSmsEntryV1:
       
   676 			{
       
   677 			RMobileSmsStore::TMobileGsmSmsEntryV1Pckg* gsmSmsPckg=(RMobileSmsStore::TMobileGsmSmsEntryV1Pckg*)aPckg;
       
   678 			RMobileSmsStore::TMobileGsmSmsEntryV1& gsmSms=(*gsmSmsPckg)();
       
   679 
       
   680 			// Check that the data structure is supported by the simulated TSY version
       
   681 			TInt err = iPhone->CheckSimTsyVersion(gsmSms);
       
   682 			if(err != KErrNone)
       
   683 				{
       
   684 				ReqCompleted(aReqHandle, err);
       
   685 				return KErrNone;
       
   686 				}
       
   687 
       
   688 			index=gsmSms.iIndex;
       
   689 			if(index==-1)//check the 1st free slot
       
   690 				{
       
   691 				for(TInt i=1;i<=iSmsMaxNumSlots;i++)
       
   692 					{
       
   693 					if(iGsmSmsStoreEntries[i].iMsgData.Length()==0)
       
   694 						{
       
   695 						index=i;
       
   696 						//ret = KErrNone;
       
   697 						break;
       
   698 						}
       
   699 					}
       
   700 				}
       
   701 			//else ret = KErrNone;//if index is specified entry will be overwitten, not possible to exceed memory
       
   702 			if((index<1)||(index>iSmsMaxNumSlots))
       
   703 				{
       
   704 				ReqCompleted(aReqHandle,KErrArgument);
       
   705 				return KErrNone;
       
   706 				}
       
   707 
       
   708 			//
       
   709 			// This can never happen because either ret is KErrNone or
       
   710 			// index is still -1 and we have returned.
       
   711 			// 
       
   712 				//if (ret==KErrNoMemory)
       
   713 					//ReqCompleted(aReqHandle,ret);
       
   714 
       
   715 			if(iGsmSmsStoreEntries[index].iMsgData.Length()==0)
       
   716 				event=EStoreEventAdded;
       
   717 			else
       
   718 				event=EStoreEventChanged;
       
   719 
       
   720 			gsmSms.iIndex = index;		// Update index data member for the client
       
   721 			iGsmSmsStoreEntries[index].iIndex=index;
       
   722 			iGsmSmsStoreEntries[index].iMsgData.Copy(gsmSms.iMsgData);
       
   723 			iGsmSmsStoreEntries[index].iMsgStatus=gsmSms.iMsgStatus;
       
   724 			iGsmSmsStoreEntries[index].iServiceCentre=gsmSms.iServiceCentre;
       
   725 			break;
       
   726 			}
       
   727 		case RMobileSmsStore::KETelMobileCdmaSmsEntryV1:
       
   728 			 ReqCompleted(aReqHandle,KErrNotSupported);
       
   729 			 return KErrNone;		
       
   730 
       
   731 		default:
       
   732 			ReqCompleted(aReqHandle,KErrArgument);
       
   733 			return KErrNone;
       
   734 		}
       
   735 
       
   736 	DelayCompletion(iSmsIndividualPause,aReqHandle,event,index);
       
   737 	return KErrNone;
       
   738 	}
       
   739 
       
   740 TInt CSimSmsStore::StoreIncomingMessage(RMobileSmsStore::TMobileGsmSmsEntryV1* aSms)
       
   741 /**
       
   742  * This method is used to store Incoming sms messages with the status EMtMessageStored
       
   743  * It is accessed by CSimSmsMessaging::AttemptSmsRxCompleteL.
       
   744  * Note: this will not call ReqComplete as no client request has been posted on this class
       
   745  * Note: the smsStack will delete the message from the store after ReceiveMessage has completed
       
   746  **/
       
   747 	{
       
   748 	
       
   749 	TInt& index=aSms->iIndex;
       
   750 	TInt ret=KErrNoMemory;
       
   751 	TStoreEvent event=EStoreEventNoEvent;
       
   752 	for(TInt i=1;i<=iSmsMaxNumSlots;i++)
       
   753 		{
       
   754 		if(iGsmSmsStoreEntries[i].iMsgData.Length()==0)
       
   755 			{
       
   756 			index=i;
       
   757 			event=EStoreEventAdded;
       
   758 			ret = KErrNone;
       
   759 			break;
       
   760 			}
       
   761 			
       
   762 		}
       
   763 
       
   764 	aSms->iIndex=index;//set here to be used by CSimSmsMessaging
       
   765 	
       
   766 	if (ret==KErrNone)
       
   767 		{
       
   768 		iGsmSmsStoreEntries[index].iIndex=index;
       
   769 		iGsmSmsStoreEntries[index].iMsgData.Copy(aSms->iMsgData);
       
   770 		iGsmSmsStoreEntries[index].iMsgStatus=aSms->iMsgStatus;
       
   771 		iGsmSmsStoreEntries[index].iServiceCentre=aSms->iServiceCentre;
       
   772 
       
   773 		iPendingEvent=event;
       
   774 		iPendingIndex=index;
       
   775 		iIncomingTimer->Start(iSmsIndividualPause,this, 1);//delay the notification 
       
   776 		}
       
   777 
       
   778 	return ret;
       
   779 	}
       
   780 
       
   781 
       
   782 TInt CSimSmsStore::Delete(TTsyReqHandle aReqHandle,TDes8* aPckg)
       
   783 /**
       
   784  * Delete a single SMS store entry.  The completion of this request is delayed in order to
       
   785  * simulate a real TSY that would have to write the information to a SIM card. A store
       
   786  * event may be triggered by this request.
       
   787  *
       
   788  * @param aReqHandle	The TSY request handle associated with this request.
       
   789  * @param aPckg			The parameter package associated with this request.
       
   790  * @return				Standard return value.
       
   791  */
       
   792 	{
       
   793 	if (!(iSmsStoreCaps & RMobilePhoneStore::KCapsIndividualEntry && iSmsStoreCaps & RMobilePhoneStore::KCapsWriteAccess))
       
   794 		{
       
   795 		ReqCompleted(aReqHandle, KErrAccessDenied);
       
   796 		return KErrNone;
       
   797 		}
       
   798 
       
   799 	TPckg<TInt>* intPckg=(TPckg<TInt>*)aPckg;
       
   800 	TInt& index=(*intPckg)();
       
   801 
       
   802 	if((index<1)||(index>iSmsMaxNumSlots))
       
   803 		{
       
   804 		ReqCompleted(aReqHandle,KErrArgument);
       
   805 		return KErrNone;
       
   806 		}
       
   807 
       
   808 	iGsmSmsStoreEntries[index].iMsgData.Zero();
       
   809 	iGsmSmsStoreEntries[index].iMsgStatus=RMobileSmsStore::EStoredMessageUnknownStatus;
       
   810 	iGsmSmsStoreEntries[index].iServiceCentre.iTelNumber=KNullTelephoneNumber;
       
   811 	
       
   812 	DelayCompletion(iSmsIndividualPause,aReqHandle,EStoreEventDeleted,index);
       
   813 	return KErrNone;
       
   814 	}
       
   815 
       
   816 TInt CSimSmsStore::ReadAllPhase1(TTsyReqHandle aReqHandle,TDes8* aPckg1,TDes8* aPckg2)
       
   817 /**
       
   818  * First phase of a batch SMS Store read.  The completion of this request is delayed in
       
   819  * order to simulate a real TSY that would have to get the information from a SIM card.
       
   820  * If the GetSmspListPhase1L should leave this method takes care of that and 
       
   821  * makes a premature ReqCompleted to the client.
       
   822  * 
       
   823  * @param aReqHandle	The TSY request handle associated with this request.
       
   824  * @param aPckg1		The first parameter package associated with this request.
       
   825  *						It contains the client ID information required to uniquely identify this request.
       
   826  *						It also contains the batch read information (first slot, number of slots).
       
   827  * @param aPckg2		The parameter package associated with this request.
       
   828  *						The size of the information to be passed back to the client is returned in this package.
       
   829  * @return				Standard return value.
       
   830  */	{
       
   831  	if (!(iSmsStoreCaps & static_cast<TUint32>(RMobilePhoneStore::KCapsWholeStore) && iSmsStoreCaps & RMobilePhoneStore::KCapsReadAccess))
       
   832 		{
       
   833 		ReqCompleted(aReqHandle, KErrAccessDenied);
       
   834 		return KErrNone;
       
   835 		}
       
   836 		
       
   837 
       
   838 	TPckg<CRetrieveMobilePhoneSmsList::TBatchRequestData>* clientIdPckg=(TPckg<CRetrieveMobilePhoneSmsList::TBatchRequestData>*) aPckg1;
       
   839 	CRetrieveMobilePhoneSmsList::TBatchRequestData& clientId=(*clientIdPckg)();
       
   840 	TPckg<TInt>* sizePckg=(TPckg<TInt>*)aPckg2;
       
   841 	TInt& size=(*sizePckg)();
       
   842 
       
   843 	TRAPD(leaveCode,ReadAllPhase1L(aReqHandle,clientId,size));
       
   844 
       
   845 	return leaveCode;
       
   846 	}
       
   847 
       
   848 
       
   849 
       
   850 
       
   851 void CSimSmsStore::ReadAllPhase1L(TTsyReqHandle aReqHandle,CRetrieveMobilePhoneSmsList::TBatchRequestData& aClientId, 
       
   852 											 TInt& aBufSize)
       
   853 /**
       
   854  * Implementation of ReadAllPhase1. 
       
   855  *
       
   856  */
       
   857 
       
   858 	{
       
   859 	TInt cnt=0;
       
   860 	CMobilePhoneListBase* listBase = NULL;
       
   861 
       
   862 	if ((CSimTsyMode::GetMode() != CSimTsyMode::ECdmaV1) &&
       
   863 		(aClientId.iEntryType == RMobileSmsStore::KETelMobileGsmSmsEntryV1))
       
   864 		{
       
   865 		listBase = CMobilePhoneGsmSmsList::NewL();
       
   866 		}
       
   867 	else
       
   868 		{
       
   869 		// Nothing to read.
       
   870 		ReqCompleted(aReqHandle, KErrNone);
       
   871 		return;
       
   872 		}
       
   873 
       
   874 	CleanupStack::PushL(listBase);
       
   875 
       
   876 	if(!aClientId.iBatchRequest)
       
   877 		{
       
   878 		aClientId.iStartIndex=1;
       
   879 		aClientId.iBatchSize=iSmsMaxNumSlots;
       
   880 		}
       
   881 
       
   882 	for(TInt i = aClientId.iStartIndex; cnt < aClientId.iBatchSize; i++)
       
   883 		{
       
   884 		if (i > iSmsMaxNumSlots)
       
   885 			break;
       
   886 		
       
   887 		if (aClientId.iEntryType == RMobileSmsStore::KETelMobileGsmSmsEntryV1)
       
   888 			{
       
   889 			if (iGsmSmsStoreEntries[i].iMsgData.Length() != 0)
       
   890 				{
       
   891 				((CMobilePhoneGsmSmsList*)listBase)->AddEntryL(iGsmSmsStoreEntries[i]);
       
   892 				cnt++;
       
   893 				}
       
   894 			}
       
   895 
       
   896 		}
       
   897 
       
   898 	// Store the streamed list and the client ID
       
   899 	CListReadAllAttempt* read=CListReadAllAttempt::NewL(aClientId.iClient, aReqHandle);
       
   900 	CleanupStack::PushL(read);
       
   901 
       
   902 	read->iListBuf = listBase->StoreLC();
       
   903 	CleanupStack::Pop(); // pop the CBufFlat allocated by StoreLC
       
   904 
       
   905 	iSmsReadAll->AppendL(read);
       
   906 	CleanupStack::Pop(); // pop the CListReadAllAttempt
       
   907 	
       
   908 	// return the CBufFlat’s size to client			
       
   909 	aBufSize=(read->iListBuf)->Size();		
       
   910 	
       
   911 	CleanupStack::PopAndDestroy(); // pop&destroy list
       
   912 	// Complete first phase of list retrieval
       
   913 
       
   914 	DelayCompletion(iSmsBatchPause,aReqHandle);
       
   915 //	return KErrNone;
       
   916 	}
       
   917 
       
   918 TInt CSimSmsStore::ReadAllPhase2(TTsyReqHandle aReqHandle,TDes8* aPckg1,TDes8* aBuffer)
       
   919 /**
       
   920  * Second phase of a batch SMS Store read.  The completion of this request is not delayed
       
   921  * as it is assumed that the TSY has already cached the required information (during the
       
   922  * first phase of the read).
       
   923  *
       
   924  * @param aReqHandle	The TSY request handle associated with this request.
       
   925  * @param aPckg1		The first parameter package associated with this request.
       
   926  *						It contains the client ID information required to uniquely identify this request.
       
   927  * @param aBuffer		The parameter package associated with this request.
       
   928  *						It contains the read buffer in which the required information is returned.
       
   929  * @return				Standard return value.
       
   930  */
       
   931 	{
       
   932 	TPckg<RMobilePhone::TClientId>* clientIdPckg=(TPckg<RMobilePhone::TClientId>*) aPckg1;
       
   933 	RMobilePhone::TClientId& clientId=(*clientIdPckg)();
       
   934 
       
   935 	for (TInt i=0; i<iSmsReadAll->Count(); ++i)
       
   936 		{
       
   937 		CListReadAllAttempt* read = iSmsReadAll->At(i);
       
   938 		if ((read->iClient.iSessionHandle==clientId.iSessionHandle) &&
       
   939 		    (read->iClient.iSubSessionHandle==clientId.iSubSessionHandle))
       
   940 			{
       
   941 			TPtr8 bufPtr((read->iListBuf)->Ptr(0));
       
   942 			// Copy the streamed list to the client
       
   943 			aBuffer->Copy(bufPtr);
       
   944 			delete read;
       
   945 			iSmsReadAll->Delete(i);
       
   946 			ReqCompleted(aReqHandle,KErrNone);
       
   947 			return KErrNone;
       
   948 			}
       
   949 		}
       
   950 
       
   951 // Don't delay completion of this request, as we assume the TSY will have the results in
       
   952 // memory from the first request.
       
   953 	ReqCompleted(aReqHandle,KErrNotFound);
       
   954 	return KErrNone;
       
   955 	}
       
   956 
       
   957 TInt CSimSmsStore::DeleteAll(TTsyReqHandle aReqHandle)
       
   958 /**
       
   959  * Delete all entries in the SIM Store.  The completion of this function is delayed in
       
   960  * order to simulate the SIM operations a real TSY would have to carry out.  This function
       
   961  * may trigger an SMS Store notification.
       
   962  *
       
   963  * @param aReqHandle	The TSY request handle associated with this request.
       
   964  * @return				Standard return value.
       
   965  */
       
   966 	{
       
   967 	if (!(iSmsStoreCaps & static_cast<TUint32>(RMobilePhoneStore::KCapsWholeStore) && iSmsStoreCaps & RMobilePhoneStore::KCapsWriteAccess))
       
   968 		{
       
   969 		ReqCompleted(aReqHandle, KErrAccessDenied);
       
   970 		return KErrNone;
       
   971 		}
       
   972 
       
   973 	for(TInt i=1;i<=iSmsMaxNumSlots;i++)
       
   974 		{
       
   975 	
       
   976 			iGsmSmsStoreEntries[i].iIndex=i;
       
   977 			iGsmSmsStoreEntries[i].iMsgStatus=RMobileSmsStore::EStoredMessageUnknownStatus;
       
   978 			iGsmSmsStoreEntries[i].iMsgData.Zero();
       
   979 			iGsmSmsStoreEntries[i].iServiceCentre.iTelNumber=KNullTelephoneNumber;
       
   980 			
       
   981 		}
       
   982 
       
   983 	DelayCompletion(iSmsBatchPause,aReqHandle,EStoreEventDeleted,-1);
       
   984 	return KErrNone;
       
   985 	}
       
   986 
       
   987 TInt CSimSmsStore::NotifyStoreEvent(TTsyReqHandle aReqHandle,TDes8* aPckg1,TDes8* aPckg2)
       
   988 /**
       
   989  * Register a client's interest in SMS Store events.
       
   990  *
       
   991  * @param aReqHandle	The TSY request handle associated with this request.
       
   992  * @param aPckg1		The first parameter package associated with this request.
       
   993  *						It contains the event flags that will be returned to the client.
       
   994  * @param aPckg2		The second parameter package associated with this request.
       
   995  *						It contains the index value associated with the event
       
   996  *						that will be returned to the client.
       
   997  * @return				Standard return value.
       
   998  */
       
   999 	{
       
  1000 	if (!(iSmsStoreCaps & RMobilePhoneStore::KCapsNotifyEvent))
       
  1001 		{
       
  1002 		ReqCompleted(aReqHandle, KErrNotSupported);
       
  1003 		return KErrNone;
       
  1004 		}
       
  1005 
       
  1006 	__ASSERT_ALWAYS(iEvOutstandingReq==EFalse,SimPanic(ENotificationAlreadyPending));
       
  1007 	
       
  1008 	TPckg<TUint32>* eventPckg=(TPckg<TUint32>*)aPckg1;
       
  1009 	TUint32& event=(*eventPckg)();
       
  1010 	TPckg<TInt>* indexPckg=(TPckg<TInt>*)aPckg2;
       
  1011 	TInt& index=(*indexPckg)();
       
  1012 
       
  1013 	iEvOutstandingReq=ETrue;
       
  1014 	iEvReqHandle=aReqHandle;
       
  1015 	iEvEvent=&event;
       
  1016 	iEvIndex=&index;
       
  1017 	return KErrNone;
       
  1018 	}
       
  1019 
       
  1020 void CSimSmsStore::NotifyStoreEventCancel()
       
  1021 /**
       
  1022  * Cancel an outstanding notify store request.
       
  1023  */
       
  1024 	{
       
  1025 	if(iEvOutstandingReq)
       
  1026 		{
       
  1027 		iEvOutstandingReq=EFalse;
       
  1028 		ReqCompleted(iEvReqHandle,KErrCancel);
       
  1029 		}
       
  1030 	}
       
  1031 
       
  1032 //coverity[bad_override]
       
  1033 TPtrC8 CSimSmsStore::Name()
       
  1034 /**
       
  1035  * Accessor function fot the SMS Store name.
       
  1036  *
       
  1037  * @return TPtrC8	The name of this SMS Store.
       
  1038  */
       
  1039 	{
       
  1040 	return iSmsStoreName;
       
  1041 	}
       
  1042 
       
  1043 TInt CSimSmsStore::UsedEntries()
       
  1044 /**
       
  1045  * Count the number of used entries in the SMS Store.
       
  1046  * @return TInt	The number of used entries in the store.
       
  1047  */
       
  1048 	{
       
  1049 	TInt cnt=0;
       
  1050 	for(TInt i=1;i<=iSmsMaxNumSlots;i++)
       
  1051 		{
       
  1052 		if(iGsmSmsStoreEntries[i].iMsgData.Length()!=0)
       
  1053 		cnt++;		
       
  1054 		}
       
  1055 	return cnt;
       
  1056 	}
       
  1057 
       
  1058 TInt CSimSmsStore::MaxSlots()
       
  1059 /**
       
  1060  * Retrieve the maximum number of slots in this SMS Store.
       
  1061  * @return TInt	The maximum number of slots in this SMS Store.
       
  1062  */
       
  1063 	{
       
  1064 	return iSmsMaxNumSlots;
       
  1065 	}
       
  1066 
       
  1067 void CSimSmsStore::DelayCompletion(TInt aDelayDuration,TTsyReqHandle aReqHandle)
       
  1068 /**
       
  1069  * A shell function for functions that wish to delay completion but do not trigger store
       
  1070  * events.
       
  1071  */
       
  1072 	{
       
  1073 	DelayCompletion(aDelayDuration,aReqHandle,EStoreEventNoEvent,0);
       
  1074 	}
       
  1075 
       
  1076 TUint CSimSmsStore::StoreCaps()
       
  1077 	{
       
  1078 	return iSmsStoreCaps;
       
  1079 	}
       
  1080 
       
  1081 void CSimSmsStore::DelayCompletion(TInt aDelayDuration,TTsyReqHandle aReqHandle,TStoreEvent aEvent,TInt aIndex)
       
  1082 /**
       
  1083  * Delay the completion of a TSY request.  It is assumed that the member variable
       
  1084  * manipulation associated with the request has already taken place, and so all that is
       
  1085  * left to do is call the ETel server's request completion function when the timer expires.
       
  1086  * So, just record the parameters and kick off the timer.
       
  1087  *
       
  1088  * @param aDelayDuration	The time (in seconds) for which the request completion is to be delayed.
       
  1089  * @param aReqHandle		The TSY request handle related to the delayed completion.
       
  1090  * @param aEvent			The store event related to the delayed completion.
       
  1091  * @param aIndex			The index related to the event passed in aEvent.
       
  1092  */
       
  1093 	{
       
  1094 	iPendingReqCompletion=aReqHandle;
       
  1095 	iPendingEvent=aEvent;
       
  1096 	iPendingIndex=aIndex;
       
  1097 	iTimer->Start(aDelayDuration,this);
       
  1098 	}
       
  1099 
       
  1100 
       
  1101 void CSimSmsStore::ReadAllCancel()
       
  1102 /*
       
  1103  * Cancel an outstanding read/write smsp.
       
  1104  */
       
  1105 	{
       
  1106 	iTimer->Cancel();
       
  1107 	ReqCompleted(iPendingReqCompletion,KErrCancel);
       
  1108 	}
       
  1109 
       
  1110 void CSimSmsStore::DeleteAllCancel()
       
  1111 /*
       
  1112  * Cancel an outstanding read/write smsp.
       
  1113  */
       
  1114 	{
       
  1115 	iTimer->Cancel();
       
  1116 	ReqCompleted(iPendingReqCompletion,KErrNone);//The timer is cancelled but data has already been deleted
       
  1117 	}
       
  1118 
       
  1119 void CSimSmsStore::TimerCallBack(TInt aId)
       
  1120 /**
       
  1121  * Process a timer call back event.  The timer is used to kick requests which have had their
       
  1122  * completions delayed.
       
  1123  */
       
  1124 	{
       
  1125 	StoreEvent(iPendingEvent,iPendingIndex);
       
  1126 	if (aId!=1)//aId is 1 if reuest is StoreIncomingMessage(coming from CSimSmsMessaging)
       
  1127 		ReqCompleted(iPendingReqCompletion,KErrNone);
       
  1128 	}
       
  1129 
       
  1130 void CSimSmsStore::StoreEvent(TStoreEvent aEvent,TInt aIndex)
       
  1131 /**
       
  1132  * Determine if a store event notification should be completed.
       
  1133  * @param aEvent	The store event.
       
  1134  * @param aIndex	The index related to the store event.
       
  1135  */
       
  1136 	{
       
  1137 	if(iEvOutstandingReq)
       
  1138 		{
       
  1139 		TUint event=0;
       
  1140 		switch(aEvent)
       
  1141 			{
       
  1142 		case EStoreEventNoEvent:
       
  1143 			return;
       
  1144 		
       
  1145 		case EStoreEventAdded:
       
  1146 			event|=RMobilePhoneStore::KStoreEntryAdded;
       
  1147 			break;
       
  1148 
       
  1149 		case EStoreEventDeleted:
       
  1150 			event|=RMobilePhoneStore::KStoreEntryDeleted;
       
  1151 			break;
       
  1152 
       
  1153 		case EStoreEventChanged:
       
  1154 			event|=RMobilePhoneStore::KStoreEntryChanged;
       
  1155 			break;
       
  1156 			}
       
  1157 
       
  1158 		if(UsedEntries()==0)
       
  1159 			event|=RMobilePhoneStore::KStoreEmpty;
       
  1160 
       
  1161 		if(UsedEntries()==iSmsMaxNumSlots)
       
  1162 			event|=RMobilePhoneStore::KStoreFull;
       
  1163 		else
       
  1164 			event|=RMobilePhoneStore::KStoreHasSpace;
       
  1165 
       
  1166 		*iEvEvent=event;
       
  1167 		*iEvIndex=aIndex;
       
  1168 		iEvOutstandingReq=EFalse;
       
  1169 		ReqCompleted(iEvReqHandle,KErrNone);
       
  1170 		}
       
  1171 	}
       
  1172 
       
  1173 const CTestConfigSection* CSimSmsStore::CfgFileSection()
       
  1174 /**
       
  1175 * Returns a pointer to the config file section
       
  1176 *
       
  1177 * @return CTestConfigSection a pointer to the configuration file data section
       
  1178 */
       
  1179 	{
       
  1180 	LOGSMS1(">>CSimSmsStore::CfgFileSection");
       
  1181 	return iSmsMessaging->CfgFileSection();
       
  1182 	}
       
  1183