messagingappbase/ncnlist/src/NcnModel.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2004-2006 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:   Methods for CNcnModel class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    "NcnDebug.h"
       
    23 #include    "NcnModel.h"
       
    24 #include    "NcnCRHandler.h"
       
    25 #include    "NcnSNNotifier.h"
       
    26 #include    "CVoiceMailManager.h"
       
    27 
       
    28 #include    <msgsimscnumberdetector.h>
       
    29 #include	<rsatrefresh.h>
       
    30 #include	<rsatsession.h>
       
    31 
       
    32 // ================= LOCAL CONSTANTS =======================
       
    33 namespace
       
    34     {
       
    35     }
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // CNcnModelBase::NewL
       
    41 // Protocol specific class factory
       
    42 // ---------------------------------------------------------
       
    43 //
       
    44 CNcnModelBase* CNcnModelBase::NewL()
       
    45     {
       
    46     CNcnModelBase* self = CNcnModel::NewL();
       
    47 
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 // ================= MEMBER FUNCTIONS =======================
       
    56 
       
    57 // C++ default constructor can NOT contain any code that
       
    58 // might leave.
       
    59 CNcnModel::CNcnModel()
       
    60 :	iSatSession(NULL),
       
    61 	iSatRefresh(NULL)
       
    62     {
       
    63 	}
       
    64 
       
    65 // Two-phased constructor.
       
    66 CNcnModelBase* CNcnModel::NewL()
       
    67     {
       
    68     CNcnModelBase* self = new (ELeave) CNcnModel();
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 // Symbian OS default constructor can leave.
       
    74 void CNcnModel::ConstructL()
       
    75     {
       
    76 	// Call base class's constructor
       
    77     CNcnModelBase::ConstructL();
       
    78 
       
    79     //Subscribe to SAT Refresh notifications
       
    80 	iSatSession = new ( ELeave ) RSatSession;
       
    81 	iSatSession->ConnectL();
       
    82 	iSatRefresh = new ( ELeave ) RSatRefresh( *this );
       
    83 	iSatRefresh->OpenL( *iSatSession );
       
    84 
       
    85 	//We subcribe the EF_SMSP file changes
       
    86 	TSatRefreshFiles file;
       
    87 	file.Append( KSmspEf );
       
    88 	iSatRefresh->NotifyFileChangeL( file );
       
    89     }
       
    90 
       
    91 
       
    92 // Destructor
       
    93 CNcnModel::~CNcnModel()
       
    94     {
       
    95     //Cleanup for iSatRefresh
       
    96     if ( iSatRefresh )
       
    97         {
       
    98         // Cancel notifications.
       
    99         iSatRefresh->Cancel();
       
   100         // Close SubSession.
       
   101         iSatRefresh->Close();
       
   102         }
       
   103 	delete iSatRefresh;
       
   104 	iSatRefresh = NULL;
       
   105 
       
   106     //Cleanup for iSatSession
       
   107 	if ( iSatSession )
       
   108 		{
       
   109 		iSatSession->Close();
       
   110 		}
       
   111 	delete iSatSession;
       
   112 	iSatSession = NULL;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------
       
   116 // CNcnModel::SetSimChanged
       
   117 // ---------------------------------------------------------
       
   118 //
       
   119 void CNcnModel::SetSimChanged( const TBool aSimChanged )
       
   120     {
       
   121     NCN_RDEBUG_INT(_L("CNcnModel::SimChanged() %d"), aSimChanged);
       
   122 
       
   123     aSimChanged ?
       
   124         ( iNcnStatusBits |= KNcnSimChanged ) :
       
   125         ( iNcnStatusBits &= ~KNcnSimChanged );
       
   126 
       
   127     // If the sim card has been changed we notify some components
       
   128     if( aSimChanged )
       
   129         {
       
   130         NCN_RDEBUG(_L("CNcnModel::SimChanged() ResetMissedCalls") );
       
   131         // Reset the stored indicator status variable in the file.
       
   132         iNcnCRHandler->ResetMissedCalls();
       
   133 
       
   134         // Notify VoiceMailManager if it exists
       
   135         // VM Manager does not exist in boot-up but will be
       
   136         // available later
       
   137         if ( iVoiceMailManager != NULL )
       
   138 	        {
       
   139             NCN_RDEBUG(_L("CNcnModel::SimChanged() iVoiceMailManager->NotifyAboutSIMChange") );
       
   140 	        iVoiceMailManager->NotifyAboutSIMChange();
       
   141 	        }
       
   142         }
       
   143     else
       
   144       {
       
   145       iNcnCRHandler->UpdateMissedCallsNotification();
       
   146       }        
       
   147 
       
   148     // Check here if we should fetch the sms service center number
       
   149     // from the sim card.
       
   150     CheckIfSimSCOperationRequired();
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CNcnModel::SetSmsInitialisationState
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 void CNcnModel::SetSmsInitialisationState(
       
   158     const TInt aSmsInitialisationPhase )
       
   159     {
       
   160     iSmsInitialisationPhase = aSmsInitialisationPhase;
       
   161     
       
   162     if ( iSmsInitialisationPhase != ESMSInitNone )
       
   163     	{
       
   164     	iNcnStatusBits |= KNcnSmsServicePresent;
       
   165     	}
       
   166 
       
   167     // Check here if we should fetch the sms service center number
       
   168     // from the sim card.
       
   169     CheckIfSimSCOperationRequired();
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CNcnModel::CheckIfSimSCOperationRequired
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CNcnModel::CheckIfSimSCOperationRequired()
       
   177     {
       
   178     NCN_RDEBUG(_L("CNcnModelBase::CheckIfSimSCOperationRequired()" ));
       
   179 
       
   180  	TBool servicePresent = (iNcnStatusBits & KNcnSmsServicePresent);
       
   181 	TBool simChanged = (iNcnStatusBits & KNcnSimChanged);
       
   182 #ifdef _DEBUG
       
   183 	TBool systemRefresh = (iNcnStatusBits & KNcnSystemRefresh);
       
   184 	TBool readSimSc = (iNcnStatusBits & KNcnReadSimSc);		
       
   185 #endif	
       
   186 	NCN_RDEBUG_INT( _L("iSmsInitialisationPhase %d"), iSmsInitialisationPhase );
       
   187 	NCN_RDEBUG_INT( _L("NCN status bit sms service present %d"), servicePresent );
       
   188 	NCN_RDEBUG_INT( _L("NCN status bit sim changed %d"), simChanged );
       
   189 	NCN_RDEBUG_INT( _L("NCN status bit system refresh %d"), systemRefresh );
       
   190 	NCN_RDEBUG_INT( _L("NCN read sim service center %d"), readSimSc );		
       
   191 
       
   192 	// If SIM has been changed, we clear KNcnReadSimSc bit so
       
   193 	// that SIM won't be read twice. 
       
   194 	if( ( iNcnStatusBits & KNcnReadSimSc ) && 
       
   195 		( iNcnStatusBits & KNcnSimChanged ) )
       
   196 		{
       
   197 		iNcnStatusBits &= ~KNcnReadSimSc;			
       
   198 		}
       
   199 
       
   200 	// If SIM service is present and SIM SC should be read 
       
   201 	// in every boot, we enable KNcnSystemRefresh flag which will
       
   202 	// force SIM SC to be read. 
       
   203 	if( ( iNcnStatusBits & KNcnReadSimSc ) && 
       
   204 		( iNcnStatusBits & KNcnSmsServicePresent ) )
       
   205 		{
       
   206 		iNcnStatusBits &= ~KNcnReadSimSc;
       
   207 		iNcnStatusBits |= KNcnSystemRefresh;
       
   208 		}
       
   209 
       
   210     // Read service centres from SIM
       
   211     if( iSmsInitialisationPhase == ESMSInitNone )
       
   212         {
       
   213         NCN_RDEBUG(_L("CNcnModelBase::CheckIfSimSCOperationRequired() iSmsInitialisationPhase == ESMSInitNone" ));
       
   214         if( servicePresent )
       
   215             {
       
   216             NCN_RDEBUG(_L("CNcnModelBase::CheckIfSimSCOperationRequired() servicePresent" ));
       
   217             if( simChanged )
       
   218                 {
       
   219                 NCN_RDEBUG(_L("CNcnModelBase::CheckIfSimSCOperationRequired() simChanged" ));
       
   220                 PerformSimServiceCentreFetching();
       
   221                 }
       
   222             }
       
   223         return;
       
   224         }
       
   225     // Read service centres from SIM
       
   226     if ((( iSmsInitialisationPhase == ESMSInitReadServiceCentre ) && servicePresent ) ||
       
   227         // Initialisation complete
       
   228         (( iSmsInitialisationPhase == ESMSInitComplete ) && 
       
   229         ( simChanged  || iNcnStatusBits & KNcnSystemRefresh )))
       
   230         {
       
   231         NCN_RDEBUG(_L("CNcnModelBase::CheckIfSimSCOperationRequired() second Read service centres from SIM" ));
       
   232         PerformSimServiceCentreFetching();
       
   233         }
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CNcnModel::PerformSimServiceCentreFetching
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CNcnModel::PerformSimServiceCentreFetching()
       
   241     {
       
   242     NCN_RDEBUG(_L("CNcnModelBase::PerformSimServiceCentreFetching() :: Waiting until starting the SC operation" ));
       
   243 
       
   244     // If the sms service center is not fetched yet, then we create a
       
   245     // CMsgSimOperation class which does the fetching and then,
       
   246     // when completed, returns the status as iStatus.
       
   247     if( iNcnCRHandler && 
       
   248         ( !( iNcnStatusBits & KNcnSimServiceCentreFetched ) 
       
   249         || ( iNcnStatusBits & KNcnSystemRefresh ) ) )
       
   250         {
       
   251         // Read service centres from SIM
       
   252 		// 3 = read service centres from SIM
       
   253         iNcnCRHandler->SetSmumFlag( ESMSInitReadServiceCentre );
       
   254 
       
   255         iNcnStatusBits |= KNcnSimServiceCentreFetched;
       
   256         iNcnStatusBits &= ~KNcnSystemRefresh;
       
   257         if( IsActive() )
       
   258             {
       
   259             // Cancels the wait for completion of an outstanding request.
       
   260     		NCN_RDEBUG(_L("CNcnModelBase::PerformSimServiceCentreFetching() - cancelled outstanding request" ));
       
   261             Cancel();
       
   262             }
       
   263 
       
   264         // Ignore error, but don't let it leave
       
   265 		TRAPD( err, iMsgSimOperation = CMsgSimOperation::NewL( iStatus ) );
       
   266 		NCN_RDEBUG_INT2(_L("CNcnModelBase::PerformSimServiceCentreFetching - created CMsgSimOperation with status: %d error code: %d"), iStatus.Int(), err );
       
   267 
       
   268 		if( err == KErrNone )
       
   269 		    {
       
   270 		    SetActive();
       
   271 		    NCN_RDEBUG_INT(_L("CNcnModelBase::PerformSimServiceCentreFetching() - operation set active: %d"), iStatus.Int() );
       
   272 		    }
       
   273         }
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CNcnModel::ForceToPerformSimServiceCentreFetching
       
   278 // ---------------------------------------------------------
       
   279 //
       
   280 void CNcnModel::ForceToPerformSimServiceCentreFetching()
       
   281     {
       
   282     // Reset the sim service centre fetched information.
       
   283     iNcnStatusBits |= KNcnSystemRefresh;
       
   284     // Get the new sim service centre.
       
   285     CheckIfSimSCOperationRequired();
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------
       
   289 // CNcnModel::CreateCRConnectionL
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 void CNcnModel::CreateCRConnectionL()
       
   293     {
       
   294     // Create a handler for central repository information
       
   295     iNcnCRHandler = CNcnCRHandler::NewL( this );
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CNcnModel::AllowRefresh
       
   300 // Refresh query. Determines whether we allow the refresh to happen.
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 #ifdef _DEBUG
       
   304 TBool CNcnModel::AllowRefresh( TSatRefreshType aType, const TSatRefreshFiles& /*aFiles*/ )
       
   305 #else
       
   306 TBool CNcnModel::AllowRefresh( TSatRefreshType /*aType*/, const TSatRefreshFiles& /*aFiles*/ )
       
   307 #endif
       
   308 	{
       
   309  	// Refresh is always allowed
       
   310     NCN_RDEBUG( _L("CNcnModel::AllowRefresh()" ) );
       
   311     NCN_RDEBUG_INT( _L("CNcnModel::AllowRefresh() Refresh type: %d"), aType );
       
   312 	return ETrue;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CNcnModel::Refresh
       
   317 // Notification about file refresh. We should launch the fetching of the SMS
       
   318 // service center in case the changed file is KSmspEf
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 #ifdef _DEBUG
       
   322 void CNcnModel::Refresh( TSatRefreshType aType, const TSatRefreshFiles& /*aFiles*/ )
       
   323 #else
       
   324 void CNcnModel::Refresh( TSatRefreshType /*aType*/, const TSatRefreshFiles& /*aFiles*/ )
       
   325 #endif
       
   326 	{
       
   327 	// The only "file change" that we have subscribed is KSmspEf, so we don't need
       
   328 	// to examine the argument aFiles
       
   329     NCN_RDEBUG( _L("CNcnModel::Refresh()"));
       
   330     NCN_RDEBUG_INT( _L("CNcnModel::Refresh Type: %d"), aType );
       
   331 
       
   332 	//Load service center from SIM
       
   333 	ForceToPerformSimServiceCentreFetching();
       
   334 
       
   335     // Notify SAT Server that refresh initiated file read is done
       
   336     iSatRefresh->RefreshEFRead( EFalse );
       
   337 	}
       
   338 //  End of File