dbcreator/commsdatcreator/Src/cdcwlandevicesettings.cpp
changeset 0 5a93021fdf25
child 12 ea6e024ea6f9
child 18 fcbbe021d614
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Implementation of the class CWlanDeviceSettings
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cdcwlandevicesettings.h"
       
    22 #include "cdclogger.h"
       
    23 
       
    24 #include <cdbcols.h>
       
    25 #include <WlanCdbCols.h>
       
    26 
       
    27 #include <metadatabase.h>
       
    28 #include <commsdattypeinfov1_1.h>
       
    29 #include <commsdattypesv1_1.h>
       
    30 #include <wlancontainer.h>
       
    31 
       
    32 
       
    33 // CONSTANTS
       
    34 // WLAN Device Settings table - default settings
       
    35 const TUint32 KDefaultBGScanInterval    = 0;   // No background scan
       
    36 const TBool   KDefaultUseDefSettings    = ETrue;        
       
    37 const TUint32 KDefaultLongRetry         = 4;
       
    38 const TUint32 KDefaultShortRetry        = 7;
       
    39 const TUint32 KDefaultRTS               = 2347;
       
    40 const TUint32 KDefaultTxPowerLevel      = 100;  //mW
       
    41 const TBool   KDefaultRadioMeasurements = ETrue;  
       
    42 const TBool   KDefaultWlanPowerMode     = ETrue;        
       
    43 
       
    44 // Increase version every time the content of the table changes
       
    45 const TUint32 KWlanDeviceSettingsTableVersion = 9;
       
    46 
       
    47 
       
    48 // ================= MEMBER FUNCTIONS ======================
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // Constructor
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 CWlanDeviceSettings::CWlanDeviceSettings()
       
    55     {
       
    56     }
       
    57     
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // Symbian 2nd phase constructor can leave.
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CWlanDeviceSettings::ConstructL()
       
    64     {
       
    65     DEBUG( "CWlanDeviceSettings::ConstructL()" )
       
    66     
       
    67     iSession = CMDBSession::NewL( CMDBSession::LatestVersion() );
       
    68     
       
    69     // Open the WLAN device settings table.
       
    70     if( !iSession->IsInTransaction() )
       
    71         {
       
    72         iSession->OpenTransactionL();
       
    73         }
       
    74     OpenTableL();
       
    75     iSession->CommitTransactionL();
       
    76     DEBUG( "CWlanDeviceSettings::ConstructL() Tables opened ok." )
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // Static constructor.
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CWlanDeviceSettings* CWlanDeviceSettings::NewL()
       
    85     {
       
    86     DEBUG( "CWlanDeviceSettings::NewL()" )
       
    87 
       
    88     CWlanDeviceSettings* self = new (ELeave) CWlanDeviceSettings;
       
    89 
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop( self );
       
    93 
       
    94     return self;
       
    95     }
       
    96     
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // Destructor
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 CWlanDeviceSettings::~CWlanDeviceSettings()
       
   103     {
       
   104     DEBUG( "CWlanDeviceSettings::~CWlanDeviceSettings()" )
       
   105     
       
   106     if ( iSession )
       
   107         {
       
   108         iSession->Close();
       
   109         delete iSession; 
       
   110         }
       
   111     }
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CWlanDeviceSettings::GetDefaultSettings
       
   116 // ---------------------------------------------------------
       
   117 //
       
   118 void CWlanDeviceSettings::GetDefaultSettings( SWlanDeviceSettings& aSettings )
       
   119     {
       
   120     DEBUG( "CWlanDeviceSettings::GetDefaultSettings()" )
       
   121 
       
   122     aSettings.backgroundScanInterval = KDefaultBGScanInterval; 
       
   123     aSettings.savedBgScanInterval    = KDefaultBGScanInterval; 
       
   124     aSettings.useDefaultSettings     = KDefaultUseDefSettings;        
       
   125     aSettings.longRetry              = KDefaultLongRetry;
       
   126     aSettings.shortRetry             = KDefaultShortRetry;
       
   127     aSettings.rts                    = KDefaultRTS;
       
   128     aSettings.txPowerLevel           = KDefaultTxPowerLevel;
       
   129     aSettings.radioMeasurements      = KDefaultRadioMeasurements;
       
   130     aSettings.powerMode              = KDefaultWlanPowerMode;
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CWlanDeviceSettings::OpenTableL
       
   136 // ---------------------------------------------------------
       
   137 //
       
   138 void CWlanDeviceSettings::OpenTableL()
       
   139     {
       
   140     DEBUG( "CWlanDeviceSettings::OpenTableL()" )
       
   141     
       
   142     // See if there is a record whose device settings type is
       
   143     // 'WLAN default settings'
       
   144     CMDBGenericRecord* deviceSettingsTable = static_cast< CMDBGenericRecord* >
       
   145                         ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   146     CleanupStack::PushL( deviceSettingsTable );
       
   147     deviceSettingsTable->InitializeL( TPtrC( WLAN_DEVICE_SETTINGS ), NULL );
       
   148     deviceSettingsTable->LoadL( *iSession );
       
   149     
       
   150     CMDBElement* tableType = deviceSettingsTable->GetFieldByIdL
       
   151                                             ( KCDTIdWlanDeviceSettingsType );
       
   152     CMDBField< TUint32 >* tableTypeField =
       
   153                             static_cast< CMDBField< TUint32 >* >( tableType );
       
   154     tableTypeField->SetL( KWlanDefaultSettings );
       
   155     
       
   156     if( !deviceSettingsTable->FindL( *iSession ) )
       
   157         {
       
   158         // If not, store empty record
       
   159         deviceSettingsTable->SetRecordId( KCDNewRecordRequest );
       
   160         deviceSettingsTable->StoreL( *iSession );
       
   161         // And fill it with data
       
   162         FillRecordL( KWlanDefaultSettings, deviceSettingsTable );
       
   163         deviceSettingsTable->ModifyL( *iSession );
       
   164         }
       
   165     CleanupStack::PopAndDestroy( deviceSettingsTable );
       
   166     
       
   167     // See if there is a record whose device settings type is
       
   168     // 'WLAN user settings'
       
   169     deviceSettingsTable = static_cast< CMDBGenericRecord* >
       
   170                                 ( CCDRecordBase::RecordFactoryL( 0 ) );
       
   171     CleanupStack::PushL( deviceSettingsTable );
       
   172     deviceSettingsTable->InitializeL( TPtrC( WLAN_DEVICE_SETTINGS ), NULL );
       
   173     deviceSettingsTable->LoadL( *iSession );
       
   174     
       
   175     tableType = deviceSettingsTable->GetFieldByIdL( KCDTIdWlanDeviceSettingsType );
       
   176     tableTypeField = static_cast< CMDBField< TUint32 >* >( tableType );
       
   177     tableTypeField->SetL( KWlanUserSettings );
       
   178     
       
   179     if( !deviceSettingsTable->FindL( *iSession ) )
       
   180         {
       
   181         // If not, store empty record
       
   182         deviceSettingsTable->SetRecordId( KCDNewRecordRequest );
       
   183         deviceSettingsTable->StoreL( *iSession );
       
   184         // And fill it with data
       
   185         FillRecordL( KWlanUserSettings, deviceSettingsTable );
       
   186         deviceSettingsTable->ModifyL( *iSession );
       
   187         }
       
   188     CleanupStack::PopAndDestroy( deviceSettingsTable );
       
   189     }
       
   190 
       
   191 
       
   192 // ---------------------------------------------------------
       
   193 // CWlanDeviceSettings::FillRecordL
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 
       
   197 void CWlanDeviceSettings::FillRecordL( TUint32 aTableType, 
       
   198                                       CMDBGenericRecord* aRecord )
       
   199     {
       
   200     DEBUG1( "CWlanDeviceSettings::NewRecordL() Type=%d", aTableType )
       
   201     
       
   202     SWlanDeviceSettings settings;
       
   203     GetDefaultSettings( settings );
       
   204     
       
   205     // Device Settings Type
       
   206     CMDBElement* tableType = aRecord->GetFieldByIdL
       
   207                                             ( KCDTIdWlanDeviceSettingsType );
       
   208     CMDBField< TUint32 >* tableTypeField =
       
   209                             static_cast< CMDBField< TUint32 >* >( tableType );
       
   210     tableTypeField->SetL( aTableType );
       
   211     
       
   212     // Table Version
       
   213     CMDBElement* tableVersion = aRecord->GetFieldByIdL
       
   214                                                     ( KCDTIdTableVersion );
       
   215     CMDBField< TUint32 >* tableVersionField =
       
   216                         static_cast< CMDBField< TUint32 >* >( tableVersion );
       
   217     
       
   218     tableVersionField->SetL( KWlanDeviceSettingsTableVersion );
       
   219 
       
   220     // BG Scan Interval
       
   221     CMDBElement* bgScanInterval = aRecord->GetFieldByIdL
       
   222                                                     ( KCDTIdBgScanInterval );
       
   223     CMDBField< TUint32 >* bgScanIntervalField =
       
   224                         static_cast< CMDBField< TUint32 >* >( bgScanInterval );
       
   225     bgScanIntervalField->SetL( settings.backgroundScanInterval );
       
   226     
       
   227     // Saved BG Scan Interval
       
   228     CMDBElement* savedBgScanInterval = aRecord->GetFieldByIdL
       
   229                                                     ( KCDTIdSavedBgScanInterval );
       
   230     CMDBField< TUint32 >* savedBgScanIntervalField =
       
   231                         static_cast< CMDBField< TUint32 >* >( savedBgScanInterval );
       
   232     savedBgScanIntervalField->SetL( settings.savedBgScanInterval );
       
   233     
       
   234     // Use Default Settings
       
   235     CMDBElement* useDefaultSettings = aRecord->GetFieldByIdL
       
   236                                                 ( KCDTIdUseDefaultSettings );
       
   237     CMDBField< TBool >* useDefaultSettingsField =
       
   238                     static_cast< CMDBField< TBool >* >( useDefaultSettings );
       
   239     useDefaultSettingsField->SetL( settings.useDefaultSettings );
       
   240     
       
   241     // Long Retry
       
   242     CMDBElement* longRetry = aRecord->GetFieldByIdL( KCDTIdWlanLongRetry );
       
   243     CMDBField< TUint32 >* longRetryField =
       
   244                         static_cast< CMDBField< TUint32 >* >( longRetry );
       
   245     longRetryField->SetL( settings.longRetry );
       
   246     
       
   247     // Short Retry
       
   248     CMDBElement* shortRetry = aRecord->GetFieldByIdL( KCDTIdWlanShortRetry );
       
   249     CMDBField< TUint32 >* shortRetryField =
       
   250                         static_cast< CMDBField< TUint32 >* >( shortRetry );
       
   251     shortRetryField->SetL( settings.shortRetry );
       
   252     
       
   253     // RTS Threshold
       
   254     CMDBElement* rts = aRecord->GetFieldByIdL( KCDTIdWlanRTSThreshold );
       
   255     CMDBField< TUint32 >* rtsField =
       
   256                         static_cast< CMDBField< TUint32 >* >( rts );
       
   257     rtsField->SetL( settings.rts );
       
   258     
       
   259     // TX Power Level
       
   260     CMDBElement* txPowerLevel = aRecord->GetFieldByIdL( KCDTIdTxPowerLevel );
       
   261     CMDBField< TUint32 >* txPowerLevelField =
       
   262                         static_cast< CMDBField< TUint32 >* >( txPowerLevel );
       
   263     txPowerLevelField->SetL( settings.txPowerLevel );
       
   264     
       
   265     // Radio Measurements
       
   266     CMDBElement* radioMeasurements = aRecord->GetFieldByIdL
       
   267                                             ( KCDTIdAllowRadioMeasurements );
       
   268     CMDBField< TBool >* radioMeasurementsField =
       
   269                     static_cast< CMDBField< TBool >* >( radioMeasurements );
       
   270     radioMeasurementsField->SetL( settings.radioMeasurements );
       
   271     
       
   272     // Power Mode
       
   273     CMDBElement* powerMode = aRecord->GetFieldByIdL( KCDTIdWlanPowerMode );
       
   274     CMDBField< TBool >* powerModeField =
       
   275                     static_cast< CMDBField< TBool >* >( powerMode );
       
   276     powerModeField->SetL( settings.powerMode );
       
   277     }
       
   278 
       
   279 //  End of File