mobilemessaging/smum/src/MsgSimSCNumberDetector.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *     An active object class which takes care of reading the possible new
       
    16 *     service centres from SIM and adds them to pda-side Sms Settings.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <mtuireg.h>    // for CMtmUiRegistry
       
    24 #include <etelmm.h>
       
    25 #include <mmlist.h>
       
    26 #include <smutset.h>    //CSmsSettings
       
    27 #include <exterror.h>   // KErrGsmSMSSimBusy
       
    28 #include <csmsaccount.h>
       
    29 #include <centralrepository.h>
       
    30 #include <messagingvariant.hrh>
       
    31 #include <messaginginternalcrkeys.h>    // Keys
       
    32 
       
    33 #include "SmumStartUpMonitor.h"
       
    34 #include "SmumUtil.h"   // SmumUtil
       
    35 #include "MsgSimSCNumberDetector.h"
       
    36 #include "SmumLogging.h"
       
    37 #include "smsui.pan"    // for panics
       
    38 
       
    39 // CONSTANTS
       
    40 const TInt KMaxNameLength = 60;
       
    41 const TInt KSmumGranularity = 4;
       
    42 const TInt KSmumRetryCount = 20;
       
    43 const TInt KSmumRetryDelay = 5000000; // 5 secs
       
    44 const TInt KSmumSMSPid = 50;
       
    45 // ================= MEMBER FUNCTIONS =======================
       
    46 
       
    47 /*
       
    48 * Symbian OS 2 phase construction and initialization. Note that operation that is returned is already active.
       
    49 * A client will be notified via aClientStatus when the operation terminates.
       
    50 */
       
    51 EXPORT_C CMsgSimOperation* CMsgSimOperation::NewL( TRequestStatus& aClientStatus )
       
    52     {
       
    53     SMUMLOGGER_ENTERFN("CMsgSimOperation::NewL")
       
    54 
       
    55     CMsgSimOperation* self = new ( ELeave ) CMsgSimOperation( aClientStatus );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     SMUMLOGGER_LEAVEFN("CMsgSimOperation::NewL")
       
    60 
       
    61     return self;
       
    62     }
       
    63 
       
    64 // C++ constructor which initializes the active object with a default priority and adds it to the active scheduler.
       
    65 // C++ constructor can NOT contain any code, that
       
    66 // might leave.
       
    67 CMsgSimOperation::CMsgSimOperation( TRequestStatus& aStatus, TInt aPriority )
       
    68 : CActive( aPriority ), iClientStatus( &aStatus ), iRetryCount( 0 )
       
    69     {
       
    70     SMUMLOGGER_ENTERFN("CMsgSimOperation::CMsgSimOperation")
       
    71     CActiveScheduler::Add( this );
       
    72     SMUMLOGGER_LEAVEFN("CMsgSimOperation::CMsgSimOperation")
       
    73     }
       
    74 
       
    75 // Symbian OS default constructor can leave.
       
    76 void CMsgSimOperation::ConstructL()
       
    77     {
       
    78     SMUMLOGGER_ENTERFN("CMsgSimOperation::ConstructL")
       
    79     
       
    80     // initialise
       
    81     iMsvSession = CMsvSession::OpenSyncL( *this ); // have to be sync; actual active object is started right after this, not in HandleSessionEventL
       
    82     iClientRegistry = CClientMtmRegistry::NewL( *iMsvSession );   // get client mtm registry
       
    83     iSmsClientMtm = STATIC_CAST( CSmsClientMtm*, iClientRegistry->NewMtmL( KUidMsgTypeSMS ));  // get smcm object
       
    84 
       
    85     SMUMLOGGER_WRITE("ConstructL - Basic initialising ok, next connecting to Shared Data")
       
    86 	// Start the System state monitor
       
    87 	iStartupMonitor = CSmumStartUpMonitor::NewL( this );
       
    88 	// Client status can be set pending only if we don't leave
       
    89     *iClientStatus = KRequestPending;  // activate the active object
       
    90     // StartL() is called when iStartupMonitor ActiveObject completes
       
    91     //Check is sms servicecenter fetched in every boot
       
    92 	iCheckSimScAlways = ( SmumUtil::CheckVariationFlagsL( KCRUidMuiuVariation, KMuiuSmsFeatures ) & 
       
    93 			  KSmsFeatureIdCheckSimAlways );
       
    94     SMUMLOGGER_LEAVEFN("CMsgSimOperation::ConstructL")
       
    95     }
       
    96 
       
    97 // C++ virtual destructor
       
    98 CMsgSimOperation::~CMsgSimOperation()
       
    99     {
       
   100     SMUMLOGGER_ENTERFN("CMsgSimOperation::~CMsgSimOperation")
       
   101 
       
   102     Cancel(); // make sure that this object is not left on the active scheduler.
       
   103     delete iSimOperation;  
       
   104     delete iSmsClientMtm;
       
   105     delete iClientRegistry;
       
   106     delete iMsvSession;
       
   107 	delete iStartupMonitor;
       
   108     iStartupMonitor = NULL;
       
   109     iClientStatus = NULL;
       
   110     
       
   111     SMUMLOGGER_LEAVEFN("CMsgSimOperation::~CMsgSimOperation")
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------
       
   115 // CMsgSimOperation::StartL
       
   116 // This function issues request and activates the object
       
   117 //
       
   118 // ----------------------------------------------------
       
   119 void CMsgSimOperation::StartL()
       
   120     {
       
   121     SMUMLOGGER_ENTERFN("CMsgSimOperation::StartL")
       
   122     // Retry is used to define the times ReadSimParamsL() is called
       
   123     iRetryCount++;
       
   124     SMUMLOGGER_WRITE_FORMAT("StartL - iRetryCount :%d", iRetryCount)
       
   125 
       
   126     SMUMLOGGER_WRITE("StartL - BootState ok, proceed with SMSC fetch")
       
   127     // start the real sim reading operation
       
   128     iSimOperation = iSmsClientMtm->ReadSimParamsL( iStatus );
       
   129     SetActive();
       
   130 
       
   131     SMUMLOGGER_LEAVEFN("CMsgSimOperation::StartL")
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------
       
   135 // CMsgSimOperation::CompleteRequest
       
   136 //
       
   137 // ----------------------------------------------------
       
   138 void CMsgSimOperation::CompleteRequest( TInt aValue )
       
   139     {
       
   140     SMUMLOGGER_ENTERFN("CMsgSimOperation::CompleteRequest")
       
   141     
       
   142     __ASSERT_DEBUG( !IsActive(), Panic( ESimOperationPanicRequestAlreadyActive ));
       
   143     TRequestStatus* myRequestStatus = &iStatus;
       
   144     User::RequestComplete( myRequestStatus, aValue );
       
   145     if( !IsActive() )
       
   146         {
       
   147         SetActive();
       
   148         }
       
   149 
       
   150     SMUMLOGGER_LEAVEFN("CMsgSimOperation::CompleteRequest")
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------
       
   154 // CMsgSimOperation::CompleteClientRequest
       
   155 //
       
   156 // ----------------------------------------------------
       
   157 void CMsgSimOperation::CompleteClientRequest( TInt aValue )
       
   158     {
       
   159     SMUMLOGGER_ENTERFN("CMsgSimOperation::CompleteClientRequest")
       
   160     
       
   161     TBool haveClientRequestStatus = HaveClientRequestStatus();
       
   162     __ASSERT_DEBUG( haveClientRequestStatus, Panic( ESimOperationPanicClientsRequestAlreadyCompleted ));
       
   163     // So that we don't attempt to complete the clients request again in the future
       
   164     if ( haveClientRequestStatus )
       
   165         {
       
   166         User::RequestComplete( iClientStatus, aValue );
       
   167         iClientStatus = NULL;
       
   168         }
       
   169 
       
   170     SMUMLOGGER_LEAVEFN("CMsgSimOperation::CompleteClientRequest")
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------
       
   174 // CMsgSimOperation::HaveClientRequestStatus
       
   175 //
       
   176 // ----------------------------------------------------
       
   177 TBool CMsgSimOperation::HaveClientRequestStatus() const
       
   178     {
       
   179     SMUMLOGGER_WRITE("CMsgSimOperation::HaveClientRequestStatus")
       
   180     return (iClientStatus != NULL);
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------
       
   184 // CMsgSimOperation::Panic
       
   185 //
       
   186 // ----------------------------------------------------
       
   187 void CMsgSimOperation::Panic(TSimOperationPanic aPanic)
       
   188     {
       
   189     SMUMLOGGER_ENTERFN("CMsgSimOperation::Panic")
       
   190 
       
   191     _LIT(KSimOpPanicCategory, "SIMOP");
       
   192     SMUMLOGGER_WRITE_FORMAT("Panic - Panic :%d", aPanic)
       
   193     User::Panic(KSimOpPanicCategory, aPanic);
       
   194     
       
   195     SMUMLOGGER_LEAVEFN("CMsgSimOperation::Panic")
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------
       
   199 // CMsgSimOperation::RunL
       
   200 // Active object RunL method is called when the request (sim params reading operation) has been completed
       
   201 //
       
   202 // ----------------------------------------------------
       
   203 void CMsgSimOperation::RunL()
       
   204     {
       
   205     SMUMLOGGER_ENTERFN("CMsgSimOperation::RunL")
       
   206 
       
   207     TInt error = iStatus.Int();
       
   208     SMUMLOGGER_WRITE_FORMAT("RunL - 1st error check :%d", error)
       
   209     if ( error == KErrNone ) 
       
   210         { // continue if sim reading operation completed ok
       
   211         TRAP( error, DoRunL());
       
   212         }
       
   213     
       
   214     SMUMLOGGER_WRITE_FORMAT("RunL - 2nd error check :%d", error)
       
   215     // if problems with above; retry 
       
   216     TInt maxRetryCount = KSmumRetryCount;
       
   217     if ( error == KErrTimedOut )
       
   218         {
       
   219         maxRetryCount = KSmumRetryCount/10; // no use to retry many times if timed out already
       
   220         }
       
   221     if ( error != KErrNone /*KErrGsmSMSSimBusy*/ && iRetryCount <= maxRetryCount )
       
   222         { 
       
   223         SMUMLOGGER_WRITE("RunL - Retrying")
       
   224         // first cancel the current simOp if still ongoing
       
   225         if ( iSimOperation )
       
   226             {
       
   227             SMUMLOGGER_WRITE("RunL - Deleting SIM operation")
       
   228             iSimOperation->Cancel();
       
   229             delete iSimOperation;
       
   230             iSimOperation = NULL;
       
   231             }
       
   232         // wait a bit and actual retry
       
   233         User::After( KSmumRetryDelay );
       
   234         StartL();
       
   235         return;
       
   236         }
       
   237 
       
   238     // Once the 'real' operation has completed, we inform the
       
   239     // client of the result
       
   240     if  ( HaveClientRequestStatus() )
       
   241         {
       
   242         SMUMLOGGER_WRITE("RunL - Completing client request")
       
   243         CompleteClientRequest( error );
       
   244         }
       
   245 
       
   246     SMUMLOGGER_LEAVEFN("CMsgSimOperation::RunL")
       
   247     }
       
   248 
       
   249 // ----------------------------------------------------
       
   250 // CCMsgSimOperation::DoRunL
       
   251 //
       
   252 // ----------------------------------------------------
       
   253 void CMsgSimOperation::DoRunL()
       
   254     {
       
   255     SMUMLOGGER_ENTERFN("CMsgSimOperation::DoRunL")
       
   256 
       
   257     TIntBuf progressBuf;
       
   258     progressBuf.Copy( iSimOperation->ProgressL());
       
   259     TInt error = progressBuf();
       
   260     SMUMLOGGER_WRITE_FORMAT("DoRunL - Error check :%d", error)
       
   261 
       
   262     if ( error == KErrNone )  // check operation status
       
   263         {
       
   264         CMobilePhoneSmspList* centersList = iSimOperation->ServiceCentersLC();
       
   265         TInt count = centersList->Enumerate(); // How many centre numbers are there on the SIM card?
       
   266         SMUMLOGGER_WRITE_FORMAT("DoRunL - Amount of SIM SMSCs :%d", count )
       
   267         TBool emailFeatureSupported = SmumUtil::CheckEmailOverSmsSupportL();
       
   268 		TBool emailEntryFound( EFalse );
       
   269 	
       
   270 	    // Check the service centre situation even if there are no service centres on SIM!
       
   271 	    // If there are none, and only usage of service centre SIMs is allowed, all must
       
   272 	    // be removed and the SMS service will be disabled.
       
   273 	    	
       
   274         TInt numSCAddresses( 0 );
       
   275         iSmsClientMtm->SwitchCurrentEntryL( iSmsClientMtm->ServiceId() ); // load SMS settings
       
   276         CMsvEntry& service = iSmsClientMtm->Entry();
       
   277         // load settings
       
   278         CSmsSettings* smsSettings = CSmsSettings::NewLC();
       
   279         CSmsAccount* smsAccount = CSmsAccount::NewLC();
       
   280     	smsAccount->LoadSettingsL( *smsSettings );
       
   281         TBool newDefault = EFalse;
       
   282         TInt newDefaultIndex = -1;
       
   283 
       
   284 		// Check if Only Sim SC's variation is on
       
   285 		if ( SmumUtil::CheckVariationFlagsL( KCRUidMuiuVariation, KMuiuSmsFeatures ) & 
       
   286 			 KSmsFeatureIdSimServiceCentresOnly )
       
   287 			{
       
   288 			// Remove all old SMSC's
       
   289 			SMUMLOGGER_WRITE("DoRunL - Only Sim SC's - Deleting old ones->" )			
       
   290 	        numSCAddresses = smsSettings->ServiceCenterCount();
       
   291 	        SMUMLOGGER_WRITE_FORMAT("DoRunL - Amount of old SMSC's: #%d", numSCAddresses )
       
   292 	        for ( TInt j = numSCAddresses; j > 0; j-- )
       
   293 	            {
       
   294 	            smsSettings->RemoveServiceCenter( j - 1 );
       
   295 	            }
       
   296 	        #ifdef _DEBUG		
       
   297 			numSCAddresses = smsSettings->ServiceCenterCount();
       
   298 			SMUMLOGGER_WRITE_FORMAT("DoRunL - Amount of SMSC's now: #%d", numSCAddresses )
       
   299 			#endif // _DEBUG		
       
   300 			}
       
   301 	
       
   302         SMUMLOGGER_WRITE("DoRunL - Ready for looping SMSCs")
       
   303         for ( TInt i = 0; i < count; i++ )    // add all centres from sim to sms settings
       
   304             {
       
   305             SMUMLOGGER_WRITE_FORMAT("DoRunL - SMSC #%d", i)
       
   306             RMobileSmsMessaging::TMobileSmspEntryV1 entry;
       
   307             entry = centersList->GetEntryL( i );
       
   308             TBool duplicateFound = EFalse;
       
   309             
       
   310             SMUMLOGGER_WRITE_FORMAT("DoRunL - SMSC Name: %S", &entry.iText ); 
       
   311             SMUMLOGGER_WRITE_FORMAT("DoRunL - SMSC Address: %S", &entry.iServiceCentre.iTelNumber );
       
   312             // If empty tel number field, don't add
       
   313             if ( entry.iServiceCentre.iTelNumber == KNullDesC )
       
   314                 {
       
   315                 SMUMLOGGER_WRITE_FORMAT("DoRunL - No number in SMSC #%d", i)
       
   316                 continue;
       
   317                 }
       
   318             //Check is number already in cenrep
       
   319             //Get default SC from phone settings for later use
       
   320             TBuf<TGsmSmsTelNumberMaxLen> defaultSmsCenterNb;;            
       
   321             TInt defaultSCIndex = smsSettings->DefaultServiceCenter();
       
   322             if ( defaultSCIndex > -1 )
       
   323                 {
       
   324                 defaultSmsCenterNb = smsSettings->GetServiceCenter( defaultSCIndex ).Address(); 
       
   325                 }    
       
   326             if ( iCheckSimScAlways && i == 0 )
       
   327                 {
       
   328                 //Check is number already in cenrep
       
   329                 TBuf<TGsmSmsTelNumberMaxLen> previousSmsCenterNb;
       
   330                 CRepository* cenRepSession = CRepository::NewLC( KCRUidSmum );
       
   331                 cenRepSession->Get( KSmumPreviousSimSmscNumber, previousSmsCenterNb );
       
   332                 
       
   333                 //Check was there different SMSC in cenrep and default SMSC in settings. 
       
   334                 if ( entry.iServiceCentre.iTelNumber == previousSmsCenterNb &&
       
   335                     entry.iServiceCentre.iTelNumber == defaultSmsCenterNb &&
       
   336                     smsSettings->ServiceCenterCount() != 0 )
       
   337                     {
       
   338                     SMUMLOGGER_WRITE_FORMAT("DoRunL - number #%d already in cenrep/settings", i)
       
   339                     CleanupStack::PopAndDestroy( cenRepSession );
       
   340                     continue;
       
   341                     }
       
   342                 else 
       
   343                     {
       
   344                     SMUMLOGGER_WRITE_FORMAT("DoRunL - number #%d not in cenrep/settings", i)
       
   345                     cenRepSession->Set( KSmumPreviousSimSmscNumber, entry.iServiceCentre.iTelNumber );
       
   346                     CleanupStack::PopAndDestroy( cenRepSession );
       
   347                     }                
       
   348                 }
       
   349 			SMUMLOGGER_WRITE_FORMAT("DoRunL - Entry ProtocolId #%d", entry.iProtocolId)
       
   350             // Check for Email settings
       
   351             if ( emailFeatureSupported 
       
   352                  && KSmumSMSPid == entry.iProtocolId
       
   353                  && !emailEntryFound ) // We'll take the first
       
   354                 {
       
   355                 SMUMLOGGER_WRITE_FORMAT("DoRunL - Email over sms entry #%d", i)
       
   356                 SmumUtil::WriteEmailOverSmsSettingsL( 
       
   357                     entry.iServiceCentre.iTelNumber,
       
   358                     entry.iDestination.iTelNumber,
       
   359                     ETrue );
       
   360                 emailEntryFound = ETrue;
       
   361                 }
       
   362             else
       
   363             	{
       
   364                 // check if this SC is already in Sms settings
       
   365                 numSCAddresses = smsSettings->ServiceCenterCount();
       
   366                 for ( TInt j = 0; j < numSCAddresses; j++ )
       
   367                     {
       
   368                     if ( entry.iServiceCentre.iTelNumber == 
       
   369                         smsSettings->GetServiceCenter( j ).Address() )
       
   370                         {
       
   371                         SMUMLOGGER_WRITE_FORMAT("DoRunL - Duplicate. SMSC #%d", i)
       
   372                         SMUMLOGGER_WRITE_FORMAT("DoRunL -    of Sms Settings SMSC #%d", j)
       
   373 
       
   374                         duplicateFound = ETrue;
       
   375                         if ( i == 0 )   // first smsc in the sim but it has a duplicate already
       
   376                             {
       
   377                             newDefault = ETrue;
       
   378                             newDefaultIndex = j;
       
   379                             }
       
   380                         break;
       
   381                         }
       
   382                     }
       
   383 
       
   384                 SMUMLOGGER_WRITE_FORMAT("DoRunL - After dupe-check : newDefaultIndex :%d", newDefaultIndex)
       
   385 
       
   386                 // this is not a duplicate, find a name and add it to Sms settings
       
   387                 if ( !duplicateFound )
       
   388                     {
       
   389                     
       
   390                     if(i==0)    // first smsc in the sim and has no duplicates
       
   391                         {
       
   392                         newDefault=ETrue;
       
   393                         newDefaultIndex = smsSettings->ServiceCenterCount();
       
   394                         }
       
   395                     
       
   396                     SMUMLOGGER_WRITE_FORMAT("DoRunL - Not a dupe : newDefaultIndex :%d", newDefaultIndex)
       
   397                     
       
   398                     TBuf<KMaxNameLength> name;
       
   399                     name = entry.iText;
       
   400                     
       
   401                     if ( name == KNullDesC )
       
   402                         {
       
   403                         SMUMLOGGER_WRITE( "DoRunL - SMSC has no name" )
       
   404                         // read Service centres from SmsSettings
       
   405                         TInt serviceCentres = 0;
       
   406                         serviceCentres = smsSettings->ServiceCenterCount();
       
   407                         SMUMLOGGER_WRITE_FORMAT(
       
   408                             "DoRunL - Amount of Sms Settings SMSCs :%d", 
       
   409                             serviceCentres )
       
   410                         
       
   411                         CDesCArrayFlat* nameArray = 
       
   412                             new ( ELeave ) CDesCArrayFlat( KSmumGranularity );
       
   413                         CleanupStack::PushL( nameArray );
       
   414                         
       
   415                         for ( TInt loop = 0 ; loop < serviceCentres; loop++ )
       
   416                             {
       
   417                             nameArray->AppendL( 
       
   418                                 smsSettings->GetServiceCenter( loop ).Name() );
       
   419                             }
       
   420                         SmumUtil::FindDefaultNameForSCL( name, ETrue, nameArray );
       
   421                         CleanupStack::PopAndDestroy();// nameArray
       
   422                         }
       
   423                     smsSettings->AddServiceCenterL( 
       
   424                         name, entry.iServiceCentre.iTelNumber );
       
   425                     SMUMLOGGER_WRITE("DoRunL - New SMSC added")
       
   426                 	}
       
   427                 }
       
   428             }
       
   429         // set default SC
       
   430         if(newDefault)  // the default has changed
       
   431             {
       
   432             smsSettings->SetDefaultServiceCenter( newDefaultIndex );
       
   433             SMUMLOGGER_WRITE_FORMAT("DoRunL - New default SMSC :%d", newDefaultIndex)
       
   434             }
       
   435         // save settings
       
   436         smsAccount->SaveSettingsL( *smsSettings );
       
   437         SMUMLOGGER_WRITE("DoRunL - Saved")
       
   438     #ifdef _DEBUG
       
   439         TMsvEntry entry = service.Entry();
       
   440         entry.iDate.HomeTime();
       
   441         service.ChangeL( entry );
       
   442         SMUMLOGGER_WRITE("DoRunL - Entry changed")
       
   443     #endif
       
   444         CleanupStack::PopAndDestroy( 2 ); // msvStore, smsSettings
       
   445             
       
   446         if ( emailFeatureSupported && !emailEntryFound )
       
   447             {
       
   448             SMUMLOGGER_WRITE("DoRunL - Empty Email settings")
       
   449             HBufC* emptyStr = NULL;
       
   450             emptyStr = KNullDesC().AllocLC();
       
   451             SmumUtil::WriteEmailOverSmsSettingsL( 
       
   452                         emptyStr->Des(),
       
   453                         emptyStr->Des(),
       
   454                         ETrue );
       
   455             CleanupStack::PopAndDestroy();  // emptyStr
       
   456             }
       
   457         CleanupStack::PopAndDestroy();  // centersList
       
   458         }
       
   459     SMUMLOGGER_LEAVEFN("CMsgSimOperation::DoRunL")
       
   460     }
       
   461 
       
   462 // ----------------------------------------------------
       
   463 // CMsgSimOperation::RunError
       
   464 // Called when AO RunL leaves. Handle the leave and return
       
   465 //
       
   466 // ----------------------------------------------------
       
   467  
       
   468 TInt CMsgSimOperation::RunError( TInt )
       
   469     {
       
   470     SMUMLOGGER_ENTERFN("CMsgSimOperation::RunError")
       
   471     DoCancel();
       
   472     SMUMLOGGER_LEAVEFN("CMsgSimOperation::RunError")
       
   473     return KErrNone;
       
   474     }
       
   475 
       
   476 // ----------------------------------------------------
       
   477 // CMsgSimOperation::DoCancel
       
   478 // called by active object's Cancel method
       
   479 //
       
   480 // ----------------------------------------------------
       
   481 void CMsgSimOperation::DoCancel()
       
   482     {
       
   483     SMUMLOGGER_ENTERFN("CMsgSimOperation::DoCancel")
       
   484 
       
   485     if ( iSimOperation )  // if the real Sim reading operation was started:
       
   486         {
       
   487         iSimOperation->Cancel();    // cancel it
       
   488         }
       
   489 
       
   490     // We don't need to complete our own request status as this function will never
       
   491     // be called if our own request status has already been completed previously.
       
   492     // 
       
   493     // We do need to complete the client's request status however.
       
   494     if  (iClientStatus)
       
   495         {
       
   496         CompleteClientRequest(KErrCancel);
       
   497         }
       
   498 
       
   499     SMUMLOGGER_LEAVEFN("CMsgSimOperation::DoCancel")
       
   500     }
       
   501 
       
   502 
       
   503 // ----------------------------------------------------
       
   504 // CMsgSimOperation::HandleSessionEventL
       
   505 // called when there is a Msv session event. 
       
   506 //
       
   507 // ----------------------------------------------------
       
   508 void CMsgSimOperation::HandleSessionEventL(
       
   509     TMsvSessionEvent aEvent, 
       
   510     TAny* /*aArg1*/, 
       
   511     TAny* /*aArg2*/, 
       
   512     TAny* /*aArg3*/) 
       
   513     {
       
   514     SMUMLOGGER_ENTERFN("CMsgSimOperation::HandleSessionEventL")
       
   515     SMUMLOGGER_WRITE_FORMAT("HandleSessionEventL - TMsvSessionEvent :%d", aEvent)
       
   516 
       
   517     // problem case handling
       
   518     if ( aEvent == EMsvServerFailedToStart )
       
   519         {
       
   520         // also if we couldn't start up the msv server, we simulate that the request has completed
       
   521         CompleteRequest( KErrNotReady ); 
       
   522         }
       
   523     else if (( aEvent == EMsvServerTerminated ) || ( aEvent == EMsvCloseSession ))
       
   524         {
       
   525         // be polite to the Messaging Server and close the session
       
   526         Cancel();
       
   527         CompleteRequest( KErrNotReady ); 
       
   528 
       
   529         delete iSimOperation;  // These objects must be deleted first
       
   530         iSimOperation = NULL;       // as they can't exist without a MsvSession
       
   531         delete iSmsClientMtm;
       
   532         iSmsClientMtm = NULL;
       
   533         delete iClientRegistry;
       
   534         iClientRegistry = NULL;
       
   535         delete iMsvSession;
       
   536         iMsvSession = NULL;
       
   537         iClientStatus = NULL;
       
   538         }
       
   539 
       
   540     SMUMLOGGER_LEAVEFN("CMsgSimOperation::HandleSessionEventL")
       
   541     }
       
   542 
       
   543 // ----------------------------------------------------
       
   544 // CMsgSimOperation::HandleStartupReadyL
       
   545 // Handles events from startup state observer
       
   546 // 
       
   547 // ----------------------------------------------------
       
   548 //
       
   549 void CMsgSimOperation::HandleStartupReadyL()
       
   550     {
       
   551 	SMUMLOGGER_WRITE( "BootState Ready" )
       
   552 	// Boot ready, start the real SimOperation
       
   553 	StartL();
       
   554     }
       
   555 //  End of File