cellular/SSSettings/src/CSSSettingsNotifier.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Notifier for changes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <rmmcustomapi.h>
       
    21 #include    <centralrepository.h>
       
    22 #include    <SSSettingsPrivateCRKeys.h>
       
    23 
       
    24 #include    "CSSSettingsNotifier.h"
       
    25 #include    "MSSSettingsObserver.h"
       
    26 #include    "CSSSettingsAlsNotifier.h"
       
    27 #include    "SSSettingsLogger.h"
       
    28 
       
    29 
       
    30 // DATA TYPES
       
    31 
       
    32 /**
       
    33 * It enumerates all keys to be notified from Central Repository under 
       
    34 * KCRUidSupplementaryServiceSettings.
       
    35 *
       
    36 *   ESSSettingsKeyNone    - No key change to be notified.
       
    37 *   ESSSettingsKeyAlsLine - Als line change to be notified.
       
    38 *   ESSSettingsKeyClir    - Clir change to be notified.
       
    39 *   ESSSettingsKeyCug     - Cug change to be notified.
       
    40 *   ESSSettingsKeyAll     - All keys to be notified.
       
    41 */
       
    42 enum TSSSettingsCenRepNotifyKey
       
    43     {
       
    44     ESSSettingsKeyNone    = 0x00000000,
       
    45     ESSSettingsKeyAlsLine = 0x00000001,
       
    46     ESSSettingsKeyClir    = 0x00000002,
       
    47     ESSSettingsKeyCug     = 0x00000004,
       
    48 
       
    49     // Keep as last.
       
    50     ESSSettingsKeyAll     = 0xFFFFFFFF
       
    51     };
       
    52 
       
    53 
       
    54 // ================= MEMBER FUNCTIONS =======================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSSSettingsNotifier::CSSSettingsNotifier
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSSSettingsNotifier::CSSSettingsNotifier( RSSSettings& aSettings ) 
       
    61 : CActive( EPriorityStandard ), 
       
    62   iSettings( aSettings ),
       
    63   iNotifyKeys ( ESSSettingsKeyNone )
       
    64     {
       
    65     CActiveScheduler::Add( this );
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CSSSettingsNotifier::ConstructL
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CSSSettingsNotifier::ConstructL()
       
    74     {
       
    75     iAls = CSSSettingsAlsNotifier::NewL( 
       
    76         iSettings.iData->iMobilePhone,
       
    77         *iSettings.iData->iCustomPhone,
       
    78         *this );
       
    79 
       
    80     iRepository = CRepository::NewL( KCRUidSupplementaryServiceSettings );
       
    81     
       
    82     iCenRepAlsNotifyHandler = CCenRepNotifyHandler::NewL(
       
    83         *this, 
       
    84         *iRepository,
       
    85         CCenRepNotifyHandler::EIntKey,
       
    86         KSettingsAlsLine );
       
    87     
       
    88     iCenRepClirNotifyHandler = CCenRepNotifyHandler::NewL(
       
    89         *this, 
       
    90         *iRepository,
       
    91         CCenRepNotifyHandler::EIntKey,
       
    92         KSettingsCLIR );
       
    93     
       
    94     iCenRepCugNotifyHandler = CCenRepNotifyHandler::NewL(
       
    95         *this, 
       
    96         *iRepository,
       
    97         CCenRepNotifyHandler::EIntKey,
       
    98         KSettingsCUG );
       
    99     
       
   100     // Start listening all the keys, the notify is handled only if there is
       
   101     // notify request made.
       
   102     iCenRepAlsNotifyHandler->StartListeningL();
       
   103     iCenRepClirNotifyHandler->StartListeningL();
       
   104     iCenRepCugNotifyHandler->StartListeningL();
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSSSettingsNotifier::~CSSSettingsNotifier
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CSSSettingsNotifier::~CSSSettingsNotifier()
       
   112     {
       
   113     Cancel();
       
   114 	if( iCenRepAlsNotifyHandler )
       
   115     	{
       
   116         iCenRepAlsNotifyHandler->StopListening();
       
   117     	}
       
   118 
       
   119     if( iCenRepClirNotifyHandler )
       
   120         {
       
   121         iCenRepClirNotifyHandler->StopListening();
       
   122         }
       
   123 
       
   124     if( iCenRepCugNotifyHandler )
       
   125         {
       
   126         iCenRepCugNotifyHandler->StopListening();
       
   127         }
       
   128     
       
   129     delete iCenRepAlsNotifyHandler;
       
   130     delete iCenRepClirNotifyHandler;
       
   131     delete iCenRepCugNotifyHandler;
       
   132     delete iRepository;
       
   133     delete iAls;
       
   134 
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CSSSettingsNotifier::AddNotifier
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TInt CSSSettingsNotifier::AddNotifier( TSSSettingsSetting aSetting )
       
   142     {
       
   143     __SSSLOGSTRING("[SSS]--> CSSSettingsNotifier::AddNotifier");
       
   144     TInt error(KErrNone);
       
   145     switch ( aSetting )
       
   146         {
       
   147         case ESSSettingsCug:
       
   148             iNotifyKeys = ( iNotifyKeys | ESSSettingsKeyCug );
       
   149             break;
       
   150 
       
   151         case ESSSettingsClir:
       
   152             iNotifyKeys = ( iNotifyKeys | ESSSettingsKeyClir );
       
   153             break;
       
   154 
       
   155         case ESSSettingsAls:
       
   156             error = iAls->NotifyAlsChange();
       
   157             if ( error == KErrNone || error == KErrAlreadyExists )
       
   158                 {
       
   159                 iNotifyKeys = ( iNotifyKeys | ESSSettingsKeyAlsLine );
       
   160                 }
       
   161             break;
       
   162 
       
   163         case ESSSettingsAlsBlocking:
       
   164             // Handled via active object
       
   165             if ( !IsActive() )
       
   166                 {
       
   167                 iSettings.iData->iCustomPhone->NotifyAlsBlockedChanged( 
       
   168                     iStatus, iAlsBlockStatus );
       
   169                 SetActive();
       
   170                 }
       
   171             else
       
   172                 {
       
   173                 error = KErrAlreadyExists;
       
   174                 }
       
   175             break;
       
   176 
       
   177         case ESSSettingsDefaultCug:
       
   178             //CUG default cannot be changed
       
   179             break;
       
   180 
       
   181         default:
       
   182             error = KErrNotSupported;
       
   183         }   
       
   184 
       
   185     __SSSLOGSTRING1("[SSS]     CSSSettingsNotifier::AddNotifier: error: %d", error );
       
   186     __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::AddNotifier");
       
   187     return error;
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CSSSettingsNotifier::RemoveNotifier
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CSSSettingsNotifier::RemoveNotifier( TSSSettingsSetting aSetting )
       
   195     {
       
   196     __SSSLOGSTRING("[SSS]--> CSSSettingsNotifier::RemoveNotifier");
       
   197     switch ( aSetting )
       
   198         {
       
   199         case ESSSettingsCug:
       
   200             iNotifyKeys = ( iNotifyKeys & ( ~ESSSettingsKeyCug ) );
       
   201             break;
       
   202 
       
   203         case ESSSettingsClir:
       
   204             iNotifyKeys = ( iNotifyKeys & ( ~ESSSettingsKeyClir ) );
       
   205             break;
       
   206 
       
   207         case ESSSettingsAls:
       
   208             if ( iAls )
       
   209                 {
       
   210                 iAls->CancelNotify();
       
   211                 }
       
   212             iNotifyKeys = ( iNotifyKeys  & ( ~ESSSettingsKeyAlsLine ) );
       
   213             break;
       
   214 
       
   215         case ESSSettingsAlsBlocking:
       
   216             Cancel();
       
   217             break;
       
   218 
       
   219         default:
       
   220             break;
       
   221         } 
       
   222     __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::RemoveNotifier");
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CSSSettingsNotifier::RunL
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CSSSettingsNotifier::RunL()
       
   230     {
       
   231     __SSSLOGSTRING("[SSS]--> CSSSettingsNotifier::RunL");
       
   232     switch ( iStatus.Int() )
       
   233         {
       
   234         case KErrCancel:
       
   235         case KErrNotSupported:
       
   236             return;
       
   237         case KErrNone:
       
   238             // Inform observers
       
   239             switch ( iAlsBlockStatus )
       
   240                 {
       
   241                 case RMmCustomAPI::EBlockStatusNotSupported: 
       
   242                     iSettings.InformChange( 
       
   243                         ESSSettingsAlsBlocking, 
       
   244                         static_cast <TInt>( 
       
   245                         ESSSettingsAlsBlockingNotSupported ) );
       
   246                     break;
       
   247                 case RMmCustomAPI::EBlockStatusActive: 
       
   248                     iSettings.InformChange( 
       
   249                         ESSSettingsAlsBlocking, 
       
   250                         static_cast <TInt>( ESSSettingsAlsBlockingOn ) );
       
   251                     break;
       
   252                 case RMmCustomAPI::EBlockStatusInactive: 
       
   253                     iSettings.InformChange( ESSSettingsAlsBlocking,
       
   254                         static_cast <TInt>( ESSSettingsAlsBlockingOff ) );
       
   255                     break;
       
   256                 case RMmCustomAPI::EBlockStatusUnknown: 
       
   257                     break;
       
   258                 default:
       
   259                     break;
       
   260                 }
       
   261             break;
       
   262         default:
       
   263             break;
       
   264         }
       
   265 
       
   266     // re-activate request.
       
   267     iSettings.iData->iCustomPhone->NotifyAlsBlockedChanged( 
       
   268         iStatus, iAlsBlockStatus );
       
   269     SetActive();
       
   270 
       
   271     __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::RunL");
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CSSSettingsNotifier::DoCancel
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CSSSettingsNotifier::DoCancel()
       
   279     {
       
   280     iSettings.iData->iCustomPhone->CancelAsyncRequest( 
       
   281         ECustomNotifyAlsBlockedChangedIPC );
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CSSSettingsNotifier::HandleNotifyInt
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CSSSettingsNotifier::HandleNotifyInt( TUint32 aId, TInt aNewValue )
       
   289     {
       
   290     __SSSLOGSTRING2("[SSS] -->CSSSettingsNotifier::HandleNotifyInt aId: %d  aNewValue: %d", aId, aNewValue);
       
   291     // First check CUG mode
       
   292     if ( aId == KSettingsCUG )
       
   293         {
       
   294         // Inform change only if Cug notify request is on.
       
   295         if ( iNotifyKeys & ESSSettingsKeyCug )
       
   296             {
       
   297             iSettings.InformChange(
       
   298                 ESSSettingsCug,
       
   299                 aNewValue );
       
   300             }
       
   301         }
       
   302 
       
   303     // Then CLIR
       
   304     else if ( aId == KSettingsCLIR )
       
   305         {
       
   306         // Inform change only if Clir notify request is on.
       
   307         if ( iNotifyKeys & ESSSettingsKeyClir )
       
   308             {
       
   309             iSettings.InformChange(
       
   310                 ESSSettingsClir,
       
   311                 aNewValue );
       
   312             }
       
   313         }
       
   314 
       
   315     // ALS - not forwarded if not supported
       
   316     else if ( aId == KSettingsAlsLine )
       
   317         {
       
   318         // Inform change only if Als line notify request is on.
       
   319         if ( iNotifyKeys & ESSSettingsKeyAlsLine )
       
   320             {
       
   321             TBool ppSupported(EFalse);
       
   322             TBool simSupported(EFalse);
       
   323             TBool cspSupported(EFalse);
       
   324             TInt cspError(KErrNone);
       
   325             iAls->GetAlsSupport( ppSupported, 
       
   326                                 simSupported, 
       
   327                                 cspSupported, 
       
   328                                 cspError );
       
   329             __SSSLOGSTRING1("[SSS]    ppSupported:  %d", ppSupported);
       
   330             __SSSLOGSTRING1("[SSS]    simSupported: %d", simSupported);
       
   331             __SSSLOGSTRING1("[SSS]    cspSupported: %d", cspSupported);
       
   332             __SSSLOGSTRING1("[SSS]    cspError:     %d", cspError);
       
   333             if ( AlsSupport( ppSupported, cspSupported, cspError ) )
       
   334                 {
       
   335                 __SSSLOGSTRING1("[SSS] ->InformChange aNewValue:%d", aNewValue);
       
   336                 iSettings.InformChange(
       
   337                     ESSSettingsAls,
       
   338                     aNewValue );
       
   339                 }
       
   340             else
       
   341                 {
       
   342                 __SSSLOGSTRING("[SSS] ->InformChange AlsNotSupported ");
       
   343                 iSettings.InformChange( 
       
   344                     ESSSettingsAls,
       
   345                     ESSSettingsAlsNotSupported );
       
   346                 }
       
   347             }
       
   348         }
       
   349     // Other
       
   350     else
       
   351         {
       
   352         __ASSERT_DEBUG( EFalse, User::Invariant() );
       
   353         }
       
   354     __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::HandleNotifyInt");
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CSSSettingsNotifier::AlsSupport
       
   359 // -----------------------------------------------------------------------------
       
   360 //
       
   361 TBool CSSSettingsNotifier::AlsSupport( TBool aPPSupport, TBool aCSPSupport,
       
   362     TInt aCSPError )
       
   363     {
       
   364     TBool send(EFalse);
       
   365     // If aCSPSupport is false and CSP doesnt return error then it is not
       
   366     // needed to send notification to clients.
       
   367     if ( aPPSupport || ( aCSPSupport && aCSPError == KErrNone ) ) 
       
   368         {
       
   369         send = ETrue;
       
   370         }
       
   371     
       
   372     return send;
       
   373     }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // CSSSettingsNotifier::HandleNotifyError
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CSSSettingsNotifier::HandleNotifyError( TUint32 /*aId*/, TInt /*aError*/,
       
   380     CCenRepNotifyHandler* /*aHandler*/ )
       
   381     {
       
   382     // Here you could call the below, if you are sure that it do not cause 
       
   383     // eternal loop
       
   384     // TRAPD( error, aHandler->StartListeningL() );
       
   385     }
       
   386 
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CSSSettingsNotifier::GetAlsHandler
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 CSSSettingsAlsNotifier* CSSSettingsNotifier::GetAlsHandler()
       
   393     {
       
   394     __SSSLOGSTRING("[SSS]--> CSSSettingsNotifier::GetAlsHandler");
       
   395     TBool ppSupported(EFalse);
       
   396     TBool simSupported(EFalse);
       
   397     TBool cspSupported(EFalse);
       
   398     TInt cspError(KErrNone);
       
   399     iAls->GetAlsSupport( ppSupported, simSupported, cspSupported, cspError );
       
   400     __SSSLOGSTRING1("[SSS]     CSSSettingsNotifier::GetAlsHandler: ppSupported: %d", ppSupported );
       
   401     __SSSLOGSTRING1("[SSS]     CSSSettingsNotifier::GetAlsHandler: simSupported: %d", simSupported );
       
   402     __SSSLOGSTRING1("[SSS]     CSSSettingsNotifier::GetAlsHandler: cspSupported: %d", cspSupported );
       
   403     if ( ppSupported || simSupported || cspSupported )
       
   404         {
       
   405         __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::GetAlsHandler: ALS supported");
       
   406         return iAls; // returned only if supported
       
   407         }
       
   408 
       
   409     __SSSLOGSTRING("[SSS] <--CSSSettingsNotifier::GetAlsHandler: NULL returned");
       
   410     return NULL;
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CSSSettingsNotifier::HandleRefresh
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 TInt CSSSettingsNotifier::HandleRefresh()
       
   418     {
       
   419     return iAls->HandleRefresh();
       
   420     }
       
   421 
       
   422 //  End of File