|
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: BT Bearer plugin notification implementation file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <locodbearerpluginobserver.h> |
|
21 #include <btengsettings.h> |
|
22 #include <CoreApplicationUIsSDKCRKeys.h> |
|
23 #include "btpluginnotifier.h" |
|
24 #include "debug.h" |
|
25 #include <btfeaturescfg.h> |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // C++ default constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CBTPluginNotifier::CBTPluginNotifier( MLocodBearerPluginObserver& aParam, |
|
34 TUid aUid, TCenRepKeyType aKeyType, TUint32 aId ) |
|
35 : CActive( EPriorityStandard ), |
|
36 iUid( aUid ), |
|
37 iId( aId ), |
|
38 iKeyType( aKeyType ), |
|
39 iHandler( aParam ) |
|
40 { |
|
41 CActiveScheduler::Add( this ); |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Symbian 2nd-phase constructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void CBTPluginNotifier::ConstructL() |
|
50 { |
|
51 TRACE_FUNC_ENTRY |
|
52 iSession = CRepository::NewL( iUid ); |
|
53 TInt power = EBTPowerOff; |
|
54 iSession->Get( iId, power ); |
|
55 |
|
56 TInt offlineModeOff = ECoreAppUIsNetworkConnectionAllowed; |
|
57 CRepository* repository = CRepository::NewL( KCRUidCoreApplicationUIs ); |
|
58 repository->Get(KCoreAppUIsNetworkConnectionAllowed, offlineModeOff ); |
|
59 delete repository; |
|
60 |
|
61 CBTEngSettings* settings = CBTEngSettings::NewL(); |
|
62 |
|
63 BluetoothFeatures::TEnterpriseEnablementMode mode = BluetoothFeatures::EnterpriseEnablementL(); |
|
64 TRACE_INFO( ( _L( "mode = %d" ), mode) ) |
|
65 if( power == EBTPowerOn && offlineModeOff == ECoreAppUIsNetworkConnectionAllowed && mode != BluetoothFeatures::EDisabled ) |
|
66 { |
|
67 // BT was on before boot, turn it on again |
|
68 TRACE_INFO( ( _L( "Turning BT on" ) ) ) |
|
69 TInt err = settings->SetPowerState( EBTPowerOn ); |
|
70 TRACE_INFO( ( _L( "SetPowerState returned %d" ), err ) ) |
|
71 if( !err ) |
|
72 { |
|
73 iHandler.NotifyBearerStatus( ELocodBearerBT, power ); |
|
74 } |
|
75 } |
|
76 else |
|
77 { |
|
78 TRACE_INFO( ( _L( "Turning BT off" ) ) ) |
|
79 (void) settings->SetPowerState( EBTPowerOff ); // Result is not important here |
|
80 } |
|
81 delete settings; |
|
82 if ( mode != BluetoothFeatures::EDisabled ) // only subscribe if there's any point (NB changing Enterprise Disabling mode requires a reboot) |
|
83 SubscribeL(); |
|
84 TRACE_FUNC_EXIT |
|
85 } |
|
86 |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // NewL |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CBTPluginNotifier* CBTPluginNotifier::NewL( MLocodBearerPluginObserver& aParam, |
|
93 TUid aUid, TCenRepKeyType aKeyType, TUint32 aId ) |
|
94 { |
|
95 TRACE_FUNC_ENTRY |
|
96 CBTPluginNotifier* self = new( ELeave ) CBTPluginNotifier( aParam, aUid, |
|
97 aKeyType, aId ); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL(); |
|
100 CleanupStack::Pop( self ); |
|
101 return self; |
|
102 } |
|
103 |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Destructor |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CBTPluginNotifier::~CBTPluginNotifier() |
|
110 { |
|
111 TRACE_FUNC_ENTRY |
|
112 Cancel(); |
|
113 delete iSession; |
|
114 } |
|
115 |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CBTPluginNotifier::SubscribeL |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CBTPluginNotifier::SubscribeL() |
|
122 { |
|
123 TRACE_FUNC_ENTRY |
|
124 if( IsActive() ) |
|
125 { |
|
126 return; |
|
127 } |
|
128 User::LeaveIfError( iSession->NotifyRequest( iId, iStatus ) ); |
|
129 SetActive(); |
|
130 } |
|
131 |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // From class CActive. |
|
135 // Called by the active scheduler when our subscription |
|
136 // to the setting has been cancelled. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CBTPluginNotifier::DoCancel() |
|
140 { |
|
141 iSession->NotifyCancel( iId ); |
|
142 } |
|
143 |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // From class CActive. |
|
147 // Called by the active scheduler when the status has changed. |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CBTPluginNotifier::RunL() |
|
151 { |
|
152 TUint32 status = static_cast<TUint32>( iStatus.Int() ); |
|
153 TRACE_FUNC_ARG( ( _L( "RunL1 iStatus: %d]" ), status ) ) |
|
154 |
|
155 if( status != iId && status != NCentralRepositoryConstants::KInvalidNotificationId ) |
|
156 { |
|
157 return; |
|
158 } |
|
159 SubscribeL(); |
|
160 switch( iKeyType ) |
|
161 { |
|
162 case EKeyInt: |
|
163 { |
|
164 TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL2 %d]" ), status ) ) |
|
165 TInt newValue = 1; |
|
166 iSession->Get( iId, newValue ); |
|
167 iHandler.NotifyBearerStatus( ELocodBearerBT, newValue ); |
|
168 } |
|
169 break; |
|
170 default: |
|
171 { |
|
172 TRACE_INFO( ( _L( "[CBTPluginNotifier::RunL3 %d]" ), status ) ) |
|
173 } |
|
174 break; |
|
175 } |
|
176 TRACE_FUNC_EXIT |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // From class CActive. |
|
181 // Called by the active scheduler when RunL leaves. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 int CBTPluginNotifier::RunError(TInt aError) |
|
185 { |
|
186 TRACE_FUNC_ARG( ( _L( "RunError aError: %d]" ), aError ) ) |
|
187 (void) aError; |
|
188 return KErrNone; |
|
189 } |
|
190 |
|
191 |
|
192 |