wlanutilities/cpwlansettingsplugin/src/wlansettings_s60.cpp
changeset 19 10810c91db26
child 53 bdc64aa9b954
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
       
     1 /*
       
     2 * Copyright (c) 2010 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 
       
    20 #include <internetconnectivitycrkeys.h>
       
    21 #include <psmtypes.h>
       
    22 #include <cmmanager.h>
       
    23 
       
    24 // User includes
       
    25 
       
    26 #include "wlansettings_s60_p.h"
       
    27 
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "wlansettings_s60Traces.h"
       
    31 #endif
       
    32 
       
    33 /*!
       
    34     \class CWlanSettingsPrivate
       
    35     \brief CWlanSettingsPrivate is the actual implementation for 
       
    36     reading/writing WLAN Settings from/to database.
       
    37 */
       
    38 
       
    39 // External function prototypes
       
    40 
       
    41 // Local constants
       
    42 /**  Seconds per minute. */
       
    43 const TInt KWlanSettingsSecondsInMinute = 60;
       
    44 /**  Maximum value for scan interval in minutes. */
       
    45 const TInt KWlanSettingsScanNetworkMax = 30;
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 /*!
       
    50     Static NewL function for creating CWlanSettingsPrivate object.
       
    51     \return Pointer to CWlanSettingsPrivate object.
       
    52 */
       
    53 
       
    54 CWlanSettingsPrivate* CWlanSettingsPrivate::NewL(int psmKeyValue)
       
    55 {
       
    56     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_NEWL_ENTRY, this);
       
    57     
       
    58     CWlanSettingsPrivate* impl = new ( ELeave ) CWlanSettingsPrivate(psmKeyValue);
       
    59     CleanupStack::PushL( impl );
       
    60     impl->ConstructL();
       
    61     CleanupStack::Pop( impl ); 
       
    62     
       
    63     OstTraceFunctionExit1(CWLANSETINGPRIVATE_NEWL_EXIT, this);
       
    64     return impl;    
       
    65 }
       
    66 
       
    67 /*!
       
    68     Second phase Constructor.
       
    69 */
       
    70 
       
    71 void CWlanSettingsPrivate::ConstructL()
       
    72 {
       
    73     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_CONSTRUCTL_ENTRY, this);
       
    74     
       
    75     mSession = CMDBSession::NewL( KCDLatestVersion );
       
    76     
       
    77 #ifndef __WINS__
       
    78     mWlanMgmtClient = CWlanMgmtClient::NewL();
       
    79 #endif
       
    80     
       
    81     CheckPsmModeL();
       
    82     
       
    83     OstTraceFunctionExit1(CWLANSETINGPRIVATE_CONSTRUCTL_EXIT, this);
       
    84 }
       
    85 
       
    86 /*!
       
    87     Constructor.
       
    88 */
       
    89 
       
    90 CWlanSettingsPrivate::CWlanSettingsPrivate(int psmKeyValue) :
       
    91     mPsmMode( EFalse ),
       
    92     mPowerSaving(KWlanSettingsDefaultPowerSaving),
       
    93     mScanInterval(KWlanSettingsDefaultScanNetwork),
       
    94     mPsmKeyMode(psmKeyValue)
       
    95 {
       
    96     
       
    97     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_CWLANSETINGPRIVATE_ENTRY, this);
       
    98     OstTraceFunctionExit1(CWLANSETINGPRIVATE_CWLANSETINGPRIVATE_EXIT, this);
       
    99     
       
   100 }
       
   101 
       
   102 /*!
       
   103     Destructor.
       
   104 */
       
   105 
       
   106 CWlanSettingsPrivate::~CWlanSettingsPrivate()
       
   107 {
       
   108     OstTraceFunctionEntry1(DUP1_CWLANSETINGPRIVATE_CWLANSETINGPRIVATE_ENTRY, this);
       
   109     
       
   110     delete mSession;
       
   111 #ifndef __WINS__
       
   112     delete mWlanMgmtClient;
       
   113 #endif
       
   114     
       
   115     OstTraceFunctionExit1(DUP1_CWLANSETINGPRIVATE_CWLANSETINGPRIVATE_EXIT, this);
       
   116 }
       
   117 
       
   118 /*!
       
   119     Function to get the Power Saving mode of the device.
       
   120 */
       
   121 
       
   122 void CWlanSettingsPrivate::CheckPsmModeL()
       
   123 {
       
   124     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_CHECKPSMMODEL_ENTRY, this);
       
   125     
       
   126     TPsmsrvMode mode( EPsmsrvModeNormal );
       
   127     
       
   128     mode = static_cast<TPsmsrvMode>( mPsmKeyMode );
       
   129     if ( mode == EPsmsrvModePowerSave || mode == EPsmsrvPartialMode ) {
       
   130         mPsmMode = ETrue;
       
   131     }
       
   132     else {
       
   133         mPsmMode = EFalse;
       
   134     }
       
   135     
       
   136     OstTraceFunctionExit1(CWLANSETINGPRIVATE_CHECKPSMMODEL_EXIT, this);
       
   137 }
       
   138 
       
   139 /*!
       
   140     Function to load the WLAN Settings from CommsDB.
       
   141 */
       
   142 
       
   143 void CWlanSettingsPrivate::LoadDBSettingsL()
       
   144 {
       
   145     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_LOADDBSETTINGSL_ENTRY, this);
       
   146     
       
   147     TBool ownTransaction( EFalse );
       
   148     if ( !mSession->IsInTransaction() ) {
       
   149         ownTransaction = ETrue;
       
   150         mSession->OpenTransactionL();
       
   151     }
       
   152     TMDBElementId tableId = 0;
       
   153     
       
   154     tableId = CCDWlanDeviceSettingsRecord::TableIdL( *mSession );
       
   155         
       
   156     CCDWlanDeviceSettingsRecord* record = new( ELeave )
       
   157             CCDWlanDeviceSettingsRecord( tableId );         
       
   158     CleanupStack::PushL( record );
       
   159     
       
   160     record->iWlanDeviceSettingsType = KWlanUserSettings; 
       
   161     
       
   162     if ( record->FindL( *mSession ) ) {
       
   163         record->LoadL( *mSession );
       
   164     }
       
   165 
       
   166     // Read scan interval
       
   167 
       
   168     mScanInterval = record->iBgScanInterval;
       
   169     //In Case of PSM mode Scan Interval should be set to Auto
       
   170     if (mPsmMode) {
       
   171         mScanInterval = KWlanSettingsScanNetworkAuto;
       
   172     }
       
   173     else {
       
   174         mScanInterval = record->iSavedBgScanInterval;
       
   175         //Safe check for scan interval, control should not come here.
       
   176         if (mScanInterval > (KWlanSettingsScanNetworkMax
       
   177                 * KWlanSettingsSecondsInMinute)) {
       
   178             mScanInterval = KWlanSettingsScanNetworkAuto;
       
   179         }
       
   180     }
       
   181     
       
   182     mPowerSaving = record->iWlanPowerMode;
       
   183     CleanupStack::PopAndDestroy( record ); 
       
   184     
       
   185     if ( ownTransaction ) {
       
   186         mSession->CommitTransactionL();
       
   187           // Rollback operation.
       
   188     }
       
   189     
       
   190     //To Load CM Settings.
       
   191     LoadJoinWlanSettingL();
       
   192     
       
   193     OstTraceFunctionExit1(CWLANSETINGPRIVATE_LOADDBSETTINGSL_EXIT, this);
       
   194 }
       
   195 
       
   196 /*!
       
   197     Function to load the Join WLAN networks Setting from CMManager.
       
   198 */
       
   199 
       
   200 void CWlanSettingsPrivate::LoadJoinWlanSettingL()
       
   201 {
       
   202     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_LOADJOINWLANSETTINGL_ENTRY, this);
       
   203     
       
   204     RCmManager CmManager;
       
   205     CmManager.CreateTablesAndOpenL();
       
   206     CleanupClosePushL(CmManager); 
       
   207     CmManager.ReadGenConnSettingsL( mCmSettings );
       
   208     CleanupStack::PopAndDestroy( 1 );     //CmManager
       
   209     
       
   210     OstTraceFunctionExit1(CWLANSETINGPRIVATE_LOADJOINWLANSETTINGL_EXIT, this);
       
   211 }
       
   212 
       
   213 /*!
       
   214     Function to write the Join WLAN networks Setting using CMManager.
       
   215 */
       
   216 
       
   217 void CWlanSettingsPrivate::SaveJoinWlanSettingL(TInt mode)
       
   218 {
       
   219     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_SAVEJOINWLANSETTINGL_ENTRY, this);
       
   220     
       
   221     switch ( mode ) {        
       
   222         case EJoinWlanKnown:
       
   223             mCmSettings.iUsageOfWlan = ECmUsageOfWlanKnown;
       
   224             break;
       
   225             
       
   226         case EJoinWlanManual:
       
   227             mCmSettings.iUsageOfWlan = ECmUsageOfWlanManual;
       
   228             break;
       
   229                         
       
   230         default:
       
   231             break;
       
   232     }
       
   233     
       
   234     RCmManager CmManager;
       
   235     CmManager.CreateTablesAndOpenL();
       
   236     CleanupClosePushL(CmManager); 
       
   237     CmManager.WriteGenConnSettingsL( mCmSettings );
       
   238     CleanupStack::PopAndDestroy( 1 );
       
   239     
       
   240     OstTraceFunctionExit1(CWLANSETINGPRIVATE_SAVEJOINWLANSETTINGL_EXIT, this);
       
   241 }
       
   242 
       
   243 /*!
       
   244     Function to get the Join WLAN network setting.
       
   245     \return 0 for Known, 1 for Manual.
       
   246 */
       
   247 
       
   248 TInt CWlanSettingsPrivate::JoinWlanMode()
       
   249 {
       
   250     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_JOINWLANMODE_ENTRY, this);
       
   251     
       
   252     TInt mode = 0;
       
   253     
       
   254     switch ( mCmSettings.iUsageOfWlan ) {
       
   255         case ECmUsageOfWlanKnown: 
       
   256             mode = EJoinWlanKnown;
       
   257             break;
       
   258             
       
   259         case ECmUsageOfWlanManual:
       
   260             mode = EJoinWlanManual;
       
   261             break;
       
   262                         
       
   263         default:
       
   264             break;
       
   265     }
       
   266     
       
   267     OstTraceFunctionExit1(CWLANSETINGPRIVATE_JOINWLANMODE_EXIT, this);
       
   268     return mode;
       
   269 }
       
   270 
       
   271 /*!
       
   272     Function to write the WLAN Settings to CommsDb.
       
   273 */
       
   274 
       
   275 void CWlanSettingsPrivate::SaveDBSettingsL(TInt option)
       
   276 {
       
   277     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_SAVEDBSETTINGSL_ENTRY, this);
       
   278     
       
   279     TBool ownTransaction( EFalse );
       
   280     if ( !mSession->IsInTransaction() ) {
       
   281         ownTransaction = ETrue;
       
   282         mSession->OpenTransactionL();
       
   283     }
       
   284     TMDBElementId tableId = 0;
       
   285     tableId = CCDWlanDeviceSettingsRecord::TableIdL( *mSession );
       
   286         
       
   287     CCDWlanDeviceSettingsRecord* record = new( ELeave )
       
   288             CCDWlanDeviceSettingsRecord( tableId );         
       
   289     
       
   290     CleanupStack::PushL( record );
       
   291     
       
   292     record->iWlanDeviceSettingsType = KWlanUserSettings; 
       
   293     
       
   294     if ( record->FindL( *mSession ) ) {
       
   295         record->LoadL( *mSession );
       
   296     }
       
   297     
       
   298     switch (option) {
       
   299         case EWlanScanInterval:
       
   300             record->iBgScanInterval = mScanInterval;
       
   301             if ( !mPsmMode ) {
       
   302                 record->iSavedBgScanInterval = mScanInterval;
       
   303             }
       
   304             break;
       
   305         case EWlanPowerSaving:
       
   306             record->iWlanPowerMode = mPowerSaving;
       
   307             break;
       
   308         default:
       
   309             break;
       
   310     }
       
   311     
       
   312     // Whenever settings are modified, iUseDefaultSettings must be set to false.
       
   313     record->iUseDefaultSettings = EFalse;
       
   314 
       
   315     record->ModifyL( *mSession );
       
   316         
       
   317     CleanupStack::PopAndDestroy( record );        
       
   318     if ( ownTransaction ) {
       
   319         mSession->CommitTransactionL();
       
   320     }
       
   321 
       
   322 #ifndef __WINS__
       
   323     // Notifying WLAN Engine about changes in settings
       
   324     mWlanMgmtClient->NotifyChangedSettings();
       
   325 #endif
       
   326     
       
   327     OstTraceFunctionExit1(CWLANSETINGPRIVATE_SAVEDBSETTINGSL_EXIT, this);
       
   328 }
       
   329 
       
   330 /*!
       
   331     Function to get the scan interval.
       
   332     \return Scan interval  in minutes.
       
   333 */
       
   334 
       
   335 TUint CWlanSettingsPrivate::ScanInterval()
       
   336 {
       
   337     if ( mScanInterval == KWlanSettingsScanNetworkAuto ) {
       
   338         return mScanInterval;   
       
   339     }
       
   340     else {
       
   341         // Return scan time in minutes
       
   342         return ( mScanInterval / KWlanSettingsSecondsInMinute );
       
   343     }
       
   344 }
       
   345 
       
   346 /*!
       
   347     Function to get Power Saving Option.
       
   348     \return True if Power Saving option is enabled, otherwise False.
       
   349 */
       
   350 
       
   351 TBool CWlanSettingsPrivate::PowerSaving()
       
   352 {
       
   353     return mPowerSaving;
       
   354 }
       
   355 
       
   356 /*!
       
   357     Function to set Scan interval.
       
   358     \param interval Scan interval in minutes. 
       
   359 */
       
   360 
       
   361 void CWlanSettingsPrivate::SetScanInterval(TUint interval)
       
   362 {
       
   363     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_SETSCANINTERVAL_ENTRY, this);
       
   364     
       
   365     if ( interval == KWlanSettingsScanNetworkAuto ) {
       
   366         mScanInterval = interval;
       
   367     }
       
   368     else {
       
   369         // Scan time stored in seconds
       
   370         mScanInterval = interval * KWlanSettingsSecondsInMinute;
       
   371     }
       
   372     
       
   373     OstTraceFunctionExit1(CWLANSETINGPRIVATE_SETSCANINTERVAL_EXIT, this);
       
   374 }
       
   375 
       
   376 /*!
       
   377     Function to set Power Saving Option.
       
   378     \param powerSavingOption True to enable or false to disable power saving option. 
       
   379 */
       
   380 
       
   381 void CWlanSettingsPrivate::SetPowerSaving(TBool powerSavingOption)
       
   382 {
       
   383     OstTraceFunctionEntry1(CWLANSETINGPRIVATE_SETPOWERSAVING_ENTRY, this);
       
   384     
       
   385     mPowerSaving = powerSavingOption;
       
   386     
       
   387     OstTraceFunctionExit1(CWLANSETINGPRIVATE_SETPOWERSAVING_EXIT, this);
       
   388 }
       
   389 
       
   390 /*!
       
   391     Function to get Power Saving status of the device.
       
   392     \return True if Power Saving is enabled.
       
   393 */
       
   394 
       
   395 TBool CWlanSettingsPrivate::IsPsmEnabled()
       
   396 {
       
   397     return mPsmMode;
       
   398 }