|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <centralrepository.h> |
|
22 |
|
23 #include "btengprivatecrkeys.h" |
|
24 #include "btengsettingsnotify.h" |
|
25 #include "btengsettings.h" |
|
26 #include "debug.h" |
|
27 |
|
28 const TInt KPowerKeyReqId = 20; |
|
29 const TInt KVisibilityKeyReqId = 21; |
|
30 |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // C++ default constructor |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CBTEngSettingsNotify::CBTEngSettingsNotify( MBTEngSettingsObserver* aObserver ) |
|
39 : iObserver( aObserver ) |
|
40 { |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // Symbian 2nd-phase constructor |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 void CBTEngSettingsNotify::ConstructL() |
|
49 { |
|
50 TRACE_FUNC_ENTRY |
|
51 if( iObserver ) |
|
52 { |
|
53 // Power status: |
|
54 iPowerKeyWatcher = CBTEngActive::NewL( *this, KPowerKeyReqId, |
|
55 CActive::EPriorityStandard ); |
|
56 iPowerKeyCenRep = CRepository::NewL( KCRUidBluetoothPowerState ); |
|
57 iPowerKeyCenRep->NotifyRequest( KBTPowerState, |
|
58 iPowerKeyWatcher->RequestStatus() ); |
|
59 iPowerKeyWatcher->GoActive(); |
|
60 // Visibility mode: |
|
61 iVisiKeyWatcher = CBTEngActive::NewL( *this, KVisibilityKeyReqId, |
|
62 CActive::EPriorityStandard ); |
|
63 iVisiKeyCenRep = CRepository::NewL( KCRUidBTEngPrivateSettings ); |
|
64 iVisiKeyCenRep->NotifyRequest( KBTDiscoverable, |
|
65 iVisiKeyWatcher->RequestStatus() ); |
|
66 iVisiKeyWatcher->GoActive(); |
|
67 } |
|
68 |
|
69 TRACE_FUNC_EXIT |
|
70 } |
|
71 |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // NewL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CBTEngSettingsNotify* CBTEngSettingsNotify::NewL( MBTEngSettingsObserver* aObserver ) |
|
78 { |
|
79 CBTEngSettingsNotify* self = new( ELeave ) CBTEngSettingsNotify( aObserver ); |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL(); |
|
82 CleanupStack::Pop( self ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // Destructor |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CBTEngSettingsNotify::~CBTEngSettingsNotify() |
|
92 { |
|
93 if ( iPowerKeyCenRep ) |
|
94 { |
|
95 iPowerKeyCenRep->NotifyCancel( KBTPowerState ); |
|
96 } |
|
97 delete iPowerKeyWatcher; // Will call Cancel() |
|
98 delete iPowerKeyCenRep; |
|
99 if ( iVisiKeyCenRep ) |
|
100 { |
|
101 iVisiKeyCenRep->NotifyCancel( KBTDiscoverable ); |
|
102 } |
|
103 delete iVisiKeyWatcher; // Will call Cancel() |
|
104 delete iVisiKeyCenRep; |
|
105 if( iBTeng.Handle() ) |
|
106 { |
|
107 iBTeng.Close(); |
|
108 } |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Toggles Bluetooth power based on the existence of a session. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CBTEngSettingsNotify::TogglePowerTemporarily() |
|
117 { |
|
118 TRACE_FUNC_ENTRY |
|
119 TInt err = KErrNone; |
|
120 if( !iBTeng.Handle() ) |
|
121 { |
|
122 err = iBTeng.Connect(); |
|
123 if( !err ) |
|
124 { |
|
125 err = iBTeng.SetPowerState( EBTPowerOn, ETrue ); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 iBTeng.Close(); |
|
131 } |
|
132 return err; |
|
133 } |
|
134 |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // From class MBTEngCenRepNotify. |
|
138 // Handles notification of a setting change, and informs our observer. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CBTEngSettingsNotify::RequestCompletedL( CBTEngActive* aActive, TInt aId, |
|
142 TInt aStatus ) |
|
143 { |
|
144 TRACE_FUNC_ARG( ( _L( "Id(%d), status(%d)" ), aId, aStatus ) ) |
|
145 |
|
146 if( aId == KPowerKeyReqId && aStatus == KBTPowerState ) |
|
147 { |
|
148 iPowerKeyCenRep->NotifyRequest( KBTPowerState, |
|
149 iPowerKeyWatcher->RequestStatus() ); |
|
150 iPowerKeyWatcher->GoActive(); |
|
151 TInt value = 0; |
|
152 TInt err = iPowerKeyCenRep->Get( KBTPowerState, value ); |
|
153 if( !err ) |
|
154 { |
|
155 iObserver->PowerStateChanged( (TBTPowerStateValue) value ); |
|
156 } |
|
157 } |
|
158 else if( aId == KVisibilityKeyReqId && aStatus == KBTDiscoverable ) |
|
159 { |
|
160 iVisiKeyCenRep->NotifyRequest( KBTDiscoverable, |
|
161 iVisiKeyWatcher->RequestStatus() ); |
|
162 iVisiKeyWatcher->GoActive(); |
|
163 TInt value = 0; |
|
164 TInt err = iVisiKeyCenRep->Get( KBTDiscoverable, value ); |
|
165 if( !err ) |
|
166 { |
|
167 iObserver->VisibilityModeChanged( (TBTVisibilityMode) value ); |
|
168 } |
|
169 } |
|
170 else |
|
171 { |
|
172 // Coudl be a repository-wide reset (KInvalidNotificationId), |
|
173 // or an invalid key ID. Anyway we know the ID of the active |
|
174 // object, so we can just reset the watcher. |
|
175 HandleError( aActive, aId, aStatus ); |
|
176 } |
|
177 TRACE_FUNC_EXIT |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // From class MBTEngCenRepNotify. |
|
183 // Handles error situation by just re-ordering notification from CenRep. |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CBTEngSettingsNotify::HandleError( CBTEngActive* aActive, TInt aId, |
|
187 TInt aError ) |
|
188 { |
|
189 TRACE_FUNC_ARG( ( _L( "Id(%d), status(%d)" ), aId, aError ) ) |
|
190 (void) aError; |
|
191 if( aId == KPowerKeyReqId ) |
|
192 { |
|
193 delete iPowerKeyCenRep; |
|
194 iPowerKeyCenRep = NULL; |
|
195 TRAPD( err, iPowerKeyCenRep = |
|
196 CRepository::NewL( KCRUidBluetoothPowerState ) ); |
|
197 if( !err ) |
|
198 { |
|
199 iPowerKeyCenRep->NotifyRequest( KBTPowerState, |
|
200 aActive->RequestStatus() ); |
|
201 aActive->GoActive(); |
|
202 } |
|
203 } |
|
204 else if( aId == KVisibilityKeyReqId ) |
|
205 { |
|
206 delete iVisiKeyCenRep; |
|
207 iVisiKeyCenRep = NULL; |
|
208 TRAPD( err, iVisiKeyCenRep = |
|
209 CRepository::NewL( KCRUidBTEngPrivateSettings ) ); |
|
210 if( !err ) |
|
211 { |
|
212 iVisiKeyCenRep->NotifyRequest( KBTDiscoverable, |
|
213 aActive->RequestStatus() ); |
|
214 aActive->GoActive(); |
|
215 } |
|
216 } |
|
217 } |