bluetoothengine/bteng/btbearer/src/btpluginnotifier.cpp
branchRCL_3
changeset 23 9386f31cc85b
parent 22 613943a21004
equal deleted inserted replaced
22:613943a21004 23:9386f31cc85b
     1 /*
     1 /*
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    21 #include <btengsettings.h>
    21 #include <btengsettings.h>
    22 #include <CoreApplicationUIsSDKCRKeys.h>
    22 #include <CoreApplicationUIsSDKCRKeys.h>
    23 #include "btpluginnotifier.h"
    23 #include "btpluginnotifier.h"
    24 #include "debug.h"
    24 #include "debug.h"
    25 #include <btfeaturescfg.h>
    25 #include <btfeaturescfg.h>
    26 #include <btnotifclient.h>
       
    27 #include "btindicatorconstants.h"
       
    28 #include <hbsymbianvariant.h>
       
    29 
    26 
    30 // ======== MEMBER FUNCTIONS ========
    27 // ======== MEMBER FUNCTIONS ========
    31 
    28 
    32 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    33 // C++ default constructor
    30 // C++ default constructor
    60 	CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
    57 	CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
    61 	repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff );
    58 	repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff );
    62 	delete repository;
    59 	delete repository;
    63 	
    60 	
    64 	CBTEngSettings* settings = CBTEngSettings::NewL();
    61 	CBTEngSettings* settings = CBTEngSettings::NewL();
    65 	iBTIndicator = CHbIndicatorSymbian::NewL(); 
       
    66 	
    62 	
    67 	BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EnterpriseEnablementL();
    63 	BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EnterpriseEnablementL();
    68 	TRACE_INFO( ( _L( "mode = %d" ), mode) )
    64 	TRACE_INFO( ( _L( "mode = %d" ), mode) )
    69     if( power == EBTPowerOn && offlineModeOff == ECoreAppUIsNetworkConnectionAllowed && mode != BluetoothFeatures::EDisabled )
    65     if( power == EBTPowerOn && offlineModeOff == ECoreAppUIsNetworkConnectionAllowed && mode != BluetoothFeatures::EDisabled )
    70         {
    66         {
    71              // BT was on before boot, turn it on again
    67              // BT was on before boot, turn it on again
    72         TRACE_INFO( ( _L( "Turning BT on" ) ) )
    68         TRACE_INFO( ( _L( "Turning BT on" ) ) )
    73         TInt err = settings->SetPowerState( EBTPowerOn );
    69         TInt err = settings->SetPowerState( EBTPowerOn );
    74         TRACE_INFO( ( _L( "SetPowerState returned %d" ), err ) )
    70         TRACE_INFO( ( _L( "SetPowerState returned %d" ), err ) )
    75         if ( !err )
    71         if( !err )
    76             {
    72             {
    77             HandleBtPowerChanged( EBTPowerOn );
    73             iHandler.NotifyBearerStatus( ELocodBearerBT, power );
    78             }
    74             }
    79         }
    75         }
    80     else
    76     else
    81         {
    77         {
    82         TRACE_INFO( ( _L( "Turning BT off" ) ) )
    78         TRACE_INFO( ( _L( "Turning BT off" ) ) )
    83         (void) settings->SetPowerState( EBTPowerOff );	// Result is not important here
    79         (void) settings->SetPowerState( EBTPowerOff );	// Result is not important here
    84         TInt state =  EBTIndicatorOff;
       
    85         CHbSymbianVariant* parameters = CHbSymbianVariant::NewL(&state,CHbSymbianVariant::EInt );
       
    86         TBool success = iBTIndicator->Activate(KIndicatorType(),parameters); 
       
    87         delete parameters;
       
    88         if(!success)
       
    89             {
       
    90             User::Leave(iBTIndicator->Error());
       
    91             }
       
    92         }
    80         }
    93     delete settings;
    81     delete settings;
    94 	if ( mode != BluetoothFeatures::EDisabled ) // only subscribe if there's any point (NB changing Enterprise Disabling mode requires a reboot)
    82 	if ( mode != BluetoothFeatures::EDisabled ) // only subscribe if there's any point (NB changing Enterprise Disabling mode requires a reboot)
    95 		SubscribeL();
    83 		SubscribeL();
    96     TRACE_FUNC_EXIT
    84     TRACE_FUNC_EXIT
   121 CBTPluginNotifier::~CBTPluginNotifier()
   109 CBTPluginNotifier::~CBTPluginNotifier()
   122     {
   110     {
   123     TRACE_FUNC_ENTRY
   111     TRACE_FUNC_ENTRY
   124     Cancel();
   112     Cancel();
   125     delete iSession;
   113     delete iSession;
   126     delete iBTIndicator;
       
   127     }
   114     }
   128 
   115 
   129 
   116 
   130 // ---------------------------------------------------------------------------
   117 // ---------------------------------------------------------------------------
   131 // CBTPluginNotifier::SubscribeL
   118 // CBTPluginNotifier::SubscribeL
   140         }
   127         }
   141     User::LeaveIfError( iSession->NotifyRequest( iId, iStatus ) );
   128     User::LeaveIfError( iSession->NotifyRequest( iId, iStatus ) );
   142     SetActive();
   129     SetActive();
   143     }
   130     }
   144 
   131 
   145 // ---------------------------------------------------------------------------
       
   146 // Handles power state change. Inform Locod. In addition, if BT is on, start
       
   147 // btnotifier server.
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void CBTPluginNotifier::HandleBtPowerChanged( TBTPowerStateValue aPower )
       
   151     {
       
   152     TRACE_FUNC_ARG( ( _L( " to %d" ), aPower ) )
       
   153     TInt err (KErrNone );
       
   154     if ( aPower == EBTPowerOn )
       
   155         {
       
   156         // Start BT notifier server by creating a session with it:
       
   157         RBTNotifier btnotif;
       
   158         err = btnotif.Connect();
       
   159         TRACE_INFO( ( _L( "start bt notifier server %d" ), err ) )
       
   160         // btnotif server manages its lifecycle. no need
       
   161         // to keep this session:
       
   162         btnotif.Close();
       
   163         }
       
   164     if ( !err )
       
   165         {
       
   166         iHandler.NotifyBearerStatus( ELocodBearerBT, aPower );
       
   167         }
       
   168     }
       
   169 
   132 
   170 // ---------------------------------------------------------------------------
   133 // ---------------------------------------------------------------------------
   171 // From class CActive.
   134 // From class CActive.
   172 // Called by the active scheduler when our subscription 
   135 // Called by the active scheduler when our subscription 
   173 // to the setting has been cancelled.
   136 // to the setting has been cancelled.
   197     switch( iKeyType )
   160     switch( iKeyType )
   198         {
   161         {
   199         case EKeyInt:
   162         case EKeyInt:
   200             {
   163             {
   201             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL2 %d]" ), status ) )
   164             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL2 %d]" ), status ) )
   202             TInt newValue = EBTPowerOff;
   165             TInt newValue = 1;
   203             TInt err = iSession->Get( iId, newValue );
   166             iSession->Get( iId, newValue );
   204             if ( !err )
   167             iHandler.NotifyBearerStatus( ELocodBearerBT, newValue );
   205                 {
       
   206                 HandleBtPowerChanged( static_cast<TBTPowerStateValue>( newValue ) );
       
   207                 }
       
   208             }
   168             }
   209             break;
   169             break;
   210         default:
   170         default:
   211             {
   171             {
   212             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL3 %d]" ), status ) )
   172             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL3 %d]" ), status ) )