idlefw/plugins/devicestatus/src/aibtsappublisher.cpp
changeset 0 79c6a41cd166
child 8 d0529222e3f0
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Listens Bluetooth SIM Access Profile (BT SAP) and publishes
       
    15 *					text when BT SAP is activated.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <aidevstaplgres.rsg>
       
    21 #include <centralrepository.h>
       
    22 #include <BTSapDomainPSKeys.h>
       
    23 #include <StringLoader.h>
       
    24 #include <featmgr.h>
       
    25 #include "aibtsappublisher.h"
       
    26 #include "aiprioritizer.h"
       
    27 #include "ainwidpriorities.h"
       
    28 
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 CAiBTSAPPublisher::CAiBTSAPPublisher()
       
    33 : CActive( CActive::EPriorityStandard )
       
    34     {
       
    35     CActiveScheduler::Add( this );
       
    36     }
       
    37 
       
    38 
       
    39 void CAiBTSAPPublisher::ConstructL()
       
    40     {
       
    41 	//if platform doesn't support BTSAP, there is no reason
       
    42 	//to create this object.
       
    43     if( !FeatureManager::FeatureSupported( KFeatureIdBtSap ) )
       
    44         {
       
    45         User::Leave( KErrNotSupported );
       
    46         }
       
    47     }
       
    48 
       
    49 
       
    50 CAiBTSAPPublisher* CAiBTSAPPublisher::NewL()
       
    51     {
       
    52     CAiBTSAPPublisher* self = new( ELeave ) CAiBTSAPPublisher;
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 CAiBTSAPPublisher::~CAiBTSAPPublisher()
       
    61     {
       
    62     Cancel();
       
    63     iPubSub.Close();
       
    64     }
       
    65 
       
    66 
       
    67 void CAiBTSAPPublisher::ResumeL()
       
    68     {
       
    69     Cancel();
       
    70 
       
    71     iPubSub.Close();
       
    72 	//attach to BTSAP key.
       
    73     User::LeaveIfError( iPubSub.Attach( KPSUidBluetoothSapConnectionState,
       
    74     									KBTSapConnectionState ) );
       
    75 
       
    76     iFirstPublish = ETrue;
       
    77 
       
    78     //subscribe to get notification when key changes.
       
    79     iPubSub.Subscribe( iStatus );
       
    80     SetActive();
       
    81     }
       
    82 
       
    83 
       
    84 void CAiBTSAPPublisher::Subscribe( MAiContentObserver& /*aObserver*/,
       
    85 								    MAiPropertyExtension& aExtension,
       
    86                                     MAiPublishPrioritizer& aPrioritizer,
       
    87                                     MAiPublisherBroadcaster& aBroadcaster )
       
    88     {
       
    89     iExtension = &aExtension;
       
    90     iPrioritizer = &aPrioritizer;
       
    91     iBroadcaster = &aBroadcaster;
       
    92     }
       
    93 
       
    94 
       
    95 void CAiBTSAPPublisher::RefreshL( TBool aClean )
       
    96     {
       
    97     iSuccess = EFalse;
       
    98     if( aClean )
       
    99         {
       
   100         iPrioritizer->TryToCleanL( *iBroadcaster,
       
   101         							EAiDeviceStatusContentNetworkIdentity,
       
   102         							EAiBTSAP );
       
   103         }
       
   104 
       
   105     //Get BTSAP state
       
   106     TInt sapState( 0 );
       
   107     TInt err = RProperty::Get( KPSUidBluetoothSapConnectionState,
       
   108                                KBTSapConnectionState,
       
   109                                sapState );
       
   110 
       
   111     //If key is not found, it is treated same way as the BTSAP is not on.
       
   112     if( err == KErrNotFound )
       
   113         {
       
   114         err = KErrNone;
       
   115         sapState = EBTSapNotConnected;
       
   116         }
       
   117 
       
   118     User::LeaveIfError( err );
       
   119 
       
   120     if( sapState == EBTSapConnected )
       
   121         {
       
   122         iPrioritizer->TryToPublishL( *iBroadcaster,
       
   123         							EAiDeviceStatusContentNetworkIdentity,
       
   124         							R_ACTIVEIDLE_BT_SIM_ACCESS_PROFILE_STRING,
       
   125         							EAiBTSAP );
       
   126         iSuccess = ETrue;
       
   127         }
       
   128 
       
   129     else if( !iFirstPublish )
       
   130         {
       
   131 		//BTSAP is not anymore active, call clean.
       
   132         iPrioritizer->TryToCleanL( *iBroadcaster,
       
   133         							EAiDeviceStatusContentNetworkIdentity,
       
   134         							EAiBTSAP );
       
   135         }
       
   136     iFirstPublish = EFalse;
       
   137     }
       
   138 
       
   139 
       
   140 void CAiBTSAPPublisher::RunL()
       
   141     {
       
   142     if( iStatus.Int() == KErrNone )
       
   143         {
       
   144 	    //PS key changed, refresh publisher.
       
   145         RefreshL( ETrue );
       
   146         iPubSub.Subscribe( iStatus );
       
   147         SetActive();
       
   148         }
       
   149     }
       
   150 
       
   151 
       
   152 void CAiBTSAPPublisher::DoCancel()
       
   153     {
       
   154     iPubSub.Cancel();
       
   155     }
       
   156 
       
   157 
       
   158 TInt CAiBTSAPPublisher::RunError( TInt /*aError*/ )
       
   159     {
       
   160     iPubSub.Cancel();
       
   161     //failed to publish, lets however ignore it
       
   162     return KErrNone;
       
   163     }
       
   164 
       
   165 
       
   166 TBool CAiBTSAPPublisher::RefreshL( TInt aContentId, TBool aClean )
       
   167 	{
       
   168     if( aContentId == EAiDeviceStatusContentNetworkIdentity )
       
   169         {
       
   170    	    RefreshL( aClean );
       
   171         if( iSuccess )
       
   172 	        {
       
   173 	        return ETrue;
       
   174 	        }
       
   175         }
       
   176     return EFalse;
       
   177 	}
       
   178 
       
   179 
       
   180 TBool CAiBTSAPPublisher::RefreshContentWithPriorityL( TInt aContentId,
       
   181                                                         TInt aPriority )
       
   182 	{
       
   183 	if( aContentId == EAiDeviceStatusContentNetworkIdentity &&
       
   184 	    aPriority == EAiBTSAP )
       
   185         {
       
   186 	    RefreshL( EFalse );
       
   187         if( iSuccess )
       
   188 	        {
       
   189 	        return ETrue;
       
   190 	        }
       
   191         }
       
   192     return EFalse;
       
   193 	}