wlan_bearer/wlanpsmplugin/src/wlanpsmplugin.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:   ECOM plugin implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 7 %
       
    20 */
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32std.h>
       
    24 #include <ecom/implementationproxy.h>
       
    25 #include <commdb.h>
       
    26 #include <psmsettingsprovider.h>
       
    27 #include "wdbifwlandefs.h"
       
    28 #include <wlanmgmtclient.h>
       
    29 #include "wlanpsmplugin.h"
       
    30 #include "am_debug.h"
       
    31 
       
    32 // CONSTANT DEFINITIONS
       
    33 const TUint32 KWlanPsmConfigId = 0x200100C0;
       
    34 
       
    35 enum TPsmPluginFirstKeys
       
    36     {
       
    37     EWlanPsmKey1 = 1    
       
    38     };
       
    39 
       
    40 /**
       
    41 * Pairs ECom implementation UIDs with a pointer to the instantiation 
       
    42 * method for that implementation. Required for all ECom implementation
       
    43 * collections.
       
    44 */
       
    45 const TImplementationProxy ImplementationTable[] =
       
    46     {
       
    47         {{0x200100C2}, reinterpret_cast<TProxyNewLPtr>(CWlanPsmPlugin::NewL)}
       
    48     };
       
    49 
       
    50 // ========================== EXPORTED FUNCTIONS =========================
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // Returns an instance of the proxy table.
       
    54 // Returns: KErrNone
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
    58     {
       
    59     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
    60     return ImplementationTable;
       
    61     }
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 //
       
    66 // ----------------------------------------------------------------------------------
       
    67 // CWlanPsmPlugin::CWlanPsmPlugin()
       
    68 // ----------------------------------------------------------------------------------
       
    69 //  
       
    70 CWlanPsmPlugin::CWlanPsmPlugin( TPsmPluginCTorParams& aInitParams ) :
       
    71     CPsmPluginBase( aInitParams )
       
    72 	{	
       
    73 	DEBUG ( "CWlanPsmPlugin::CWlanPsmPlugin()" );
       
    74 	}
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CWlanPsmPlugin::ConstructL(
       
    78 // Symbian 2nd phase constructor can leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CWlanPsmPlugin::ConstructL()
       
    82     {
       
    83     DEBUG ( "CWlanPsmPlugin::ConstructL()" );
       
    84     User::LeaveIfError( iWlmServer.Connect() );
       
    85     }
       
    86     
       
    87 //
       
    88 // ----------------------------------------------------------------------------------
       
    89 // CWlanPsmPlugin::NewL() 
       
    90 // ----------------------------------------------------------------------------------
       
    91 //  
       
    92 // Two-phased constructor.
       
    93 CWlanPsmPlugin* CWlanPsmPlugin::NewL( TPsmPluginCTorParams& aInitParams )
       
    94 	{
       
    95 	DEBUG ( "CWlanPsmPlugin::NewL()" );
       
    96 	
       
    97 	CWlanPsmPlugin* self = new ( ELeave ) CWlanPsmPlugin( aInitParams );
       
    98 
       
    99 	CleanupStack::PushL( self );
       
   100     self->ConstructL();
       
   101     CleanupStack::Pop( self );
       
   102 
       
   103     return self;
       
   104 	}
       
   105 	
       
   106 //
       
   107 // ----------------------------------------------------------------------------------
       
   108 // CWlanPsmPlugin::~CWlanPsmPlugin()
       
   109 // ----------------------------------------------------------------------------------
       
   110 //  
       
   111 // Destructor.
       
   112 CWlanPsmPlugin::~CWlanPsmPlugin()
       
   113 	{
       
   114     DEBUG ( "CWlanPsmPlugin::~CWlanPsmPlugin()" );
       
   115     iWlmServer.Close();
       
   116 	}
       
   117 
       
   118 //
       
   119 // ----------------------------------------------------------------------------------
       
   120 // CWlanPsmPlugin::NotifyModeChange()
       
   121 // ----------------------------------------------------------------------------------
       
   122 //  
       
   123 void CWlanPsmPlugin::NotifyModeChange( const TInt aMode )
       
   124     {
       
   125     DEBUG1( "CWlanPsmPlugin::NotifyModeChange(), Mode:%d", aMode );
       
   126 
       
   127     //call the function that can Leave
       
   128     TRAPD( err, NotifyModeChangeL(aMode) );
       
   129     if (err)
       
   130     	{
       
   131     	DEBUG("CWlanPsmPlugin::NotifyModeChange(), NotifyModeChangeL Leave'd");
       
   132     	}
       
   133     }
       
   134 
       
   135 
       
   136 //
       
   137 // ----------------------------------------------------------------------------------
       
   138 // CWlanPsmPlugin::NotifyModeChangeL()
       
   139 // ----------------------------------------------------------------------------------
       
   140 //  
       
   141 void CWlanPsmPlugin::NotifyModeChangeL( const TInt aMode )
       
   142     {
       
   143     
       
   144 #ifdef _DEBUG
       
   145     if( aMode == EPsmsrvModePowerSave )
       
   146         {
       
   147         DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - aMode: EPsmsrvModePowerSave (%d)", aMode );
       
   148         }
       
   149     else if ( aMode == EPsmsrvPartialMode )
       
   150         {
       
   151         DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - aMode: EPsmsrvPartialMode (%d)", aMode );
       
   152         }
       
   153     else if ( aMode == EPsmsrvModeNormal )
       
   154         {
       
   155         DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - aMode: EPsmsrvModeNormal (%d)", aMode );
       
   156         }
       
   157     else
       
   158         {
       
   159         DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - unrecognised aMode: %d", aMode );
       
   160         }
       
   161 #endif
       
   162     
       
   163     //NOTE: The plugin changes only the current BG scan interval in CommsDat.
       
   164     //Updating of Default BG scan interval in CenRep is taken care by PSM Engine
       
   165     //using Passive configuration file.
       
   166     
       
   167     RConfigInfoArray infoArray;
       
   168     TPsmsrvConfigInfo info1;
       
   169     TUint32 bgScanIntervalCurrentlyInCommsDat, bgScanIntervalFromPsmFramework;
       
   170     TBool updateBgScanIntervalToCommsDat = EFalse;       
       
   171     CCommsDatabase*    commDB = NULL;
       
   172     CCommsDbTableView* table  = NULL;
       
   173 
       
   174     //Read current BG interval from CommsDat
       
   175     commDB = CCommsDatabase::NewL();
       
   176     CleanupStack::PushL( commDB );
       
   177 
       
   178     table = commDB->OpenViewMatchingUintLC( TPtrC(WLAN_DEVICE_SETTINGS),
       
   179     										TPtrC(WLAN_DEVICE_SETTINGS_TYPE),
       
   180     										KWlanUserSettings );
       
   181 
       
   182     User::LeaveIfError( table->GotoFirstRecord() );
       
   183 	
       
   184 	table->ReadUintL( TPtrC( WLAN_BG_SCAN_INTERVAL ), bgScanIntervalCurrentlyInCommsDat ); 
       
   185 
       
   186     // Backup and Get settings...
       
   187     info1.iConfigId = EWlanPsmKey1;
       
   188     info1.iConfigType = EConfigTypeInt;
       
   189     info1.iIntValue = bgScanIntervalCurrentlyInCommsDat;
       
   190     infoArray.Append( info1 );
       
   191 
       
   192     iSettingsProvider.BackupAndGetSettingsL( infoArray, KWlanPsmConfigId );
       
   193     
       
   194     bgScanIntervalFromPsmFramework = infoArray[0].iIntValue;
       
   195     
       
   196     DEBUG2( "CWlanPsmPlugin::NotifyModeChangeL() - current value in CommsDat: %u, PSM Framework provided value: %u",
       
   197     					bgScanIntervalCurrentlyInCommsDat, bgScanIntervalFromPsmFramework);
       
   198     
       
   199     if ( EPsmsrvModePowerSave == aMode || EPsmsrvPartialMode == aMode )
       
   200     	{
       
   201         DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - PSM server mode is changing to EPsmsrvModePowerSave/EPsmsrvPartialMode" );
       
   202         
       
   203         // if bg scan interval is neither non-zero nor automatic...
       
   204         if ( bgScanIntervalCurrentlyInCommsDat != 0 && bgScanIntervalCurrentlyInCommsDat != 0xFFFFFFFF )
       
   205             {
       
   206             DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - storing Automatic value to CommsDat as current CommsDat value (%u) is non-zero and non-Automatic",
       
   207                     bgScanIntervalCurrentlyInCommsDat );
       
   208             // set bg scan interval to automatic
       
   209             updateBgScanIntervalToCommsDat = ETrue;
       
   210             }
       
   211 #ifdef _DEBUG
       
   212         else
       
   213             {
       
   214             DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - CommsDat update not needed as current value (%u) is zero or Automatic", bgScanIntervalCurrentlyInCommsDat );
       
   215             }
       
   216 #endif        
       
   217     	}
       
   218     else 
       
   219     	{
       
   220         DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - PSM server mode is changing to EPsmsrvModeNormal" );
       
   221         // If backed up value is...
       
   222         // * zero -> if current value in commsdat is automatic, user has set bg scan to automatic during power save, no need to change commsdat.
       
   223         //        -> if current value in commsdat is zero -> commsdat had setting zero before entering power save -> no need to change commsdat.
       
   224         //        -> UI shall prevent setting other values in commsdat during power save.
       
   225         // * automatic -> if current value in commsdat is automatic, no need to change commsdat.
       
   226         //             -> if current value in commsdat is zero, no need to change commsdat.
       
   227         //             -> UI shall prevent setting other values in commsdat during power save.
       
   228         // * non-zero -> if current value in commsdat is automatic, plugin set value to automatic during entering power save mode -> restore backed up setting to commsdat.
       
   229         //            -> if current value in commsdat is zero, user has disabled background scan -> no need to change commsdat.
       
   230         //            -> UI shall prevent setting other values in commsdat during power save.
       
   231         if( bgScanIntervalFromPsmFramework != 0 && bgScanIntervalFromPsmFramework != 0xFFFFFFFF )
       
   232             {
       
   233             DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - backed up value (%u) is non-zero or non-Automatic", bgScanIntervalFromPsmFramework );
       
   234             if( bgScanIntervalCurrentlyInCommsDat == 0xFFFFFFFF )
       
   235                 {
       
   236                 DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - current value in CommsDat is Automatic -> restoring backed up value to CommsDat" );
       
   237                 // restore background scan interval from backup
       
   238                 updateBgScanIntervalToCommsDat = ETrue;
       
   239                 }
       
   240 #ifdef _DEBUG
       
   241             else
       
   242                 {
       
   243                 DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - no CommsDat update needed as current value in commsdat is zero" );
       
   244                 if( bgScanIntervalCurrentlyInCommsDat != 0 )
       
   245                     {
       
   246                     DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - value in CommsDat is non-zero (%u) -> do assert, UI shouldn't allow setting other than 0 or Automatic",
       
   247                             bgScanIntervalCurrentlyInCommsDat );
       
   248                     ASSERT( 0 );
       
   249                     }
       
   250                 }
       
   251 #endif        
       
   252             }
       
   253 #ifdef _DEBUG
       
   254         else
       
   255             {
       
   256             DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - no CommsDat update needed as backed up value (%u) is zero or Automatic", bgScanIntervalFromPsmFramework );
       
   257             }
       
   258 #endif      
       
   259         }
       
   260            
       
   261     if ( updateBgScanIntervalToCommsDat )
       
   262     	{
       
   263         DEBUG1( "CWlanPsmPlugin::NotifyModeChangeL() - updating CommsDat with value: %d",
       
   264 							bgScanIntervalFromPsmFramework);
       
   265 
       
   266 		//update CommsDb to reflect the changed value
       
   267         User::LeaveIfError( table->UpdateRecord() );
       
   268 		table->WriteUintL( TPtrC(WLAN_BG_SCAN_INTERVAL), bgScanIntervalFromPsmFramework );
       
   269 		User::LeaveIfError( table->PutRecordChanges() );
       
   270 		
       
   271 		DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - informing WLAN Engine about changed value" );
       
   272 		iWlmServer.NotifyChangedSettings();
       
   273     	}
       
   274     
       
   275     DEBUG( "CWlanPsmPlugin::NotifyModeChangeL() - notifying WLAN Engine about new power save mode" );
       
   276     iWlmServer.NotifyChangedPsmSrvMode( aMode );
       
   277 
       
   278     // cleanup
       
   279     CleanupStack::PopAndDestroy( table );
       
   280     CleanupStack::PopAndDestroy( commDB );
       
   281     
       
   282     infoArray.Reset();
       
   283     }
       
   284