bluetoothengine/bteng/btbearer/src/btpluginnotifier.cpp
branchRCL_3
changeset 55 613943a21004
parent 0 f63038272f30
child 56 9386f31cc85b
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2010 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>
    26 
    29 
    27 // ======== MEMBER FUNCTIONS ========
    30 // ======== MEMBER FUNCTIONS ========
    28 
    31 
    29 // ---------------------------------------------------------------------------
    32 // ---------------------------------------------------------------------------
    30 // C++ default constructor
    33 // C++ default constructor
    57 	CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
    60 	CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs );
    58 	repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff );
    61 	repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff );
    59 	delete repository;
    62 	delete repository;
    60 	
    63 	
    61 	CBTEngSettings* settings = CBTEngSettings::NewL();
    64 	CBTEngSettings* settings = CBTEngSettings::NewL();
       
    65 	iBTIndicator = CHbIndicatorSymbian::NewL(); 
    62 	
    66 	
    63 	BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EnterpriseEnablementL();
    67 	BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EnterpriseEnablementL();
    64 	TRACE_INFO( ( _L( "mode = %d" ), mode) )
    68 	TRACE_INFO( ( _L( "mode = %d" ), mode) )
    65     if( power == EBTPowerOn && offlineModeOff == ECoreAppUIsNetworkConnectionAllowed && mode != BluetoothFeatures::EDisabled )
    69     if( power == EBTPowerOn && offlineModeOff == ECoreAppUIsNetworkConnectionAllowed && mode != BluetoothFeatures::EDisabled )
    66         {
    70         {
    67              // BT was on before boot, turn it on again
    71              // BT was on before boot, turn it on again
    68         TRACE_INFO( ( _L( "Turning BT on" ) ) )
    72         TRACE_INFO( ( _L( "Turning BT on" ) ) )
    69         TInt err = settings->SetPowerState( EBTPowerOn );
    73         TInt err = settings->SetPowerState( EBTPowerOn );
    70         TRACE_INFO( ( _L( "SetPowerState returned %d" ), err ) )
    74         TRACE_INFO( ( _L( "SetPowerState returned %d" ), err ) )
    71         if( !err )
    75         if ( !err )
    72             {
    76             {
    73             iHandler.NotifyBearerStatus( ELocodBearerBT, power );
    77             HandleBtPowerChanged( EBTPowerOn );
    74             }
    78             }
    75         }
    79         }
    76     else
    80     else
    77         {
    81         {
    78         TRACE_INFO( ( _L( "Turning BT off" ) ) )
    82         TRACE_INFO( ( _L( "Turning BT off" ) ) )
    79         (void) settings->SetPowerState( EBTPowerOff );	// Result is not important here
    83         (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             }
    80         }
    92         }
    81     delete settings;
    93     delete settings;
    82 	if ( mode != BluetoothFeatures::EDisabled ) // only subscribe if there's any point (NB changing Enterprise Disabling mode requires a reboot)
    94 	if ( mode != BluetoothFeatures::EDisabled ) // only subscribe if there's any point (NB changing Enterprise Disabling mode requires a reboot)
    83 		SubscribeL();
    95 		SubscribeL();
    84     TRACE_FUNC_EXIT
    96     TRACE_FUNC_EXIT
   109 CBTPluginNotifier::~CBTPluginNotifier()
   121 CBTPluginNotifier::~CBTPluginNotifier()
   110     {
   122     {
   111     TRACE_FUNC_ENTRY
   123     TRACE_FUNC_ENTRY
   112     Cancel();
   124     Cancel();
   113     delete iSession;
   125     delete iSession;
       
   126     delete iBTIndicator;
   114     }
   127     }
   115 
   128 
   116 
   129 
   117 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   118 // CBTPluginNotifier::SubscribeL
   131 // CBTPluginNotifier::SubscribeL
   127         }
   140         }
   128     User::LeaveIfError( iSession->NotifyRequest( iId, iStatus ) );
   141     User::LeaveIfError( iSession->NotifyRequest( iId, iStatus ) );
   129     SetActive();
   142     SetActive();
   130     }
   143     }
   131 
   144 
       
   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     }
   132 
   169 
   133 // ---------------------------------------------------------------------------
   170 // ---------------------------------------------------------------------------
   134 // From class CActive.
   171 // From class CActive.
   135 // Called by the active scheduler when our subscription 
   172 // Called by the active scheduler when our subscription 
   136 // to the setting has been cancelled.
   173 // to the setting has been cancelled.
   160     switch( iKeyType )
   197     switch( iKeyType )
   161         {
   198         {
   162         case EKeyInt:
   199         case EKeyInt:
   163             {
   200             {
   164             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL2 %d]" ), status ) )
   201             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL2 %d]" ), status ) )
   165             TInt newValue = 1;
   202             TInt newValue = EBTPowerOff;
   166             iSession->Get( iId, newValue );
   203             TInt err = iSession->Get( iId, newValue );
   167             iHandler.NotifyBearerStatus( ELocodBearerBT, newValue );
   204             if ( !err )
       
   205                 {
       
   206                 HandleBtPowerChanged( static_cast<TBTPowerStateValue>( newValue ) );
       
   207                 }
   168             }
   208             }
   169             break;
   209             break;
   170         default:
   210         default:
   171             {
   211             {
   172             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL3 %d]" ), status ) )
   212             TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL3 %d]" ), status ) )