messagingappbase/smsmtm/clientmtm/src/smutsimparam.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 // Copyright (c) 1999-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 // smutsimparam.cpp
       
    15 //
       
    16 #include <smutsimparam.h>
       
    17 
       
    18 #include <mmlist.h>
       
    19 
       
    20 #include "SMCMMAIN.H"
       
    21 #include <smscmds.h>
       
    22 #include "SMUTSET.H"
       
    23 
       
    24 /**
       
    25 The UID for the stream into which the SIM parameters are stored.
       
    26 
       
    27 @internalComponent
       
    28 @deprecated
       
    29 Should be moved to the cpp file for this class.
       
    30 */
       
    31 const TUid KUidMsvSimSmsParams = {0x100081BC};
       
    32 
       
    33 /**
       
    34 Creates an operation that reads the SMS parameters from the SIM.
       
    35 
       
    36 @param	aMtm
       
    37 The UID for the SMS MTM.
       
    38 
       
    39 @param	aService
       
    40 The SMS Service settings Id.
       
    41 
       
    42 @param	aMsvSession
       
    43 A message server session.
       
    44 
       
    45 @param	aObserverRequestStatus
       
    46 The observer status to be completed.
       
    47 
       
    48 @return
       
    49 The operation encapsulating reading the SIM parameters. 
       
    50 
       
    51 @post
       
    52 The SMS parameters are stored in iSimParams.
       
    53 
       
    54 @internalComponent
       
    55 */
       
    56 CSmsSimParamOperation* CSmsSimParamOperation::ReadSimParamsL(TUid aMtm, TMsvId aService, CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus)
       
    57 	{
       
    58 	CSmsSimParamOperation* self = new (ELeave) CSmsSimParamOperation(aMtm, aService, aMsvSession, aObserverRequestStatus);
       
    59 	CleanupStack::PushL(self);
       
    60 	
       
    61 	self->iSimParams = CMobilePhoneSmspList::NewL();
       
    62 	self->iState = EStateReadingSimParams;
       
    63 	self->DoReadSimParamsL();
       
    64 	
       
    65 	CleanupStack::Pop(self);
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 /**
       
    70 Creates an operation that writes the SMS parameters to the SIM.
       
    71 
       
    72 @param	aList
       
    73 The list of SIM parameters to be written.
       
    74 
       
    75 @param	aMtm
       
    76 The UID for the SMS MTM.
       
    77 
       
    78 @param	aService
       
    79 The SMS Service settings Id.
       
    80 
       
    81 @param	aMsvSession
       
    82 A message server session.
       
    83 
       
    84 @param	aObserverRequestStatus
       
    85 The observer status to be completed.
       
    86 
       
    87 @return
       
    88 The operation encapsulating writing the SIM parameters. 
       
    89 
       
    90 @post
       
    91 The SMS parameters are stored in the SIM.
       
    92 
       
    93 @internalComponent
       
    94 */
       
    95 CSmsSimParamOperation* CSmsSimParamOperation::WriteSimParamsL(const CMobilePhoneSmspList& aList, TUid aMtm, TMsvId aService, CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus)
       
    96 	{
       
    97 	CSmsSimParamOperation* self = new (ELeave) CSmsSimParamOperation(aMtm, aService, aMsvSession, aObserverRequestStatus);
       
    98 	CleanupStack::PushL(self);
       
    99 	
       
   100 	self->iSimParams = CMobilePhoneSmspList::NewL();
       
   101 	self->iState = EStateWritingSimParams;
       
   102 	self->DoWriteSimParamsL(aList);
       
   103 	
       
   104 	CleanupStack::Pop(self);
       
   105 	return self;
       
   106 	}
       
   107 
       
   108 /** 
       
   109 Gets the operation completion/error code for reading/writing the SMS parameters.
       
   110 
       
   111 It returns a packaged TInt (TIntBuf) and not a packaged TSmsProgress.
       
   112 
       
   113 The code can be intrepreted as follows:
       
   114 
       
   115 KErrNone - the SMS parameters were successfully read/writte from/to the SIM
       
   116 
       
   117 KErrNotSupported - the telephone handset and/or TSY module does not support 
       
   118 reading/writing the SMS parameters.
       
   119 
       
   120 KErrNotFound - no SMS parameters where found on the SIM.
       
   121 
       
   122 Other system-wide error codes - may indicate a comms, telephony or memory error.
       
   123 
       
   124 @return
       
   125 A TIntBuf containing the operation completion/error code.
       
   126 */
       
   127 EXPORT_C const TDesC8& CSmsSimParamOperation::ProgressL()
       
   128 	{
       
   129 	iProgressBuf = TIntBuf(iError);
       
   130 	return iProgressBuf;
       
   131 	}
       
   132 
       
   133 /**
       
   134 Constructor.
       
   135 */
       
   136 CSmsSimParamOperation::CSmsSimParamOperation(TUid aMtm, TMsvId aService, CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus)
       
   137 :	CMsvOperation(aMsvSession, EPriorityStandard, aObserverRequestStatus),
       
   138 	iError(KErrNone)
       
   139 	{
       
   140 	iService = aService;
       
   141 	iMtm = aMtm;
       
   142 	CActiveScheduler::Add(this);
       
   143 	}
       
   144 
       
   145 /**
       
   146 Destructor.
       
   147 */
       
   148 CSmsSimParamOperation::~CSmsSimParamOperation()
       
   149 	{
       
   150 	Cancel();
       
   151 	delete iSimParams;
       
   152 	delete iOperation;
       
   153 	}
       
   154 
       
   155 /**
       
   156 Retrieves the read SIM parameters from the stream in the SMS Service entry.
       
   157 
       
   158 The read SIM parameters are placed in the member data iSimParams.
       
   159 
       
   160 @pre
       
   161 The async read SIM parameters operation is complete.
       
   162 
       
   163 @post
       
   164 The parameters are retrived from the stream in the SMS Service entry and stored
       
   165 in iSimParams.
       
   166 
       
   167 @leave	KErrNotFound
       
   168 There were no SIM parameters to read from the SIM.
       
   169 */
       
   170 void CSmsSimParamOperation::DoRunReadSimParamsL()
       
   171 	{
       
   172 	CMsvEntry* entry = iMsvSession.GetEntryL(iService);
       
   173 	CleanupStack::PushL(entry);
       
   174 			
       
   175 	CMsvStore* store = entry->ReadStoreL();
       
   176 	CleanupStack::PushL(store);
       
   177 
       
   178 	RestoreSimParamsL(*store, *iSimParams);
       
   179 
       
   180 	const TInt count = iSimParams->Enumerate();
       
   181 
       
   182 	if (!count)
       
   183 		User::Leave(KErrNotFound);
       
   184 
       
   185 	CleanupStack::PopAndDestroy(2, entry); //entry, store
       
   186 	}
       
   187 
       
   188 /**
       
   189 Completes the observer with the value in iError.
       
   190 */
       
   191 void CSmsSimParamOperation::Complete()
       
   192 	{
       
   193 	TRequestStatus* status = &iObserverRequestStatus;
       
   194 	User::RequestComplete(status, iError);
       
   195 	}
       
   196 
       
   197 /**
       
   198 Reads the SIM parameters from the SIM.
       
   199 
       
   200 A read SIM parameters command is transferred to the SMS server MTM. It is this
       
   201 operation that does the actual reading of SIM parameters.
       
   202 
       
   203 @post
       
   204 A ESmsMtmCommandReadSimParams comand operation is started.
       
   205 */
       
   206 void CSmsSimParamOperation::DoReadSimParamsL()
       
   207 	{
       
   208 	TransferCommandL(ESmsMtmCommandReadSimParams);
       
   209 	}
       
   210 
       
   211 /**
       
   212 Writes the SMS parameters to the SIM.
       
   213 
       
   214 The new parameters to be stored are written to a stream in the SMS Service entry.
       
   215 A write SIM parameters command is transferred to the SMS server MTM. It is this
       
   216 operation that does the actual writing of SIM parameters.
       
   217 
       
   218 @param	aList
       
   219 A list wit the new SIM parameters.
       
   220 
       
   221 @post
       
   222 The new SIM parameters are stored in the message store and a ESmsMtmCommandWriteSimParams
       
   223 comand operation is started.
       
   224 */
       
   225 void CSmsSimParamOperation::DoWriteSimParamsL(const CMobilePhoneSmspList& aList)
       
   226 	{
       
   227 	CMsvEntry* entry = iMsvSession.GetEntryL(iService);
       
   228 	CleanupStack::PushL(entry);
       
   229 		
       
   230 	CMsvStore* store = entry->EditStoreL();
       
   231 	CleanupStack::PushL(store);
       
   232 
       
   233 	StoreSimParamsL(*store, aList);
       
   234 
       
   235 	CleanupStack::PopAndDestroy(2, entry); 
       
   236 
       
   237 	TransferCommandL(ESmsMtmCommandWriteSimParams);
       
   238 	}
       
   239 
       
   240 /**
       
   241 Requests the specified asynchronous command from the SMS server MTM.
       
   242 
       
   243 The command Ids are defined by TSmsMtmCommand.
       
   244 
       
   245 @param	aCommandId
       
   246 The Id of the requested command.
       
   247 
       
   248 @post
       
   249 The requested command is started.
       
   250 
       
   251 @see	TSmsMtmCommand
       
   252 */
       
   253 void CSmsSimParamOperation::TransferCommandL(TInt aCommandId)
       
   254 	{
       
   255 	CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection();
       
   256 	CleanupStack::PushL(sel);
       
   257 	sel->AppendL(iService);
       
   258 
       
   259 	delete iOperation;
       
   260 	iOperation = NULL;
       
   261 	iOperation = iMsvSession.TransferCommandL(*sel, aCommandId, TPtrC8(), iStatus);
       
   262 
       
   263 	CleanupStack::PopAndDestroy(sel);
       
   264 	iObserverRequestStatus = KRequestPending;
       
   265 	SetActive();
       
   266 	}
       
   267 
       
   268 /**
       
   269 Gets a list of Service Centre addresses.
       
   270 
       
   271 This function can only be used after a read/write SIM parameters operation has
       
   272 completed. If the CSmsSimParamOperation::ProgressL API returns any an error
       
   273 code other than KErrNone, or the SIM parameters contain no Service Centre 
       
   274 addresses, then this function returns an empty list.
       
   275 
       
   276 @return
       
   277 The list of SMS parameters that only contain Service Centre addresses. A pointer
       
   278 to the list object is left on the cleanup stack.
       
   279 */
       
   280 EXPORT_C CMobilePhoneSmspList* CSmsSimParamOperation::ServiceCentersLC() const
       
   281 	{
       
   282 	TInt count = 0;
       
   283 	count = iSimParams->Enumerate();
       
   284 
       
   285 	CMobilePhoneSmspList* list = CMobilePhoneSmspList::NewL();
       
   286 	CleanupStack::PushL(list);
       
   287 
       
   288 	// Order important
       
   289 	for (TInt i = 0; i < count; ++i)
       
   290 		{
       
   291 		const RMobileSmsMessaging::TMobileSmspEntryV1& smspEntry = iSimParams->GetEntryL(i);
       
   292 
       
   293 		if (smspEntry.iValidParams & RMobileSmsMessaging::KSCAIncluded)
       
   294 			{
       
   295 			list->AddEntryL(smspEntry);
       
   296 			}
       
   297 		}
       
   298 	return list;
       
   299 	}
       
   300 
       
   301 /**
       
   302 Stores the contents of aList into the message store.
       
   303 
       
   304 The supplied SIM parameters are stored in the KUidMsvSimSmsParams stream of the
       
   305 message entry store specified. This should be the SMS Service entry. No checking
       
   306 is performed to verify that the store is for the SMS service entry.
       
   307 
       
   308 @param	aStore
       
   309 The message entry store to write the parameters into.
       
   310 
       
   311 @param	aList
       
   312 The SMS parameters to be written.
       
   313 
       
   314 @post
       
   315 The contents of aList are stored in the message store. 
       
   316 
       
   317 @internalTechnology
       
   318 */
       
   319 EXPORT_C void CSmsSimParamOperation::StoreSimParamsL(CMsvStore& aStore, const CMobilePhoneSmspList& aList)
       
   320 	{
       
   321 	aStore.Remove(KUidMsvSimSmsParams);
       
   322 	
       
   323 	RMsvWriteStream writeStream;
       
   324 	writeStream.AssignLC(aStore, KUidMsvSimSmsParams);
       
   325 
       
   326 	writeStream << aList;
       
   327 	writeStream.CommitL();
       
   328 	aStore.CommitL();
       
   329 
       
   330 	CleanupStack::PopAndDestroy(&writeStream);
       
   331 	}
       
   332 
       
   333 /**
       
   334 Restores the SIM parameters from message store.
       
   335 
       
   336 The SIM parameters are restored from the KUidMsvSimSmsParams stream of the 
       
   337 message entry store specified. This should be the SMS Service entry. No checking
       
   338 is performed to verify that the store is for the SMS service entry.
       
   339 
       
   340 @param	aStore
       
   341 The message entry store to read the parameters from.
       
   342 
       
   343 @param	aList
       
   344 An output argument to conatin the restored SMS parameters.
       
   345 
       
   346 @leave	KErrNotFound
       
   347 The stream did not exist in the specified message entry store.
       
   348 
       
   349 @post
       
   350 The output argument aList contains the restored SIM parameters.
       
   351 
       
   352 @internalTechnology
       
   353 */
       
   354 EXPORT_C void CSmsSimParamOperation::RestoreSimParamsL(CMsvStore& aStore, CMobilePhoneSmspList& aList)
       
   355 	{
       
   356 	if (aStore.IsPresentL(KUidMsvSimSmsParams))
       
   357 		{
       
   358 		RMsvReadStream readStream;
       
   359 		readStream.OpenLC(aStore, KUidMsvSimSmsParams);
       
   360 
       
   361 		readStream >> aList;
       
   362 		readStream.Close();
       
   363 
       
   364 		CleanupStack::PopAndDestroy(&readStream); 
       
   365 		}
       
   366 	else
       
   367 		{
       
   368 		User::Leave(KErrNotFound);
       
   369 		}
       
   370 	}
       
   371 
       
   372 /*
       
   373  *	Methods from CActive
       
   374  */
       
   375 
       
   376 /**
       
   377 Handles completed async operations.
       
   378 
       
   379 If the async operation was to read the SIM parameters, then the SIM parameters 
       
   380 are read from the appropriate stream in the SMS Service entry and placed in the
       
   381 parameter member iSimParams.
       
   382 
       
   383 If the async operation was to read the SIM parameters, then there is nothing 
       
   384 more to do.
       
   385 
       
   386 For both types of operation the observer for this operation is completed.
       
   387 
       
   388 @pre
       
   389 The async operation is complete
       
   390 
       
   391 @post
       
   392 The operation is complete
       
   393 
       
   394 @leave	KErrNotFound
       
   395 There were no SIM parameters to read from the SIM.
       
   396 
       
   397 @panic	SMCM	3
       
   398 There was an supported command.
       
   399 */
       
   400 void CSmsSimParamOperation::RunL()
       
   401 	{
       
   402 	iError = iStatus.Int();
       
   403 
       
   404 	if (iError == KErrNone)
       
   405 		{
       
   406 		TSmsProgressBuf progressBuf;
       
   407 		progressBuf.Copy(iOperation->ProgressL());
       
   408 		TSmsProgress progress = progressBuf();
       
   409 
       
   410 		iError = progress.iError;
       
   411 
       
   412 		if (iError == KErrNone)
       
   413 			{
       
   414 			switch (iState)
       
   415 				{
       
   416 				case EStateReadingSimParams:
       
   417 					{
       
   418 					DoRunReadSimParamsL();
       
   419 					break;
       
   420 					}
       
   421 				case EStateWritingSimParams:
       
   422 					{
       
   423 					break;
       
   424 					}
       
   425 				default:
       
   426 					{
       
   427 					Panic(ESmscPanicUnexpectedCommand);
       
   428 					}
       
   429 				}
       
   430 			}
       
   431 		}
       
   432 	
       
   433 	Complete();
       
   434 	}
       
   435 
       
   436 /**
       
   437 Cancels any pending async request.
       
   438 
       
   439 The observer is completed with an value of KErrCancel.
       
   440 */
       
   441 void CSmsSimParamOperation::DoCancel()
       
   442 	{
       
   443 	if (iOperation)
       
   444 		{
       
   445 		iOperation->Cancel();
       
   446 		}
       
   447 
       
   448 	iError = KErrCancel;
       
   449 	Complete();
       
   450 	}
       
   451 
       
   452 /**
       
   453 Handles leaves from RunL().
       
   454 
       
   455 The observer is completed with the leave code aError.
       
   456 
       
   457 @param	aError
       
   458 The leave code from RunL().
       
   459 
       
   460 @return
       
   461 A value of KErrNone.
       
   462 */
       
   463 TInt CSmsSimParamOperation::RunError(TInt aError)
       
   464 	{
       
   465 	iError = aError;
       
   466 	Complete();
       
   467 	return KErrNone;
       
   468 	}