cellular/SSSettings/src/CSSSettingsRefreshHandler.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004-2008 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:  The Refresh handler to inform SAT refresses.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <centralrepository.h>
       
    22 #include    <rsatrefresh.h> 
       
    23 #include    <BTSapDomainPSKeys.h> // bt sap central repository key. 
       
    24 #include    <featmgr.h>
       
    25 
       
    26 #include    "csssettingsrefreshhandler.h" 
       
    27 #include    "sssettingslogger.h" 
       
    28 #include    "csssettingsactiveobject.h" 
       
    29 
       
    30 // ============================= LOCAL FUNCTIONS ===============================
       
    31 
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 *  The Refresh notify observer info container.
       
    37 *
       
    38 *  @lib SsSettings.lib
       
    39 *  @since 2.6
       
    40 */
       
    41 class CSSSettingsNotifyInfo
       
    42 :public CBase
       
    43     {
       
    44     public: // Data
       
    45 
       
    46         // Refresh observer.
       
    47         MSSSettingsRefreshObserver* iObserver;
       
    48 
       
    49         // Observed file.
       
    50         TSatElementaryFiles    iObservedFile;
       
    51 
       
    52         // Observed refresh type.
       
    53         TSatRefreshType      iObservedRefreshType;
       
    54     };
       
    55 
       
    56 
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSSSettingsRefreshHandler::CSSSettingsRefreshHandler
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSSSettingsRefreshHandler::CSSSettingsRefreshHandler()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSSSettingsRefreshHandler::ConstructL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CSSSettingsRefreshHandler::ConstructL()
       
    73     {
       
    74     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::ConstructL");
       
    75     iNotifyInfo = new ( ELeave ) CSSSettingsNotifyInfo;
       
    76 
       
    77     User::LeaveIfError ( iRSSSettings.Open() );
       
    78 
       
    79     User::LeaveIfError ( iRCspCache.Open() );
       
    80 
       
    81     iRSatSession.ConnectL();
       
    82 
       
    83     iRSatRefresh = new ( ELeave ) RSatRefresh ( *this);
       
    84     iRSatRefresh->OpenL( iRSatSession );
       
    85     iRSatRefresh->NotifyFileChangeL();
       
    86     
       
    87     if ( FeatureManager::FeatureSupported ( KFeatureIdBtSap ) )
       
    88         {
       
    89         //create the active object instance
       
    90         iBtSapNotifier = CSSSettingsActiveObject::NewL(
       
    91             KPSUidBluetoothSapConnectionState,
       
    92             KBTSapConnectionState,
       
    93             *this );
       
    94 
       
    95         //subscribe for key event notifications
       
    96         iBtSapNotifier->NotifyKeyChange();        
       
    97         }        
       
    98     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::ConstructL");
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSSSettingsRefreshHandler::NewL
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CSSSettingsRefreshHandler* CSSSettingsRefreshHandler::NewL()
       
   106     {
       
   107     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::NewL");
       
   108     CSSSettingsRefreshHandler* self = new( ELeave ) CSSSettingsRefreshHandler;
       
   109     
       
   110     CleanupStack::PushL( self );
       
   111     self->ConstructL();
       
   112     CleanupStack::Pop();
       
   113 
       
   114     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::NewL");
       
   115     return self;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler()
       
   123     {
       
   124     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler");
       
   125     if ( iRSatRefresh )
       
   126         {
       
   127         iRSatRefresh->Cancel();
       
   128         iRSatRefresh->Close();
       
   129         delete iRSatRefresh;
       
   130         iRSatRefresh = NULL;
       
   131         }
       
   132     iRSatSession.Close();
       
   133     iRSSSettings.Close();
       
   134 
       
   135     delete iNotifyInfo;
       
   136     iNotifyInfo = NULL;
       
   137 
       
   138     if ( FeatureManager::FeatureSupported ( KFeatureIdBtSap ) )
       
   139         {
       
   140         if( iBtSapNotifier )
       
   141             {
       
   142             iBtSapNotifier->CancelNotify();
       
   143             }
       
   144         delete iBtSapNotifier;
       
   145         } 
       
   146         
       
   147     iRCspCache.Close();
       
   148                
       
   149     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler");
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CSSSettingsRefreshHandler::NotifyFileChangeL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CSSSettingsRefreshHandler::NotifyFileChangeL(
       
   157     MSSSettingsRefreshObserver& aObserver,
       
   158     TSatElementaryFiles aObservedFiles,
       
   159     TSatRefreshType aObservedRefreshType )
       
   160     {
       
   161     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::NotifyFileChangeL");
       
   162     // Update variables.
       
   163     iNotifyInfo->iObserver = &aObserver;
       
   164     iNotifyInfo->iObservedFile = aObservedFiles;
       
   165     iNotifyInfo->iObservedRefreshType = aObservedRefreshType;
       
   166     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::NotifyFileChangeL");
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CSSSettingsRefreshHandler::CancelNotify
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CSSSettingsRefreshHandler::CancelNotify()
       
   174     {
       
   175     iNotifyInfo->iObserver = NULL;    
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CSSSettingsRefreshHandler::ChangedCspTable
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 TInt CSSSettingsRefreshHandler::ChangedCspTable( 
       
   183     TDes8& aChangedCsps,
       
   184     TDes8& aNewValues )
       
   185     {
       
   186     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::ChangedCspTable");
       
   187     return iRCspCache.ChangedCspTable( 
       
   188         aChangedCsps,
       
   189         aNewValues );    
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CSSSettingsRefreshHandler::AllowRefresh
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TBool CSSSettingsRefreshHandler::AllowRefresh(
       
   197     TSatRefreshType aType,
       
   198     const TSatRefreshFiles& aFiles )
       
   199     {
       
   200     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::AllowRefresh");
       
   201     return DoHandleRefresh( aType, aFiles, ESSSettingsAllowRefresh );
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CSSSettingsRefreshHandler::Refresh
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CSSSettingsRefreshHandler::Refresh(
       
   209     TSatRefreshType aType,
       
   210     const TSatRefreshFiles& aFiles )
       
   211     {
       
   212     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::Refresh");
       
   213     DoHandleRefresh(  aType, aFiles, ESSSettingsRefresh );
       
   214     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::Refresh");
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CSSSettingsRefreshHandler::DoHandleRefresh
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TBool CSSSettingsRefreshHandler::DoHandleRefresh(
       
   222     TSatRefreshType aType,
       
   223     const TSatRefreshFiles& aFiles,
       
   224     const TSSSettingsRefreshFunction aFunctionality )
       
   225     {    
       
   226     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::DoHandleRefresh");
       
   227     if ( aFunctionality == ESSSettingsRefresh )
       
   228         {
       
   229         // Refresh handling needed only if the refresh has happened.
       
   230         iRCspCache.HandleRefresh();
       
   231         iRSSSettings.HandleRefresh();
       
   232         }
       
   233 
       
   234     TBool cspEfFound =  
       
   235         aFiles.Locate( KCsp1Ef ) != KErrNotFound || 
       
   236         aFiles.Locate( KCsp2Ef ) != KErrNotFound; 
       
   237 
       
   238     // KCspEf is no longer provided by SAT but GS and PS seem to depend on it, 
       
   239     // handled here for now. 
       
   240     TBool fileFound =  
       
   241         aFiles.Locate( iNotifyInfo->iObservedFile ) != KErrNotFound || 
       
   242         cspEfFound && iNotifyInfo->iObservedFile == KCspEf; 
       
   243 
       
   244 
       
   245     // By default refresh is allowed.
       
   246     TBool allow(ETrue);
       
   247 
       
   248     // Handle only if there is observer.
       
   249     if ( iNotifyInfo->iObserver )
       
   250         {
       
   251         // Handle only if observer wants to listen this event.
       
   252         if ( iNotifyInfo->iObservedRefreshType & aType )
       
   253             {
       
   254             if ( aType != EFileChangeNotification || fileFound )
       
   255                 {
       
   256                 if ( aFunctionality == ESSSettingsRefresh )
       
   257                     {
       
   258                     // Inform the observer about the refresh event.
       
   259                     iNotifyInfo->iObserver->Refresh(
       
   260                         aType, iNotifyInfo->iObservedFile );
       
   261                     iRSatRefresh->RefreshEFRead( cspEfFound );
       
   262                     }
       
   263                 else // ESSSettingsAllowRefresh
       
   264                     {
       
   265                     // Inform the observer about the coming refresh event.
       
   266                     allow = iNotifyInfo->iObserver->AllowRefresh(
       
   267                         aType, iNotifyInfo->iObservedFile );
       
   268                     }
       
   269                 }
       
   270             
       
   271             // If there is no client listening changed files SSSettings has to
       
   272             // check if some CSP file is into the list and send right response
       
   273             // since itself reads CSP files.    
       
   274             if ( !fileFound )
       
   275             	{
       
   276                 iRSatRefresh->RefreshEFRead( !cspEfFound );
       
   277                 }
       
   278             }
       
   279         else
       
   280             {
       
   281             iRSatRefresh->RefreshEFRead( EFalse );
       
   282             }
       
   283         }
       
   284     else if ( aType == EFileChangeNotification 
       
   285         || aType == ESimInitFileChangeNotification 
       
   286         || aType == ESimInit )
       
   287         {
       
   288         iRSatRefresh->RefreshEFRead( !cspEfFound );
       
   289         }
       
   290     else 
       
   291         {
       
   292         // Do nothing
       
   293         }
       
   294     	    	
       
   295     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::DoHandleRefresh");
       
   296     return allow;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CSSSettingsRefreshHandler::HandlePubSubNotify
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CSSSettingsRefreshHandler::HandlePubSubNotify( const TUid aUid,
       
   304     const TUint32 aKeyId )
       
   305     {
       
   306     __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::HandlePubSubNotify");
       
   307     if ( aUid == KPSUidBluetoothSapConnectionState && 
       
   308          aKeyId == KBTSapConnectionState )
       
   309         {
       
   310         TInt btSapState(EBTSapNotConnected);
       
   311         //get the current SAP state
       
   312         RProperty::Get( aUid, aKeyId, btSapState );
       
   313         if ( btSapState == EBTSapNotConnected )
       
   314             {
       
   315             // Refresh handling needed only if the BT SAP 
       
   316             // state is not connected.
       
   317             iRCspCache.HandleRefresh();
       
   318             iRSSSettings.HandleRefresh();
       
   319             }
       
   320         __SSSLOGSTRING1("[SSS]    HandlePubSubNotify: btSapState: %d", btSapState);
       
   321         }
       
   322     __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::HandlePubSubNotify");
       
   323     }
       
   324 
       
   325 
       
   326 //  End of File