bluetoothengine/bteng/src/btengsrvsettingsmgr.cpp
changeset 19 43824b19ee35
parent 17 f05641c183ff
child 41 0b2439c3e397
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
    21 #include <btnotif.h>
    21 #include <btnotif.h>
    22 #include <btengdomainpskeys.h>
    22 #include <btengdomainpskeys.h>
    23 #include <centralrepository.h>
    23 #include <centralrepository.h>
    24 #include <featmgr.h>
    24 #include <featmgr.h>
    25 #include <AknSmallIndicator.h>
    25 #include <AknSmallIndicator.h>
    26 #include <avkon.hrh>
    26 //#include <avkon.hrh>
    27 
       
    28 #include "btengserver.h"
    27 #include "btengserver.h"
    29 #include "btengsrvpluginmgr.h"
    28 #include "btengsrvpluginmgr.h"
    30 #include "btengsrvbbconnectionmgr.h"
    29 #include "btengsrvbbconnectionmgr.h"
    31 #include "btengsrvstate.h"
    30 #include "btengsrvstate.h"
    32 #include "debug.h"
    31 #include "debug.h"
    91 // Destructor
    90 // Destructor
    92 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    93 //
    92 //
    94 CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
    93 CBTEngSrvSettingsMgr::~CBTEngSrvSettingsMgr()
    95     {
    94     {
    96     if( iActive && iActive->IsActive() )
       
    97         {
       
    98         // Cancel the outstanding request.
       
    99         iPowerMgr.Cancel();
       
   100         }
       
   101     delete iActive;  
    95     delete iActive;  
   102     iPowerMgr.Close();
    96     iPowerMgr.Close();
   103     }
    97     }
   104 
    98 
   105 
    99 
   182         // We don't return an error here, as there is no error situation.
   176         // We don't return an error here, as there is no error situation.
   183         TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
   177         TRACE_INFO( ( _L( "SetPowerStateL: nothing to do" ) ) )
   184         if ( currentState == aState )
   178         if ( currentState == aState )
   185             {
   179             {
   186             // Make sure that the CenRep key is in sync.
   180             // Make sure that the CenRep key is in sync.
   187             // During boot-up, the pwoer is set from the CenRep key, so we could 
   181             // During boot-up, the power is set from the CenRep key, so we could 
   188             // end up out-of-sync.
   182             // end up out-of-sync.
   189             TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
   183             TRACE_INFO( ( _L( "SetPowerStateL: currentState == aState" ) ) )
   190             UpdateCenRepPowerKeyL( aState );
   184             HandleHwPowerChangeL( aState );
   191             } 
   185             }
   192         return;
   186         return;
   193         }
   187         }
   194     if ( aState == EBTOn )
   188     if ( aState == EBTOn )
   195         {
   189         {
   196         // Hardware power on is the first step.
   190         // Hardware power on is the first step.
   316     TRACE_FUNC_EXIT
   310     TRACE_FUNC_EXIT
   317     }
   311     }
   318 
   312 
   319 
   313 
   320 // ---------------------------------------------------------------------------
   314 // ---------------------------------------------------------------------------
   321 // Update the power state CenRep key.
   315 // Update the power state CenRep key, and start BTNotif server if BT is on.
   322 // ---------------------------------------------------------------------------
   316 // ---------------------------------------------------------------------------
   323 //
   317 //
   324 void CBTEngSrvSettingsMgr::UpdateCenRepPowerKeyL( TBTPowerState aState )
   318 void CBTEngSrvSettingsMgr::HandleHwPowerChangeL( TBTPowerState aState )
   325     {
   319     {
   326     TRACE_FUNC_ENTRY
   320     TRACE_FUNC_ENTRY
   327     CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   321     CRepository* cenrep = CRepository::NewLC( KCRUidBluetoothPowerState );
   328     // TBTPowerState power state type is inverted from TBTPowerStateValue...
   322     // TBTPowerState power state type is inverted from TBTPowerStateValue...
   329     TBTPowerStateValue power = (TBTPowerStateValue) !aState;
   323     TBTPowerStateValue power = ( aState == EBTOn ) ? EBTPowerOn : EBTPowerOff;
   330     User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
   324     User::LeaveIfError( cenrep->Set( KBTPowerState, (TInt) power ) );
   331     CleanupStack::PopAndDestroy( cenrep );
   325     CleanupStack::PopAndDestroy( cenrep );
   332     TRACE_FUNC_EXIT
   326     TRACE_FUNC_EXIT
   333     }
   327     }
   334 
       
   335 
   328 
   336 // ---------------------------------------------------------------------------
   329 // ---------------------------------------------------------------------------
   337 // ?implementation_description
   330 // ?implementation_description
   338 // ---------------------------------------------------------------------------
   331 // ---------------------------------------------------------------------------
   339 //
   332 //
   652 // ---------------------------------------------------------------------------
   645 // ---------------------------------------------------------------------------
   653 // From class MBTEngActiveObserver.
   646 // From class MBTEngActiveObserver.
   654 // Callback to notify that an outstanding request has completed.
   647 // Callback to notify that an outstanding request has completed.
   655 // ---------------------------------------------------------------------------
   648 // ---------------------------------------------------------------------------
   656 //
   649 //
   657 void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aId, TInt aStatus )
   650 void CBTEngSrvSettingsMgr::RequestCompletedL( CBTEngActive* aActive, TInt aStatus )
   658     {
   651     {
   659     __ASSERT_ALWAYS( aId == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
   652     __ASSERT_ALWAYS( aActive->RequestId() == KBTEngSettingsActive, PanicServer( EBTEngPanicCorrupt ) );
   660     TRACE_FUNC_ENTRY
   653     TRACE_FUNC_ENTRY
   661     (void) aActive;
   654     (void) aActive;
   662     if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
   655     if ( aStatus != KErrNone && aStatus != KErrAlreadyExists && aStatus != KErrCancel )
   663         {
   656         {
   664         // Something went wrong, so we turn BT off again.
   657         // Something went wrong, so we turn BT off again.
   665         SetPowerStateL( EBTOff, EFalse );
   658         SetPowerStateL( EBTOff, EFalse );
   666         }
   659         }
   667     
       
   668     if ( !iMessage.IsNull())
   660     if ( !iMessage.IsNull())
   669         {
   661         {
   670         iMessage.Complete( aStatus );
   662         iMessage.Complete( aStatus );
   671         }
   663         }
   672     TRACE_FUNC_EXIT
   664     TRACE_FUNC_EXIT
   673     }
   665     }
   674 
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // From class MBTEngActiveObserver.
       
   669 // Handles cancelation of an outstanding request
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 void CBTEngSrvSettingsMgr::CancelRequest( TInt aRequestId )
       
   673     {
       
   674     TRACE_FUNC_ARG( ( _L( "reqID %d" ), aRequestId ) );
       
   675     if ( aRequestId == KBTEngSettingsActive )
       
   676         {
       
   677         iPowerMgr.Cancel();
       
   678         }
       
   679     TRACE_FUNC_EXIT 
       
   680     }
   675 
   681 
   676 // ---------------------------------------------------------------------------
   682 // ---------------------------------------------------------------------------
   677 // From class MBTEngActiveObserver.
   683 // From class MBTEngActiveObserver.
   678 // Callback to notify that an error has occurred in RunL.
   684 // Callback to notify that an error has occurred in RunL.
   679 // ---------------------------------------------------------------------------
   685 // ---------------------------------------------------------------------------
   680 //
   686 //
   681 void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aId, TInt aError )
   687 void CBTEngSrvSettingsMgr::HandleError( CBTEngActive* aActive, TInt aError )
   682     {
   688     {
   683     (void) aActive;
   689     (void) aActive;
   684     (void) aId;
       
   685     if ( !iMessage.IsNull())
   690     if ( !iMessage.IsNull())
   686         {
   691         {
   687         iMessage.Complete( aError );
   692         iMessage.Complete( aError );
   688         }
   693         }
   689     }
   694     }
   727     User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
   732     User::LeaveIfError( cenrep->Get( KBTPowerState, (TInt&) powerState ) );
   728     CleanupStack::PopAndDestroy( cenrep );
   733     CleanupStack::PopAndDestroy( cenrep );
   729     
   734     
   730     if( powerState == EBTPowerOff )
   735     if( powerState == EBTPowerOff )
   731         {
   736         {
   732         SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   737         // To be migrated
   733         SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   738         //SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   734         SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   739         //SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   735         SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   740         //SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
       
   741         //SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   736         }
   742         }
   737     else
   743     else
   738         {
   744         {
   739         // Power is on.
   745         // Power is on.
   740         RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
   746         RProperty::Get( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount, phys );
   746         
   752         
   747         if( visibilityMode == EBTVisibilityModeHidden )
   753         if( visibilityMode == EBTVisibilityModeHidden )
   748             {
   754             {
   749              if ( connecting ) // BT connecting and hidden
   755              if ( connecting ) // BT connecting and hidden
   750                 {
   756                 {
   751                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   757                 // To be migrated to QT
   752                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateAnimate );
   758                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
       
   759                 //SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateAnimate );
   753                 }
   760                 }
   754             else if ( phys > 0 ) // BT connection active and hidden     
   761             else if ( phys > 0 ) // BT connection active and hidden     
   755                 {
   762                 {
   756                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   763                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   757                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOn );
   764                 //SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOn );
   758                 }
   765                 }
   759             else  // BT connection not active and hidden
   766             else  // BT connection not active and hidden
   760                 {
   767                 {
   761                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOn );
   768                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOn );
   762                 SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   769                 //SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   763                 }
   770                 }
   764             SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   771             //SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   765             SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   772             //SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   766             }           
   773             }           
   767         else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
   774         else if( visibilityMode == EBTVisibilityModeGeneral || visibilityMode == EBTVisibilityModeTemporary )
   768             {     
   775             {     
   769             if ( connecting ) // BT connecting and visible
   776             if ( connecting ) // BT connecting and visible
   770                 {
   777                 {
   771                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   778                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   772                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateAnimate );
   779                 //SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateAnimate );
   773                 }
   780                 }
   774             else if ( phys > 0 ) // BT connection active and visible 
   781             else if ( phys > 0 ) // BT connection active and visible 
   775                 {
   782                 {
   776                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   783                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOff );
   777                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOn );
   784                 //SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOn );
   778                 }
   785                 }
   779             else  // BT connection not active and visible
   786             else  // BT connection not active and visible
   780                 {
   787                 {
   781                 SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOn );
   788                 //SetIndicatorStateL( EAknIndicatorBluetoothModuleOnVisible, EAknIndicatorStateOn );
   782                 SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   789                 //SetIndicatorStateL( EAknIndicatorBluetoothVisible, EAknIndicatorStateOff );
   783                 }
   790                 }
   784             SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   791             //SetIndicatorStateL( EAknIndicatorBluetoothModuleOn, EAknIndicatorStateOff );
   785             SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   792             //SetIndicatorStateL( EAknIndicatorBluetooth, EAknIndicatorStateOff );
   786             }
   793             }
   787         }
   794         }
   788     TRACE_FUNC_EXIT
   795     TRACE_FUNC_EXIT
   789     }
   796     }
   790 
       
   791 
   797 
   792 // ---------------------------------------------------------------------------
   798 // ---------------------------------------------------------------------------
   793 // ?implementation_description
   799 // ?implementation_description
   794 // ---------------------------------------------------------------------------
   800 // ---------------------------------------------------------------------------
   795 //
   801 //
   796 void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aIndicator, const TInt aState )
   802 void CBTEngSrvSettingsMgr::SetIndicatorStateL( const TInt aIndicator, const TInt aState )
   797     {
   803     {
   798     CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
   804     // To be migrated to QT
   799     indicator->SetIndicatorStateL( aState );
   805     (void) aIndicator;
   800     CleanupStack::PopAndDestroy( indicator ); //indicator
   806     (void) aState;
       
   807     //CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC( TUid::Uid( aIndicator ) );
       
   808     //indicator->SetIndicatorStateL( aState );
       
   809     //CleanupStack::PopAndDestroy( indicator ); //indicator
   801     }
   810     }
   802 
   811 
   803 
   812 
   804 // ---------------------------------------------------------------------------
   813 // ---------------------------------------------------------------------------
   805 // Gets the current HW power state.
   814 // Gets the current HW power state.
   884         {
   893         {
   885         iAutoOffClients = 0;
   894         iAutoOffClients = 0;
   886         }
   895         }
   887     TRACE_FUNC_EXIT 
   896     TRACE_FUNC_EXIT 
   888     }
   897     }
       
   898