cellular/telephonysettings/src/PsetCallWaiting.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     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:  CPsetCallWaiting is call waiting SS setting abstraction.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //  Include Files
       
    21 #include "PsetCallWaiting.h"
       
    22 #include "MPsetCallWaitingObs.h"
       
    23 #include "nwdefs.h"             
       
    24 #include "PSetPanic.h"          
       
    25 #include "PsetConstants.h"      
       
    26 #include "MPsetRequestObs.h"
       
    27 #include "PSetUtility.h"
       
    28 #include "PhoneSettingsLogger.h"
       
    29 
       
    30 #include "PsetVariationProxy.h"
       
    31 #include <settingsinternalcrkeys.h>
       
    32 
       
    33 // CONSTANTS    
       
    34 _LIT( KPSNameOfClass, "CPsetCallWaiting" );
       
    35 
       
    36 //  MEMBER FUNCTIONS
       
    37 // ---------------------------------------------------------------------------
       
    38 // 
       
    39 // Symbian OS 1st phase constructor.
       
    40 // 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CPsetCallWaiting* CPsetCallWaiting::NewL( 
       
    44     RMobilePhone& aPhone, MPsetCallWaitingObserver& aObserver )
       
    45     {
       
    46     CPsetCallWaiting* self = new ( ELeave ) CPsetCallWaiting( aPhone );  
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL(aObserver);
       
    49     CleanupStack::Pop( self );         
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 
       
    55 // 2nd phase constructor.
       
    56 // 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CPsetCallWaiting::ConstructL(MPsetCallWaitingObserver& aObserver)
       
    60     {
       
    61     __PHSLOGSTRING("[PHS]--> CPsetCallWaiting::ConstructL" );
       
    62     this->SetPsuiObserver( aObserver );
       
    63     
       
    64     //Check which line is used, or if ALS is not active.
       
    65     TInt usedLine = ESSSettingsAlsNotSupported;
       
    66 
       
    67     iSsSettings = new (ELeave) RSSSettings;
       
    68     User::LeaveIfError( iSsSettings->Open() );
       
    69     TRAPD( err, iSsSettings->Register( ESSSettingsAls, *this ) );
       
    70     if ( err == KErrNone )
       
    71         {
       
    72         iSsSettings->Get( ESSSettingsAls, usedLine );
       
    73         }
       
    74         
       
    75     CPSetVariationProxy* variationProxy = 
       
    76         CPSetVariationProxy::NewL( KCRUidPhoneSettings, KPSetCallWaiting );
       
    77     CleanupStack::PushL( variationProxy );
       
    78     iCallWaitingDistinquishEnabled = variationProxy->IsFeatureEnabled( KCallWaitingDistiquishNotProvisioned );
       
    79     CleanupStack::PopAndDestroy( variationProxy );
       
    80 
       
    81     iAls = static_cast <TSSSettingsAlsValue> ( usedLine );
       
    82     __PHSLOGSTRING1("[PHS]    CPsetCallWaiting::ConstructL: usedLine: %d", usedLine );
       
    83     __PHSLOGSTRING("[PHS] <--CPsetCallWaiting::ConstructL" );
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // 
       
    88 // C++ constructor.
       
    89 // 
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CPsetCallWaiting::CPsetCallWaiting( RMobilePhone& aPhone) 
       
    93                 : CActive( EPriorityStandard ),
       
    94                   iPhone ( aPhone )
       
    95     {
       
    96     CActiveScheduler::Add( this );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // 
       
   101 // Destructor
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C CPsetCallWaiting::~CPsetCallWaiting()
       
   106     {
       
   107     Cancel();
       
   108     iReqObserver = NULL;
       
   109 
       
   110 	if ( iSsSettings )
       
   111         {
       
   112         iSsSettings->Cancel( ESSSettingsAls, *this ); 
       
   113         iSsSettings->Close();
       
   114         }
       
   115     delete iSsSettings;
       
   116     iSsSettings = NULL;
       
   117 	
       
   118     delete iCwInterrogator;
       
   119     iCwInterrogator = NULL;
       
   120     }
       
   121     
       
   122 // ---------------------------------------------------------------------------
       
   123 // 
       
   124 // If SsSettings notifies of settings change, copy new value to member variable.
       
   125 // 
       
   126 // ---------------------------------------------------------------------------
       
   127 void CPsetCallWaiting::PhoneSettingChanged( TSSSettingsSetting aSetting, TInt aNewValue )
       
   128 	{
       
   129 	__PHSLOGSTRING("[PHS]--> PhoneSettingChanged::ValidateBsc" );
       
   130 	if ( aSetting == ESSSettingsAls )
       
   131         {
       
   132         iAls = static_cast <TSSSettingsAlsValue> (aNewValue);
       
   133         }
       
   134     __PHSLOGSTRING("[PHS] <--PhoneSettingChanged::ValidateBsc" );
       
   135 	}
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // 
       
   139 // Validates used bsc, if EUnknown, updates to real value
       
   140 // 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CPsetCallWaiting::ValidateBsc( TBasicServiceGroups& aBsc )
       
   144     {
       
   145     __PHSLOGSTRING("[PHS]--> CPsetCallWaiting::ValidateBsc" );
       
   146     if ( aBsc == EUnknown )
       
   147     // if bsc is unknown, update it
       
   148         {
       
   149         if ( iAls == ESSSettingsAlsAlternate )
       
   150             {
       
   151             aBsc = EAltTele;
       
   152             }
       
   153         else
       
   154             {
       
   155             aBsc = ETelephony;
       
   156             }
       
   157         }    
       
   158     else
       
   159     // If no specific line is indicated
       
   160         {
       
   161         if ( aBsc == EAllTeleAndBearer || aBsc == EAllTele )
       
   162             {
       
   163             // if ALS is used, use 89 bsc
       
   164             if ( iAls == ESSSettingsAlsAlternate )
       
   165                 {
       
   166                 aBsc = EAltTele;
       
   167                 }
       
   168             }
       
   169         }
       
   170     __PHSLOGSTRING("[PHS] <--CPsetCallWaiting::ValidateBsc" );
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // 
       
   175 // Sets call waiting.
       
   176 // 
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C void CPsetCallWaiting::SetCallWaitingL
       
   180     ( TSetCallWaiting aSetting, TBasicServiceGroups aBsc )
       
   181     {
       
   182     __PHSLOGSTRING("[PHS]--> CPsetCallWaiting::SetCallWaitingL");
       
   183     if ( IsActive() )
       
   184         {
       
   185         User::Leave( KErrInUse );
       
   186         }
       
   187     /*****************************************************
       
   188     *    Series 60 Customer / ETel
       
   189     *    Series 60  ETel API
       
   190     *****************************************************/
       
   191     RMobilePhone::TMobilePhoneServiceAction cwAction = 
       
   192         RMobilePhone::EServiceActionUnspecified;
       
   193     
       
   194     RMobilePhone::TMobileService cwBasicServiceGroup;
       
   195 
       
   196 	ValidateBsc( aBsc );
       
   197 
       
   198     if ( aBsc == EAltTele )
       
   199         {
       
   200         cwBasicServiceGroup = PSetUtility::VerifyAltLineUseL();
       
   201         }
       
   202 
       
   203 	cwBasicServiceGroup = PSetUtility::ChangeToEtelInternal( aBsc );
       
   204 
       
   205     if ( aSetting == EActivateCallWaiting )
       
   206         {
       
   207         cwAction = RMobilePhone::EServiceActionActivate;
       
   208         }
       
   209     else 
       
   210         {
       
   211         cwAction = RMobilePhone::EServiceActionDeactivate;
       
   212         }
       
   213 
       
   214     //Copy data to member variables.
       
   215     iSetValue = aSetting;
       
   216 
       
   217     //Start requesting for setting CW.
       
   218     iPhone.SetCallWaitingStatus( iStatus, cwBasicServiceGroup, cwAction);
       
   219 
       
   220     SetActive();
       
   221     SetRequestStatus( EPSetServiceRequestSetCallWaiting );
       
   222 
       
   223     //Set PSUI so that correct observer is used and show requesting note.
       
   224     CleanupLeavePushL();
       
   225     iObserver->SetEngineContact( *this );
       
   226     iObserver->HandleCWRequestingL( ETrue, EFalse );
       
   227     CleanupStack::Pop();
       
   228     __PHSLOGSTRING("[PHS] <--CPsetCallWaiting::SetCallWaitingL");
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // 
       
   233 // Requests call waiting status.
       
   234 // 
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 EXPORT_C void CPsetCallWaiting::GetCallWaitingStatusL()
       
   238     {
       
   239     __PHSLOGSTRING("[PHS]--> CPsetCallWaiting::GetCallWaitingStatusL");
       
   240     if ( IsActive() )
       
   241         {
       
   242         User::Leave( KErrInUse );
       
   243         }    
       
   244 
       
   245     SetRequestStatus( EPSetServiceRequestGetCallWaitingStatus );
       
   246 
       
   247     //Start requesting for CW status.
       
   248     iCwInterrogator = CRetrieveMobilePhoneCWList::NewL( iPhone );
       
   249     iCwInterrogator->Start( iStatus );
       
   250     
       
   251     SetActive();
       
   252 
       
   253     //Set PSUI so that correct observer is used and show requesting note.
       
   254     CleanupLeavePushL();
       
   255     iObserver->SetEngineContact( *this );
       
   256     iObserver->HandleCWRequestingL( ETrue, EFalse );
       
   257     CleanupStack::Pop(); //CleanupLeavePushL
       
   258     __PHSLOGSTRING("[PHS] <--CPsetCallWaiting::GetCallWaitingStatusL");
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // 
       
   263 // Cancel process.
       
   264 // 
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 EXPORT_C TInt CPsetCallWaiting::CancelProcess()
       
   268     {
       
   269     // Set PSUI so that correct observer is used and hide requesting note.
       
   270     // When interrupting a note, does not leave.
       
   271     // This needs to be done first, since notes must be cleared from screen
       
   272     // even though request is not active.
       
   273     iObserver->SetEngineContact( *this );
       
   274     // Does not leave
       
   275 	TRAPD( err, iObserver->HandleCWRequestingL( EFalse, ETrue ) );
       
   276 	
       
   277     if ( !IsActive() || err != KErrNone )
       
   278         {
       
   279         return KErrGeneral;
       
   280         }            
       
   281     Cancel();
       
   282 
       
   283     return KErrNone;
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // Sets request observer.
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 EXPORT_C void CPsetCallWaiting::SetRequestObserver( MPsetRequestObserver* aObs )
       
   291     {
       
   292     iReqObserver = aObs;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // 
       
   297 // Run active object.
       
   298 // 
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CPsetCallWaiting::RunL()
       
   302     {
       
   303     __PHSLOGSTRING("[PHS]--> CPsetCallWaiting::RunL");
       
   304 
       
   305     __ASSERT_ALWAYS( iObserver, Panic( KPSNameOfClass, ECWPanicNoObserver ) );
       
   306 
       
   307     // Set PSUI so that correct observer is used and hide requesting note.
       
   308     // does not leave when deleting a note.
       
   309     iObserver->SetEngineContact( *this );
       
   310     iObserver->HandleCWRequestingL( EFalse, EFalse );
       
   311 
       
   312     if ( iStatus != KErrNone )
       
   313         {
       
   314         iObserver->HandleCWErrorL( iStatus.Int() );
       
   315         RequestCompleted( iStatus.Int() );
       
   316         return;
       
   317         } 
       
   318 
       
   319     TUint8 arrayOfBsc[KPSetNumberOfBsc];
       
   320     switch ( iServiceRequest )
       
   321         {
       
   322         case EPSetServiceRequestGetCallWaitingStatus:
       
   323             {
       
   324             __PHSLOGSTRING("[PHS]    CPsetCallWaiting::RunL: EPSetServiceRequestGetCallWaitingStatus");
       
   325             CMobilePhoneCWList* cwStatusList = iCwInterrogator->RetrieveListL();
       
   326             CleanupStack::PushL( cwStatusList );
       
   327             TGetCallWaitingStatus status = EStatusUnknown;
       
   328 
       
   329             /*****************************************************
       
   330             *    Series 60 Customer / ETel
       
   331             *    Series 60  ETel API
       
   332             *****************************************************/
       
   333             RMobilePhone::TMobilePhoneCWInfoEntryV1 cwInfo;
       
   334             TInt entries = cwStatusList->Enumerate();
       
   335             TInt i = 0;
       
   336             while ( entries > i)
       
   337                 {
       
   338                 cwInfo = cwStatusList->GetEntryL( i );
       
   339                 if ( cwInfo.iStatus == RMobilePhone::ECallWaitingStatusActive )
       
   340                     {
       
   341                     status = TGetCallWaitingStatus( cwInfo.iStatus );
       
   342                     }
       
   343                     
       
   344                 if ( iCallWaitingDistinquishEnabled && status == EStatusUnknown 
       
   345                     && cwInfo.iStatus != RMobilePhone::ECallWaitingStatusUnknown )
       
   346                     {
       
   347                     // pass on the status if the current status is still 
       
   348                     // unknown and the received status is not unknown
       
   349                     switch ( cwInfo.iStatus )
       
   350                     	{
       
   351                     	case RMobilePhone::ECallWaitingStatusNotProvisioned:
       
   352                     		{
       
   353                     		status = EStatusNotProvisioned;
       
   354                     		break;
       
   355                     		}	
       
   356                     		
       
   357                     		case RMobilePhone::ECallWaitingStatusNotAvailable:
       
   358                     		{		
       
   359                     		status = EStatusNotAvailable;
       
   360                     		break;
       
   361                     		}
       
   362                     		
       
   363                     		default:
       
   364                     		{	
       
   365                     		status = TGetCallWaitingStatus( cwInfo.iStatus );
       
   366                     		break;		
       
   367                     		}
       
   368                     	}
       
   369                     }
       
   370                     
       
   371                 arrayOfBsc[i] = static_cast <TUint8> 
       
   372                     ( PSetUtility::ChangeToGSM( cwInfo.iServiceGroup ) );
       
   373                 i++;                                                                
       
   374                 }
       
   375             arrayOfBsc[i++] = KPSetUnusedValue;
       
   376             CleanupStack::PopAndDestroy( cwStatusList );
       
   377             iObserver->SetEngineContact( *this );
       
   378             iObserver->HandleCallWaitingGetStatusL( status, arrayOfBsc );
       
   379             }
       
   380             break;
       
   381         case EPSetServiceRequestSetCallWaiting:
       
   382             __PHSLOGSTRING("[PHS]    CPsetCallWaiting::RunL: EPSetServiceRequestSetCallWaiting");
       
   383             // Set PSUI so that correct observer is used and show note.
       
   384             iObserver->SetEngineContact( *this );
       
   385             iObserver->HandleCallWaitingChangedL( iSetValue, iStatus.Int() );
       
   386             break;
       
   387         default:
       
   388             Panic( KPSNameOfClass, ECWPanicInvalidRequestMode );
       
   389         }
       
   390     RequestCompleted( KErrNone );
       
   391     
       
   392     __PHSLOGSTRING("[PHS] <--CPsetCallWaiting::RunL");
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // 
       
   397 // Cancels active object.
       
   398 // 
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CPsetCallWaiting::DoCancel()
       
   402     {    
       
   403     switch ( iServiceRequest )
       
   404         {
       
   405         case EPSetServiceRequestGetCallWaitingStatus:
       
   406             iCwInterrogator->Cancel();
       
   407             delete iCwInterrogator;
       
   408             iCwInterrogator = NULL;
       
   409             break;
       
   410         case EPSetServiceRequestSetCallWaiting:
       
   411             iPhone.CancelAsyncRequest( EMobilePhoneSetCallWaitingStatus );
       
   412             break;
       
   413         default:
       
   414             break;
       
   415         } 
       
   416     SetRequestStatus( EPSetServiceRequestNone );
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // 
       
   421 // Sets observer (member variable)
       
   422 //  
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CPsetCallWaiting::SetPsuiObserver( MPsetCallWaitingObserver& aObserver )
       
   426     {
       
   427     iObserver = &aObserver;
       
   428     iObserver->SetEngineContact( *this );
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // 
       
   433 // Push object into cleanupstack to catch leaving.
       
   434 // 
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CPsetCallWaiting::CleanupLeavePushL()
       
   438       {
       
   439       CleanupStack::PushL( TCleanupItem( DoHandleLeave, this ) );
       
   440       }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // 
       
   444 // Object has caused a leave.
       
   445 // 
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void CPsetCallWaiting::DoHandleLeave( TAny* aAny )
       
   449       {
       
   450       REINTERPRET_CAST( CPsetCallWaiting*, aAny )->HandleLeave();
       
   451       }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // 
       
   455 // Things to do when leave occurs.
       
   456 // 
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 void CPsetCallWaiting::HandleLeave()
       
   460     {
       
   461     CancelProcess();
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // Inform the request observer that request has been completed.
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 void CPsetCallWaiting::RequestCompleted( const TInt& aError )
       
   469     {
       
   470     if ( aError != KErrNone )
       
   471         {
       
   472         SetRequestStatus( static_cast <TPSetServiceRequest> (aError) );
       
   473         }
       
   474     SetRequestStatus( EPSetServiceRequestNone );
       
   475 
       
   476     if ( iReqObserver )
       
   477         {
       
   478         iReqObserver->RequestComplete(); 
       
   479         }
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // Update the request status - both internally and to observers.
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 void CPsetCallWaiting::SetRequestStatus( TPSetServiceRequest aStatus )
       
   487     {
       
   488     iServiceRequest = aStatus;
       
   489     if ( iReqObserver )
       
   490         {
       
   491         iReqObserver->RequestStatusChanged( aStatus );
       
   492         }
       
   493     }
       
   494 
       
   495 // End of file