wlanutilities/wlansniffer/aiplugin/src/wsfdbobserver.cpp
branchRCL_3
changeset 24 63be7eb3fc78
parent 23 b852595f5cbe
child 25 f28ada11abbf
equal deleted inserted replaced
23:b852595f5cbe 24:63be7eb3fc78
     1 /*
       
     2 * Copyright (c) 2007-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: 
       
    15 *      Implementation of utilities functions.   
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 //User includes
       
    23 #include "wsfdbobserver.h"
       
    24 #include "wsfaicontroller.h"
       
    25 #include "wsflogger.h"
       
    26 
       
    27 #include <featmgr.h>
       
    28 
       
    29 #include <wlandevicesettingsinternalcrkeys.h> 
       
    30 #include <centralrepository.h>
       
    31 
       
    32 
       
    33 const TInt KWlanSettingsUiDefaultScanNetwork = 300;
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CWsfDbObserver::CWsfDbObserver
       
    38 // ---------------------------------------------------------
       
    39 CWsfDbObserver::CWsfDbObserver(  ) 
       
    40 : CActive( EPriorityNormal ),
       
    41 iOuterScanState( EFalse )
       
    42     {
       
    43     }
       
    44     
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CWsfDbObserver::NewL
       
    48 // ---------------------------------------------------------    
       
    49 CWsfDbObserver* CWsfDbObserver::NewL(  )
       
    50     {
       
    51     CWsfDbObserver* self = new ( ELeave ) CWsfDbObserver( );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop();
       
    55     return self;
       
    56     }
       
    57 
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CWsfDbObserver::ConstructL
       
    61 // ---------------------------------------------------------   
       
    62 void CWsfDbObserver::ConstructL()
       
    63     {
       
    64 #ifndef __WINS__ // client is not available on wins
       
    65     iWlanMgmtClient = CWlanMgmtClient::NewL();
       
    66 #endif
       
    67     
       
    68     FeatureManager::InitializeLibL(); 
       
    69          
       
    70     CActiveScheduler::Add( this );
       
    71     }
       
    72 
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CWsfDbObserver::~CWsfDbObserver
       
    76 // ---------------------------------------------------------       
       
    77 CWsfDbObserver::~CWsfDbObserver()
       
    78     {
       
    79     Cancel();
       
    80     
       
    81     delete iRecord;
       
    82             
       
    83     delete iSession;
       
    84             
       
    85     delete iWlanMgmtClient;
       
    86     
       
    87     FeatureManager::UnInitializeLib();  
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CWsfDbObserver::RunL
       
    93 // ---------------------------------------------------------       
       
    94 void CWsfDbObserver::RunL()
       
    95     {
       
    96     LOG_ENTERFN( "CWsfDbObserver::RunL" );        
       
    97     iRecord->LoadL( *iSession );
       
    98     
       
    99     //if scanning state changed start or stop the server
       
   100     TInt i = iRecord->iBgScanInterval;
       
   101     TInt j = iRecord->iSavedBgScanInterval;
       
   102     LOG_WRITEF( "CWsfDbObserver::RunL -- Bg:%d bg2:%d O:%d", i, j, 
       
   103                                                               iOuterScanState );
       
   104     if ( iRecord->iBgScanInterval == 0 && iOuterScanState )
       
   105         {
       
   106         LOG_WRITE( "CWsfDbObserver::RunL -- Scan disabled" );
       
   107         iController->DisableScanL();
       
   108         iOuterScanState = EFalse;
       
   109         }
       
   110     else if(iRecord->iBgScanInterval != 0 && !iOuterScanState )
       
   111         {
       
   112         LOG_WRITE( "CWsfDbObserver::RunL -- Scan enabled" );
       
   113         iController->EnableScanL();
       
   114         iOuterScanState = ETrue;
       
   115         }
       
   116     
       
   117     SetActive();
       
   118     
       
   119     iRecord->RequestNotification(*iSession,iStatus);
       
   120     }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // CWsfDbObserver::DoCancel
       
   125 // ---------------------------------------------------------       
       
   126 void CWsfDbObserver::DoCancel()
       
   127     {
       
   128     iRecord->CancelNotification( *iSession, iStatus );       
       
   129     }
       
   130 
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // CWsfDbObserver::ActivateIt
       
   134 // ---------------------------------------------------------       
       
   135 void CWsfDbObserver::ActivateItL()
       
   136     {
       
   137     LOG_ENTERFN( "CWsfDbObserver::ActivateItL" );
       
   138     
       
   139     iSession = CMDBSession::NewL( KCDLatestVersion );
       
   140 
       
   141     TMDBElementId tableId = 0;
       
   142 
       
   143     tableId = CCDWlanDeviceSettingsRecord::TableIdL( *iSession );
       
   144 
       
   145     iRecord = new (ELeave) CCDWlanDeviceSettingsRecord( tableId );
       
   146 
       
   147     iRecord->iWlanDeviceSettingsType = KWlanUserSettings;
       
   148     
       
   149     
       
   150     if(iRecord->FindL( *iSession ))
       
   151         {
       
   152         iRecord->LoadL( *iSession );
       
   153         }          
       
   154        
       
   155     if ( iRecord->iBgScanInterval != 0 )
       
   156         {
       
   157         iController->EnableScanL();
       
   158         iOuterScanState = ETrue;
       
   159         }
       
   160     SetActive();
       
   161     
       
   162     iRecord->RequestNotification(*iSession,iStatus);
       
   163     
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CWsfDbObserver::SetController
       
   169 // ---------------------------------------------------------  
       
   170 void CWsfDbObserver::SetController( TWsfAiController* aController )
       
   171 	{
       
   172 	iController = aController;
       
   173 	}
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CWsfDbObserver::EnableScanL
       
   178 // ---------------------------------------------------------  
       
   179 void CWsfDbObserver::EnableScanL()
       
   180     {
       
   181     LOG_ENTERFN( "CWsfDbObserver::EnableScanL" );
       
   182     if ( !iOuterScanState )
       
   183         {
       
   184         iRecord->RefreshL( *iSession );
       
   185         if ( iRecord->iBgScanInterval == 0 ) // not scanning
       
   186             {
       
   187             TInt j;
       
   188             j = iRecord->iSavedBgScanInterval;
       
   189             if ( j == 0 )
       
   190                 {
       
   191                 j = DefaultScanIntervalL();
       
   192                 }
       
   193             iRecord->iBgScanInterval = j;
       
   194             iRecord->ModifyL( *iSession );
       
   195             iOuterScanState = ETrue;
       
   196             }
       
   197 #ifndef __WINS__
       
   198         // Notifying WLAN Engine about changes in settings
       
   199         iWlanMgmtClient->NotifyChangedSettings();
       
   200 #endif
       
   201         }
       
   202     }
       
   203        
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CWsfDbObserver::DisableScanL
       
   207 // ---------------------------------------------------------     
       
   208 void CWsfDbObserver::DisableScanL()
       
   209     {
       
   210     LOG_ENTERFN( "CWsfDbObserver::DisableScanL" );
       
   211     if ( iOuterScanState )
       
   212         {
       
   213         iRecord->RefreshL(*iSession);
       
   214         if ( iRecord->iBgScanInterval != 0 ) // scanning
       
   215             {
       
   216             TInt i;
       
   217             i = iRecord->iBgScanInterval;
       
   218             iRecord->iBgScanInterval = 0;
       
   219             iRecord->iSavedBgScanInterval = i;
       
   220             iRecord->ModifyL( *iSession );
       
   221             iOuterScanState = EFalse;
       
   222             }
       
   223 #ifndef __WINS__
       
   224         // Notifying WLAN Engine about changes in settings
       
   225         iWlanMgmtClient->NotifyChangedSettings();
       
   226 #endif
       
   227         }
       
   228     }
       
   229 
       
   230 
       
   231 // ---------------------------------------------------------
       
   232 // CWsfDbObserver::DefaultScanInterval
       
   233 // ---------------------------------------------------------     
       
   234 TInt CWsfDbObserver::DefaultScanIntervalL()
       
   235     {
       
   236     LOG_ENTERFN( "CWsfDbObserver::DefaultScanIntervalL" );
       
   237     TBool iPsmSupported = FeatureManager::FeatureSupported(
       
   238                                                         KFeatureIdPowerSave );
       
   239     if ( iPsmSupported )
       
   240         {
       
   241         // Read the default value from CenRep (different in PSM mode)
       
   242         TInt defaultScanInterval( KWlanSettingsUiDefaultScanNetwork );
       
   243 
       
   244         CRepository* repository = CRepository::NewLC( 
       
   245                 KCRUidWlanDeviceSettingsRegistryId );
       
   246         if ( repository )
       
   247             {
       
   248             repository->Get( KWlanDefaultBGScanInterval, defaultScanInterval );
       
   249             }
       
   250         CleanupStack::PopAndDestroy( repository );
       
   251         return defaultScanInterval;
       
   252         }
       
   253     else
       
   254         {
       
   255         return KWlanSettingsUiDefaultScanNetwork;
       
   256         }
       
   257     }
       
   258 
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // CWsfDbObserver::RunError
       
   262 // ----------------------------------------------------------------------------
       
   263 //
       
   264 #ifdef _DEBUG
       
   265 TInt CWsfDbObserver::RunError( TInt aError )
       
   266     {
       
   267     LOG_ENTERFN( "CWsfDbObserver::RunError" );
       
   268     LOG_WRITEF( "aError = %d", aError );
       
   269 #else
       
   270 TInt CWsfDbObserver::RunError( TInt /*aError*/ )
       
   271     {
       
   272 #endif
       
   273     return KErrNone;
       
   274     }
       
   275 
       
   276