bluetoothengine/bteng/src/btengsrvkeywatcher.cpp
changeset 0 f63038272f30
child 10 0707dd69d236
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Watcher for BTEng server PubSub and CenRep keys.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <startupdomainpskeys.h>
       
    21 #include <coreapplicationuisdomainpskeys.h>
       
    22 #include <ctsydomainpskeys.h>
       
    23 #include <centralrepository.h>
       
    24 #include <bt_subscribe.h>
       
    25 
       
    26 #include "btengsrvkeywatcher.h"
       
    27 #include "btengserver.h"
       
    28 #include "btengsrvpluginmgr.h"
       
    29 #include "btengprivatepskeys.h"
       
    30 #include "btengprivatecrkeys.h"
       
    31 #include "debug.h"
       
    32 
       
    33 /**  Identification for active object */
       
    34 const TInt KBTEngDutWatcher = 15;
       
    35 /**  Identification for active object */
       
    36 const TInt KBTEngLockWatcher = 16;
       
    37 /**  Identification for active object */
       
    38 const TInt KBTEngSysWatcher = 17;
       
    39 /**  Identification for active object */
       
    40 const TInt KBTEngPHYCountWatcher = 18;
       
    41 /**  Identification for active object */
       
    42 const TInt KBTEngBtConnectionWatcher = 19;
       
    43 /**  Identification for active object */
       
    44 const TInt KBTEngScanningWatcher = 20;
       
    45 /**  Identification for active object */
       
    46 const TInt KBTEngEmergencyWatcher = 21;
       
    47 /**  Identification for active object */
       
    48 const TInt KBTEngSapWatcher = 22;
       
    49 /**  Identification for active object */
       
    50 const TInt KBTEngAddrWatcher = 23;
       
    51 /**  Identification for active object */
       
    52 const TInt KBTEngRegistryWatcher = 24;
       
    53 /**  Identification for active object */
       
    54 const TInt KBTEngSspDebugWatcher = 25;
       
    55 /**  Buffer size for BT device address as stored in CenRep */
       
    56 const TInt KCenRepAddrBufSize = 2 * KBTDevAddrSize;
       
    57 
       
    58 
       
    59 // ======== MEMBER FUNCTIONS ========
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // C++ default constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CBTEngSrvKeyWatcher::CBTEngSrvKeyWatcher( CBTEngServer* aServer )
       
    66 :   iServer( aServer )
       
    67     {
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Symbian 2nd-phase constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CBTEngSrvKeyWatcher::ConstructL()
       
    76     {
       
    77     TRACE_FUNC_ENTRY
       
    78     TInt err = iDutModeKey.Attach( KPSUidBluetoothTestingMode, KBTDutEnabled );
       
    79     if( !err )
       
    80         {
       
    81         iDutModeWatcher = CBTEngActive::NewL( *this, KBTEngDutWatcher, 
       
    82                                                CActive::EPriorityStandard );
       
    83         iDutModeKey.Subscribe( iDutModeWatcher->RequestStatus() );
       
    84         iDutModeWatcher->GoActive();
       
    85         }
       
    86 #ifdef RD_REMOTELOCK
       
    87     err = iPhoneLockKey.Attach( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus );
       
    88     if( !err )
       
    89         {
       
    90         iPhoneLockWatcher = CBTEngActive::NewL( *this, KBTEngLockWatcher, 
       
    91                                                  CActive::EPriorityStandard );
       
    92         iPhoneLockKey.Subscribe( iPhoneLockWatcher->RequestStatus() );
       
    93         iPhoneLockWatcher->GoActive();
       
    94         }
       
    95 #endif  //RD_REMOTELOCK
       
    96 
       
    97     err = iSystemStateKey.Attach( KPSUidStartup, KPSGlobalSystemState );
       
    98     if( !err )
       
    99         {
       
   100         iSystemStateWatcher = CBTEngActive::NewL( *this, KBTEngSysWatcher, 
       
   101                                                    CActive::EPriorityStandard );
       
   102         iSystemStateKey.Subscribe( iSystemStateWatcher->RequestStatus() );
       
   103         iSystemStateWatcher->GoActive();
       
   104         }
       
   105         
       
   106     err = iPHYCountKey.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothPHYCount );
       
   107     if( !err )
       
   108         {
       
   109         iPHYCountWatcher = CBTEngActive::NewL( *this, KBTEngPHYCountWatcher, 
       
   110                                                CActive::EPriorityStandard );
       
   111         iPHYCountKey.Subscribe( iPHYCountWatcher->RequestStatus() );
       
   112         iPHYCountWatcher->GoActive();
       
   113         }
       
   114         
       
   115     err = iBtConnectionKey.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothConnecting );
       
   116     if( !err )
       
   117         {
       
   118         iBtConnectionWatcher = CBTEngActive::NewL( *this, KBTEngBtConnectionWatcher, 
       
   119                                                CActive::EPriorityStandard );
       
   120         iBtConnectionKey.Subscribe( iBtConnectionWatcher->RequestStatus() );
       
   121         iBtConnectionWatcher->GoActive();
       
   122         }
       
   123 
       
   124     err = iBtScanningKey.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus );
       
   125     if( !err )
       
   126         {
       
   127         iBtScanningWatcher = CBTEngActive::NewL( *this, KBTEngScanningWatcher, 
       
   128                                                CActive::EPriorityStandard );
       
   129         iBtScanningKey.Subscribe( iBtScanningWatcher->RequestStatus() );
       
   130         iBtScanningWatcher->GoActive();
       
   131         }
       
   132 
       
   133     err = iEmergencyCallKey.Attach( KPSUidCtsyEmergencyCallInfo, KCTSYEmergencyCallInfo );
       
   134     if( !err )
       
   135         {
       
   136         iEmergencyCallWatcher = CBTEngActive::NewL( *this, KBTEngEmergencyWatcher, 
       
   137                                                    CActive::EPriorityStandard );
       
   138         iEmergencyCallKey.Subscribe( iEmergencyCallWatcher->RequestStatus() );
       
   139         iEmergencyCallWatcher->GoActive();
       
   140         }
       
   141 
       
   142     err = iBtRegistryKey.Attach( KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetRegistryTableChange );
       
   143     if( !err )
       
   144         {
       
   145         iBtRegistryWatcher = CBTEngActive::NewL( *this, KBTEngRegistryWatcher, 
       
   146                                                  CActive::EPriorityStandard );
       
   147         iBtRegistryKey.Subscribe( iBtRegistryWatcher->RequestStatus() );
       
   148         iBtRegistryWatcher->GoActive();
       
   149         }
       
   150 
       
   151     err = iSspDebugModeKey.Attach( KPSUidBluetoothTestingMode, KBTSspDebugmode );
       
   152     if( !err )
       
   153         {
       
   154         iSspDebugModeWatcher = CBTEngActive::NewL( *this, KBTEngSspDebugWatcher, 
       
   155                                                     CActive::EPriorityStandard );
       
   156         iSspDebugModeKey.Subscribe( iSspDebugModeWatcher->RequestStatus() );
       
   157         iSspDebugModeWatcher->GoActive();
       
   158         }
       
   159 
       
   160         // Use TRAP here, because it leaves if the key does not exist.
       
   161     TRAP( err, iSapKeyCenRep = CRepository::NewL( KCRUidBTEngPrivateSettings ) );
       
   162     if( !err )
       
   163         {
       
   164         iSapModeWatcher = CBTEngActive::NewL( *this, KBTEngSapWatcher, 
       
   165                                                      CActive::EPriorityStandard );
       
   166         err = iSapKeyCenRep->NotifyRequest( KBTSapEnabled, 
       
   167                                              iSapModeWatcher->RequestStatus() );
       
   168         }
       
   169     if( !err )
       
   170         {
       
   171         iSapModeWatcher->GoActive();
       
   172         }
       
   173     err = iBdaddrKey.Attach( KPropertyUidBluetoothCategory, 
       
   174                               KPropertyKeyBluetoothGetLocalDeviceAddress );
       
   175                               
       
   176     if( !err )
       
   177         {
       
   178         CheckBDAddrL();
       
   179         }
       
   180     TRACE_FUNC_EXIT
       
   181     }
       
   182 
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // NewL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 CBTEngSrvKeyWatcher* CBTEngSrvKeyWatcher::NewL( CBTEngServer* aServer )
       
   189     {
       
   190     CBTEngSrvKeyWatcher* self = new( ELeave ) CBTEngSrvKeyWatcher( aServer );
       
   191     CleanupStack::PushL( self );
       
   192     self->ConstructL();
       
   193     CleanupStack::Pop( self );
       
   194     return self;
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Destructor
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 CBTEngSrvKeyWatcher::~CBTEngSrvKeyWatcher()
       
   203     {
       
   204     if( iDutModeKey.Handle() )
       
   205         {
       
   206         iDutModeKey.Cancel();
       
   207         }
       
   208     delete iDutModeWatcher;
       
   209     iDutModeKey.Close();
       
   210 
       
   211 #ifdef RD_REMOTELOCK
       
   212     if( iPhoneLockKey.Handle() )
       
   213         {
       
   214         iPhoneLockKey.Cancel();
       
   215         }
       
   216     delete iPhoneLockWatcher;
       
   217     iPhoneLockKey.Close();
       
   218 #endif  //RD_REMOTELOCK
       
   219 
       
   220     if( iSystemStateKey.Handle() )
       
   221         {
       
   222         iSystemStateKey.Cancel();
       
   223         }
       
   224     delete iSystemStateWatcher;
       
   225     iSystemStateKey.Close();
       
   226     
       
   227     if( iPHYCountKey.Handle() )
       
   228         {
       
   229         iPHYCountKey.Cancel();
       
   230         }
       
   231     delete iPHYCountWatcher;
       
   232     iPHYCountKey.Close();
       
   233      
       
   234     if( iBtConnectionKey.Handle() )
       
   235         {
       
   236         iBtConnectionKey.Cancel();
       
   237         }
       
   238     delete iBtConnectionWatcher;
       
   239     iBtConnectionKey.Close();
       
   240     
       
   241     if( iBtScanningKey.Handle() )
       
   242         {
       
   243         iBtScanningKey.Cancel();
       
   244         }
       
   245     delete iBtScanningWatcher;
       
   246     iBtScanningKey.Close();
       
   247 
       
   248     if( iEmergencyCallKey.Handle() )
       
   249         {
       
   250         iEmergencyCallKey.Cancel();
       
   251         }
       
   252     delete iEmergencyCallWatcher;
       
   253     iEmergencyCallKey.Close();
       
   254     
       
   255     if( iSspDebugModeKey.Handle() )
       
   256         {
       
   257         iSspDebugModeKey.Cancel();
       
   258         }
       
   259     delete iSspDebugModeWatcher;
       
   260     iSspDebugModeKey.Close();
       
   261 
       
   262     if( iBtRegistryKey.Handle() )
       
   263     	{
       
   264     	iBtRegistryKey.Cancel();
       
   265     	}
       
   266     delete iBtRegistryWatcher;
       
   267     iBtRegistryKey.Close();
       
   268 
       
   269     if( iSapKeyCenRep )
       
   270         {
       
   271         iSapKeyCenRep->NotifyCancel( KBTSapEnabled );
       
   272         }
       
   273     delete iSapModeWatcher;
       
   274     delete iSapKeyCenRep;
       
   275 
       
   276     if( iBdaddrKey.Handle() )
       
   277         {
       
   278         iBdaddrKey.Cancel();
       
   279         }
       
   280     delete iBdaddrWatcher;
       
   281     iBdaddrKey.Close();
       
   282     }
       
   283 
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // From class MBTEngActiveObserver.
       
   287 // Processes a changed key value.
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CBTEngSrvKeyWatcher::RequestCompletedL( CBTEngActive* aActive, TInt aId, 
       
   291     TInt aStatus )
       
   292     {
       
   293     TRACE_FUNC_ARG( ( _L( "status %d" ), aStatus ) )
       
   294     ASSERT( aStatus != KErrPermissionDenied );
       
   295     TInt val = 0;
       
   296     switch( aId )
       
   297         {
       
   298         case KBTEngDutWatcher:
       
   299             {
       
   300             TRACE_INFO( ( _L( "DUT mode key changed" ) ) )
       
   301             iDutModeKey.Subscribe( aActive->RequestStatus() );
       
   302             aActive->GoActive();
       
   303             if( !aStatus && !iDutModeKey.Get( val ) )
       
   304                 {
       
   305                 iServer->SetDutMode( val );
       
   306                 }
       
   307             }
       
   308             break;
       
   309         case KBTEngLockWatcher:
       
   310             {
       
   311             TRACE_INFO( ( _L( "phone lock key changed" ) ) )
       
   312 #ifdef RD_REMOTELOCK
       
   313             iPhoneLockKey.Subscribe( aActive->RequestStatus() );
       
   314             aActive->GoActive();
       
   315             TInt remoteLockVal = 0;
       
   316             remoteLockVal = ERemoteLocked;
       
   317             if( !aStatus && !iPhoneLockKey.Get( val ) && val == remoteLockVal )
       
   318                 {
       
   319                 iServer->SetPowerStateL( EBTPowerOff, EFalse );
       
   320                 }
       
   321 #endif  //RD_REMOTELOCK
       
   322             }
       
   323             break;
       
   324         case KBTEngSysWatcher:
       
   325             {
       
   326             TRACE_INFO( ( _L( "System state key changed" ) ) )
       
   327             iSystemStateKey.Subscribe( aActive->RequestStatus() );
       
   328             aActive->GoActive();
       
   329             if( !aStatus && !iSystemStateKey.Get( val ) && 
       
   330                  val == ESwStateShuttingDown )
       
   331                 {
       
   332                 iServer->SetVisibilityModeL( EBTVisibilityModeNoScans , 0 );
       
   333                 iServer->DisconnectAllL();   
       
   334                 }
       
   335             }
       
   336             break;   
       
   337         case KBTEngPHYCountWatcher:
       
   338             {
       
   339             TRACE_INFO( ( _L( "PHY count key changed" ) ) )
       
   340             iPHYCountKey.Subscribe( aActive->RequestStatus() );
       
   341             aActive->GoActive();
       
   342             iServer->SetUiIndicatorsL();
       
   343             }
       
   344             break;
       
   345         case KBTEngBtConnectionWatcher:
       
   346             {
       
   347             TRACE_INFO( ( _L( "BT connection key changed" ) ) )
       
   348             iBtConnectionKey.Subscribe( aActive->RequestStatus() );
       
   349             aActive->GoActive();
       
   350             iServer->SetUiIndicatorsL();
       
   351             }
       
   352             break;        
       
   353         case KBTEngScanningWatcher:
       
   354             {
       
   355             TRACE_INFO( ( _L( "BT stack scanning key changed" ) ) )
       
   356             iBtScanningKey.Subscribe( aActive->RequestStatus() );
       
   357             aActive->GoActive();
       
   358             if ( !iBtScanningKey.Get( val ) )
       
   359                 {
       
   360                 iServer->UpdateVisibilityModeL( val );
       
   361                 }
       
   362             }
       
   363             break;
       
   364         case KBTEngEmergencyWatcher:
       
   365             {
       
   366             TRACE_INFO( ( _L( "Emergency call key changed" ) ) )
       
   367             iEmergencyCallKey.Subscribe( aActive->RequestStatus() );
       
   368             aActive->GoActive();
       
   369             if( !aStatus && !iEmergencyCallKey.Get( val ) && val )
       
   370                 {
       
   371                 // An emergency call initiated -> Close SAP connection if it's active
       
   372                 iServer->iPluginMgr->DisconnectProfile( EBTProfileSAP );
       
   373                 }
       
   374             }
       
   375             break;
       
   376         case KBTEngSspDebugWatcher:
       
   377             {
       
   378             TRACE_INFO( ( _L( "Simple pairing debug mode key changed" ) ) )
       
   379             iSspDebugModeKey.Subscribe( aActive->RequestStatus() );
       
   380             aActive->GoActive();
       
   381             if( !aStatus && !iSspDebugModeKey.Get( val ) )
       
   382                 {
       
   383                 iServer->CheckSspDebugModeL( (TBool) val );
       
   384                 }
       
   385             break;
       
   386             }
       
   387         case KBTEngRegistryWatcher:
       
   388         	{
       
   389             TRACE_INFO( ( _L( "BT Registry key changed" ) ) )
       
   390             TInt myChangedTable;
       
   391 
       
   392 			iBtRegistryKey.Subscribe( aActive->RequestStatus() );
       
   393 			aActive->GoActive();
       
   394 
       
   395             TInt err = iBtRegistryKey.Get( myChangedTable );
       
   396             if( !err && myChangedTable == KRegistryChangeRemoteTable )
       
   397             	{
       
   398             	TRACE_INFO( ( _L("BT Remote registry key changed") ) )
       
   399             	iServer->RemoteRegistryChangeDetected();            	
       
   400             	}
       
   401         	break;
       
   402         	}    
       
   403         case KBTEngSapWatcher:
       
   404             {
       
   405             TRACE_INFO( ( _L( "SAP mode key changed" ) ) )
       
   406             iSapKeyCenRep->NotifyRequest( KBTSapEnabled, aActive->RequestStatus() );
       
   407             aActive->GoActive();
       
   408             iSapKeyCenRep->Get( KBTSapEnabled, val );
       
   409             
       
   410             TBTPowerStateValue powerState = EBTPowerOff;
       
   411             User::LeaveIfError( iServer->GetHwPowerState( (TBTPowerStateValue&) powerState ) );
       
   412             if( aStatus >= 0 && powerState )
       
   413                 {
       
   414                 // Relevant only if BT is on
       
   415                 if( val == EBTSapEnabled )
       
   416                     {
       
   417                     iServer->iPluginMgr->LoadBTSapPluginL();
       
   418                     }
       
   419                 else
       
   420                     {
       
   421                     iServer->iPluginMgr->UnloadBTSapPlugin();
       
   422                     }
       
   423                 }
       
   424             }
       
   425             break;
       
   426         case KBTEngAddrWatcher:
       
   427             {
       
   428             TBuf8<KBTDevAddrSize> addrPubSub;
       
   429 			iBdaddrKey.Subscribe( aActive->RequestStatus() );
       
   430 			aActive->GoActive();
       
   431 
       
   432             if( !aStatus && !iBdaddrKey.Get( addrPubSub ) && 
       
   433                  addrPubSub.Length() == KBTDevAddrSize )
       
   434                 {
       
   435 				iBdaddrKey.Cancel();
       
   436 
       
   437                 TBTDevAddr addr( addrPubSub );
       
   438                 TBuf<KCenRepAddrBufSize> addrCenRep;
       
   439                 addr.GetReadable( addrCenRep );
       
   440                     // Write the key to CenRep and stop listening.
       
   441                 CRepository* cenRep = CRepository::NewL( 
       
   442                                             KCRUidBluetoothLocalDeviceAddress );
       
   443                 cenRep->Set( KBTLocalDeviceAddress, addrCenRep );
       
   444                 if ( iBdaddrWatcher )
       
   445                     {
       
   446                     delete iBdaddrWatcher;
       
   447                     iBdaddrWatcher = NULL;
       
   448                     }
       
   449                 iBdaddrKey.Close();
       
   450                 }
       
   451             }
       
   452             break;
       
   453         default:
       
   454             {
       
   455             TRACE_INFO( ( _L( "[BTENG]\t wrong key notification! id=%d" ), aId ) )
       
   456             }
       
   457             break;
       
   458 
       
   459         }
       
   460     TRACE_FUNC_EXIT
       
   461     }
       
   462 
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // From class MBTEngActiveObserver.
       
   466 // Handles a leave in RunL/RequestCompletedL by checking that all 
       
   467 // the subscriptions are active.
       
   468 // ---------------------------------------------------------------------------
       
   469 //
       
   470 void CBTEngSrvKeyWatcher::HandleError( CBTEngActive* aActive, TInt aId, 
       
   471     TInt aError )
       
   472     {
       
   473     TRACE_FUNC_ARG( ( _L( "status %d" ), aError ) )
       
   474     (void) aError;
       
   475     if( !aActive->IsActive() )
       
   476         {
       
   477         switch( aId )
       
   478             {
       
   479             case KBTEngDutWatcher:
       
   480                 {
       
   481                 iDutModeKey.Subscribe( aActive->RequestStatus() );
       
   482                 }
       
   483                 break;
       
   484             case KBTEngLockWatcher:
       
   485                 {
       
   486 #ifdef RD_REMOTELOCK
       
   487                 iPhoneLockKey.Subscribe( aActive->RequestStatus() );
       
   488 #else
       
   489                 return; // we don't want to go active without subscribing
       
   490 #endif  //RD_REMOTELOCK
       
   491                 }
       
   492                 break;
       
   493             case KBTEngSysWatcher:
       
   494                 {
       
   495                 iSystemStateKey.Subscribe( aActive->RequestStatus() );
       
   496                 }
       
   497                 break;
       
   498             case KBTEngSspDebugWatcher:
       
   499                 {
       
   500                 iSspDebugModeKey.Subscribe( aActive->RequestStatus() );
       
   501                 }
       
   502                 break;
       
   503             case KBTEngSapWatcher:
       
   504                 {
       
   505                 iSapKeyCenRep->NotifyRequest( KBTSapEnabled, aActive->RequestStatus() );
       
   506                 }
       
   507                 break;
       
   508             default:
       
   509                 {
       
   510                 TRACE_INFO( ( _L( "[BTENG]\t wrong key notification! id=%d" ), aId ) )
       
   511                 }
       
   512                 return; // we don't want to go active without subscribing
       
   513             }
       
   514         aActive->GoActive();
       
   515         }
       
   516     }
       
   517 
       
   518 
       
   519 // ---------------------------------------------------------------------------
       
   520 // Checks if we have already stored the BD_ADDR in CenRep; if not, we get it
       
   521 // from PubSub. If not available from PubSub yet, we subscribe to the key.
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 void CBTEngSrvKeyWatcher::CheckBDAddrL()
       
   525     {
       
   526     TBuf<KCenRepAddrBufSize> addrCenRep;
       
   527     CRepository* cenRep = NULL;
       
   528         // Use TRAP to catch a leave if the CenRep key does not exist.
       
   529     TRAPD( err, cenRep = CRepository::NewL( KCRUidBluetoothLocalDeviceAddress ) );
       
   530     CleanupStack::PushL( cenRep );
       
   531     if( !err )
       
   532         {
       
   533         err = cenRep->Get( KBTLocalDeviceAddress, addrCenRep );
       
   534         }
       
   535     if( err || addrCenRep.Length() != KCenRepAddrBufSize )
       
   536         {
       
   537         TBuf8<KBTDevAddrSize> addrPubSub;
       
   538         err = iBdaddrKey.Get( addrPubSub );
       
   539         if( !err && addrPubSub.Length() == KBTDevAddrSize )
       
   540             {
       
   541             TBTDevAddr addr( addrPubSub );  // For easy conversion
       
   542             addr.GetReadable( addrCenRep );
       
   543             cenRep->Set( KBTLocalDeviceAddress, addrCenRep );
       
   544             iBdaddrKey.Close();
       
   545             }
       
   546         else
       
   547             {
       
   548             iBdaddrWatcher = CBTEngActive::NewL( *this, KBTEngAddrWatcher, 
       
   549                                                         CActive::EPriorityStandard );
       
   550             iBdaddrKey.Subscribe( iBdaddrWatcher->RequestStatus() );
       
   551             iBdaddrWatcher->GoActive();
       
   552             }
       
   553         }
       
   554     else
       
   555         {
       
   556         iBdaddrKey.Close();
       
   557         }
       
   558     CleanupStack::PopAndDestroy( cenRep );
       
   559     }